From 61649d5da7cd8598a5c4339ec609bbfb237b49fe Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 4 May 2020 23:16:24 -0700 Subject: [PATCH 001/151] Deprecate various IP/packet header Val-building methods And supply new alternatives that use IntrusivePtr --- NEWS | 4 + src/Discard.cc | 8 +- src/IP.cc | 90 ++++++++++++------- src/IP.h | 17 ++++ src/Sessions.cc | 16 ++-- .../protocol/gtpv1/gtpv1-analyzer.pac | 2 +- src/analyzer/protocol/teredo/Teredo.cc | 2 +- src/analyzer/protocol/vxlan/VXLAN.cc | 3 +- src/iosource/Packet.cc | 14 ++- src/iosource/Packet.h | 4 + src/zeek.bif | 2 +- 11 files changed, 107 insertions(+), 55 deletions(-) diff --git a/NEWS b/NEWS index b394d78d7f..0a35e5d69d 100644 --- a/NEWS +++ b/NEWS @@ -133,6 +133,10 @@ Deprecated Functionality - Returning ``Val*`` from BIFs is deprecated, return ``IntrusivePtr`` instead. +- Various methods of converting protocol structures, like IP or packet headers, + to associated ``Val`` type are now deprecated, the deprecation warning + message will advice what new method to use instead. + Zeek 3.1.0 ========== diff --git a/src/Discard.cc b/src/Discard.cc index 77e83620db..3e87ca0bc7 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -39,7 +39,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) if ( check_ip ) { - zeek::Args args{{AdoptRef{}, ip->BuildPktHdrVal()}}; + zeek::Args args{ip->ToPktHdrVal()}; try { @@ -92,7 +92,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) int th_len = tp->th_off * 4; zeek::Args args{ - {AdoptRef{}, ip->BuildPktHdrVal()}, + ip->ToPktHdrVal(), {AdoptRef{}, BuildData(data, th_len, len, caplen)}, }; @@ -116,7 +116,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) int uh_len = sizeof (struct udphdr); zeek::Args args{ - {AdoptRef{}, ip->BuildPktHdrVal()}, + ip->ToPktHdrVal(), {AdoptRef{}, BuildData(data, uh_len, len, caplen)}, }; @@ -138,7 +138,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) { const struct icmp* ih = (const struct icmp*) data; - zeek::Args args{{AdoptRef{}, ip->BuildPktHdrVal()}}; + zeek::Args args{ip->ToPktHdrVal()}; try { diff --git a/src/IP.cc b/src/IP.cc index 58c0a9ef26..820570a2d6 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -77,14 +77,14 @@ static VectorVal* BuildOptionsVal(const u_char* data, int len) return vv; } -RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const +IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const { - RecordVal* rv = nullptr; + IntrusivePtr rv; switch ( type ) { case IPPROTO_IPV6: { - rv = new RecordVal(hdrType(ip6_hdr_type, "ip6_hdr")); + rv = make_intrusive(hdrType(ip6_hdr_type, "ip6_hdr")); const struct ip6_hdr* ip6 = (const struct ip6_hdr*)data; rv->Assign(0, val_mgr->Count((ntohl(ip6->ip6_flow) & 0x0ff00000)>>20)); rv->Assign(1, val_mgr->Count(ntohl(ip6->ip6_flow) & 0x000fffff)); @@ -94,15 +94,15 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const rv->Assign(5, make_intrusive(IPAddr(ip6->ip6_src))); rv->Assign(6, make_intrusive(IPAddr(ip6->ip6_dst))); if ( ! chain ) - chain = new VectorVal( + chain = make_intrusive( internal_type("ip6_ext_hdr_chain")->AsVectorType()); - rv->Assign(7, chain); + rv->Assign(7, std::move(chain)); } break; case IPPROTO_HOPOPTS: { - rv = new RecordVal(hdrType(ip6_hopopts_type, "ip6_hopopts")); + rv = make_intrusive(hdrType(ip6_hopopts_type, "ip6_hopopts")); const struct ip6_hbh* hbh = (const struct ip6_hbh*)data; rv->Assign(0, val_mgr->Count(hbh->ip6h_nxt)); rv->Assign(1, val_mgr->Count(hbh->ip6h_len)); @@ -114,7 +114,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const case IPPROTO_DSTOPTS: { - rv = new RecordVal(hdrType(ip6_dstopts_type, "ip6_dstopts")); + rv = make_intrusive(hdrType(ip6_dstopts_type, "ip6_dstopts")); const struct ip6_dest* dst = (const struct ip6_dest*)data; rv->Assign(0, val_mgr->Count(dst->ip6d_nxt)); rv->Assign(1, val_mgr->Count(dst->ip6d_len)); @@ -125,7 +125,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const case IPPROTO_ROUTING: { - rv = new RecordVal(hdrType(ip6_routing_type, "ip6_routing")); + rv = make_intrusive(hdrType(ip6_routing_type, "ip6_routing")); const struct ip6_rthdr* rt = (const struct ip6_rthdr*)data; rv->Assign(0, val_mgr->Count(rt->ip6r_nxt)); rv->Assign(1, val_mgr->Count(rt->ip6r_len)); @@ -138,7 +138,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const case IPPROTO_FRAGMENT: { - rv = new RecordVal(hdrType(ip6_fragment_type, "ip6_fragment")); + rv = make_intrusive(hdrType(ip6_fragment_type, "ip6_fragment")); const struct ip6_frag* frag = (const struct ip6_frag*)data; rv->Assign(0, val_mgr->Count(frag->ip6f_nxt)); rv->Assign(1, val_mgr->Count(frag->ip6f_reserved)); @@ -151,7 +151,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const case IPPROTO_AH: { - rv = new RecordVal(hdrType(ip6_ah_type, "ip6_ah")); + rv = make_intrusive(hdrType(ip6_ah_type, "ip6_ah")); rv->Assign(0, val_mgr->Count(((ip6_ext*)data)->ip6e_nxt)); rv->Assign(1, val_mgr->Count(((ip6_ext*)data)->ip6e_len)); rv->Assign(2, val_mgr->Count(ntohs(((uint16_t*)data)[1]))); @@ -170,7 +170,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const case IPPROTO_ESP: { - rv = new RecordVal(hdrType(ip6_esp_type, "ip6_esp")); + rv = make_intrusive(hdrType(ip6_esp_type, "ip6_esp")); const uint32_t* esp = (const uint32_t*)data; rv->Assign(0, val_mgr->Count(ntohl(esp[0]))); rv->Assign(1, val_mgr->Count(ntohl(esp[1]))); @@ -180,7 +180,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const #ifdef ENABLE_MOBILE_IPV6 case IPPROTO_MOBILITY: { - rv = new RecordVal(hdrType(ip6_mob_type, "ip6_mobility_hdr")); + rv = make_intrusive(hdrType(ip6_mob_type, "ip6_mobility_hdr")); const struct ip6_mobility* mob = (const struct ip6_mobility*) data; rv->Assign(0, val_mgr->Count(mob->ip6mob_payload)); rv->Assign(1, val_mgr->Count(mob->ip6mob_len)); @@ -296,7 +296,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const break; } - rv->Assign(5, msg); + rv->Assign(5, std::move(msg)); } break; #endif //ENABLE_MOBILE_IPV6 @@ -308,6 +308,11 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const return rv; } +RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const + { + return ToVal({AdoptRef{}, chain}).release(); + } + IPAddr IP_Hdr::IPHeaderSrcAddr() const { return ip4 ? IPAddr(ip4->ip_src) : IPAddr(ip6->ip6_src); @@ -328,13 +333,13 @@ IPAddr IP_Hdr::DstAddr() const return ip4 ? IPAddr(ip4->ip_dst) : ip6_hdrs->DstAddr(); } -RecordVal* IP_Hdr::BuildIPHdrVal() const +IntrusivePtr IP_Hdr::ToIPHdrVal() const { - RecordVal* rval = nullptr; + IntrusivePtr rval; if ( ip4 ) { - rval = new RecordVal(hdrType(ip4_hdr_type, "ip4_hdr")); + rval = make_intrusive(hdrType(ip4_hdr_type, "ip4_hdr")); rval->Assign(0, val_mgr->Count(ip4->ip_hl * 4)); rval->Assign(1, val_mgr->Count(ip4->ip_tos)); rval->Assign(2, val_mgr->Count(ntohs(ip4->ip_len))); @@ -346,24 +351,33 @@ RecordVal* IP_Hdr::BuildIPHdrVal() const } else { - rval = ((*ip6_hdrs)[0])->BuildRecordVal(ip6_hdrs->BuildVal()); + rval = ((*ip6_hdrs)[0])->ToVal(ip6_hdrs->ToVal()); } return rval; } -RecordVal* IP_Hdr::BuildPktHdrVal() const +RecordVal* IP_Hdr::BuildIPHdrVal() const + { + return ToIPHdrVal().release(); + } + +IntrusivePtr IP_Hdr::ToPktHdrVal() const { static RecordType* pkt_hdr_type = nullptr; if ( ! pkt_hdr_type ) pkt_hdr_type = internal_type("pkt_hdr")->AsRecordType(); - RecordVal* pkt_hdr = new RecordVal(pkt_hdr_type); - return BuildPktHdrVal(pkt_hdr, 0); + return ToPktHdrVal(make_intrusive(pkt_hdr_type), 0); } -RecordVal* IP_Hdr::BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const +RecordVal* IP_Hdr::BuildPktHdrVal() const + { + return ToPktHdrVal().release(); + } + +IntrusivePtr IP_Hdr::ToPktHdrVal(IntrusivePtr pkt_hdr, int sindex) const { static RecordType* tcp_hdr_type = nullptr; static RecordType* udp_hdr_type = nullptr; @@ -377,9 +391,9 @@ RecordVal* IP_Hdr::BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const } if ( ip4 ) - pkt_hdr->Assign(sindex + 0, BuildIPHdrVal()); + pkt_hdr->Assign(sindex + 0, ToIPHdrVal()); else - pkt_hdr->Assign(sindex + 1, BuildIPHdrVal()); + pkt_hdr->Assign(sindex + 1, ToIPHdrVal()); // L4 header. const u_char* data = Payload(); @@ -453,6 +467,11 @@ RecordVal* IP_Hdr::BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const return pkt_hdr; } +RecordVal* IP_Hdr::BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const + { + return ToPktHdrVal({AdoptRef{}, pkt_hdr}, sindex).release(); + } + static inline bool isIPv6ExtHeader(uint8_t type) { switch (type) { @@ -674,7 +693,7 @@ void IPv6_Hdr_Chain::ProcessDstOpts(const struct ip6_dest* d, uint16_t len) } #endif -VectorVal* IPv6_Hdr_Chain::BuildVal() const +IntrusivePtr IPv6_Hdr_Chain::ToVal() const { if ( ! ip6_ext_hdr_type ) { @@ -688,38 +707,38 @@ VectorVal* IPv6_Hdr_Chain::BuildVal() const ip6_mob_type = internal_type("ip6_mobility_hdr")->AsRecordType(); } - VectorVal* rval = new VectorVal( + auto rval = make_intrusive( internal_type("ip6_ext_hdr_chain")->AsVectorType()); for ( size_t i = 1; i < chain.size(); ++i ) { - RecordVal* v = chain[i]->BuildRecordVal(); + auto v = chain[i]->ToVal(); RecordVal* ext_hdr = new RecordVal(ip6_ext_hdr_type); uint8_t type = chain[i]->Type(); ext_hdr->Assign(0, val_mgr->Count(type)); switch (type) { case IPPROTO_HOPOPTS: - ext_hdr->Assign(1, v); + ext_hdr->Assign(1, std::move(v)); break; case IPPROTO_DSTOPTS: - ext_hdr->Assign(2, v); + ext_hdr->Assign(2, std::move(v)); break; case IPPROTO_ROUTING: - ext_hdr->Assign(3, v); + ext_hdr->Assign(3, std::move(v)); break; case IPPROTO_FRAGMENT: - ext_hdr->Assign(4, v); + ext_hdr->Assign(4, std::move(v)); break; case IPPROTO_AH: - ext_hdr->Assign(5, v); + ext_hdr->Assign(5, std::move(v)); break; case IPPROTO_ESP: - ext_hdr->Assign(6, v); + ext_hdr->Assign(6, std::move(v)); break; #ifdef ENABLE_MOBILE_IPV6 case IPPROTO_MOBILITY: - ext_hdr->Assign(7, v); + ext_hdr->Assign(7, std::move(v)); break; #endif default: @@ -734,6 +753,11 @@ VectorVal* IPv6_Hdr_Chain::BuildVal() const return rval; } +VectorVal* IPv6_Hdr_Chain::BuildVal() const + { + return ToVal().release(); + } + IP_Hdr* IP_Hdr::Copy() const { char* new_hdr = new char[HdrLen()]; diff --git a/src/IP.h b/src/IP.h index bb62d30b04..2959a6dd1a 100644 --- a/src/IP.h +++ b/src/IP.h @@ -14,6 +14,8 @@ #include +#include "IntrusivePtr.h" + class IPAddr; class RecordVal; class VectorVal; @@ -134,6 +136,9 @@ public: /** * Returns the script-layer record representation of the header. */ + IntrusivePtr ToVal(IntrusivePtr chain = nullptr) const; + + [[deprecated("Remove in v4.1. Use ToVal() instead.")]] RecordVal* BuildRecordVal(VectorVal* chain = nullptr) const; protected: @@ -223,6 +228,9 @@ public: * Returns a vector of ip6_ext_hdr RecordVals that includes script-layer * representation of all extension headers in the chain. */ + IntrusivePtr ToVal() const; + + [[deprecated("Remove in v4.1. Use ToVal() instead.")]] VectorVal* BuildVal() const; protected: @@ -517,18 +525,27 @@ public: /** * Returns an ip_hdr or ip6_hdr_chain RecordVal. */ + IntrusivePtr ToIPHdrVal() const; + + [[deprecated("Remove in v4.1. Use ToIPHdrVal() instead.")]] RecordVal* BuildIPHdrVal() const; /** * Returns a pkt_hdr RecordVal, which includes not only the IP header, but * also upper-layer (tcp/udp/icmp) headers. */ + IntrusivePtr ToPktHdrVal() const; + + [[deprecated("Remove in v4.1. Use ToPktHdrVal() instead.")]] RecordVal* BuildPktHdrVal() const; /** * Same as above, but simply add our values into the record at the * specified starting index. */ + IntrusivePtr ToPktHdrVal(IntrusivePtr pkt_hdr, int sindex) const; + + [[deprecated("Remove in v4.1. Use ToPktHdrVal() instead.")]] RecordVal* BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const; private: diff --git a/src/Sessions.cc b/src/Sessions.cc index 251d8de3a8..a2dc0fe248 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -123,7 +123,7 @@ void NetSessions::NextPacket(double t, const Packet* pkt) SegmentProfiler prof(segment_logger, "dispatching-packet"); if ( raw_packet ) - mgr.Enqueue(raw_packet, IntrusivePtr{AdoptRef{}, pkt->BuildPktHdrVal()}); + mgr.Enqueue(raw_packet, pkt->ToRawPktHdrVal()); if ( pkt_profiler ) pkt_profiler->ProfilePkt(t, pkt->cap_len); @@ -310,7 +310,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr { dump_this_packet = true; if ( esp_packet ) - mgr.Enqueue(esp_packet, IntrusivePtr{AdoptRef{}, ip_hdr->BuildPktHdrVal()}); + mgr.Enqueue(esp_packet, ip_hdr->ToPktHdrVal()); // Can't do more since upper-layer payloads are going to be encrypted. return; @@ -330,8 +330,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr } if ( mobile_ipv6_message ) - mgr.Enqueue(mobile_ipv6_message, - IntrusivePtr{AdoptRef{}, ip_hdr->BuildPktHdrVal()}); + mgr.Enqueue(mobile_ipv6_message, ip_hdr->ToPktHdrVal()); if ( ip_hdr->NextProto() != IPPROTO_NONE ) Weird("mobility_piggyback", pkt, encapsulation); @@ -686,19 +685,18 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr conn->CheckFlowLabel(is_orig, ip_hdr->FlowLabel()); - Val* pkt_hdr_val = nullptr; + IntrusivePtr pkt_hdr_val; if ( ipv6_ext_headers && ip_hdr->NumHeaders() > 1 ) { - pkt_hdr_val = ip_hdr->BuildPktHdrVal(); + pkt_hdr_val = ip_hdr->ToPktHdrVal(); conn->EnqueueEvent(ipv6_ext_headers, nullptr, conn->ConnVal(), - IntrusivePtr{AdoptRef{}, pkt_hdr_val}); + pkt_hdr_val); } if ( new_packet ) conn->EnqueueEvent(new_packet, nullptr, conn->ConnVal(), pkt_hdr_val ? - IntrusivePtr{NewRef{}, pkt_hdr_val} : - IntrusivePtr{AdoptRef{}, ip_hdr->BuildPktHdrVal()}); + std::move(pkt_hdr_val) : ip_hdr->ToPktHdrVal()); conn->NextPacket(t, is_orig, ip_hdr, len, caplen, data, record_packet, record_content, pkt); diff --git a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac index a804dfbbcd..d7e9ca9010 100644 --- a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac +++ b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac @@ -760,7 +760,7 @@ flow GTPv1_Flow(is_orig: bool) if ( ::gtpv1_g_pdu_packet ) BifEvent::enqueue_gtpv1_g_pdu_packet(a, c, BuildGTPv1Hdr(pdu), - {AdoptRef{}, inner->BuildPktHdrVal()}); + inner->ToPktHdrVal()); EncapsulatingConn ec(c, BifEnum::Tunnel::GTPv1); diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index 8fbb8eb4af..9501378a23 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -137,7 +137,7 @@ IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const teredo_hdr->Assign(1, teredo_origin); } - teredo_hdr->Assign(2, inner->BuildPktHdrVal()); + teredo_hdr->Assign(2, inner->ToPktHdrVal()); return teredo_hdr; } diff --git a/src/analyzer/protocol/vxlan/VXLAN.cc b/src/analyzer/protocol/vxlan/VXLAN.cc index 2af72887f7..eb4e0e5926 100644 --- a/src/analyzer/protocol/vxlan/VXLAN.cc +++ b/src/analyzer/protocol/vxlan/VXLAN.cc @@ -102,8 +102,7 @@ void VXLAN_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, if ( vxlan_packet ) Conn()->EnqueueEvent(vxlan_packet, nullptr, ConnVal(), - IntrusivePtr{AdoptRef{}, inner->BuildPktHdrVal()}, - val_mgr->Count(vni)); + inner->ToPktHdrVal(), val_mgr->Count(vni)); EncapsulatingConn ec(Conn(), BifEnum::Tunnel::VXLAN); sessions->DoNextInnerPacket(network_time, &pkt, inner, estack, ec); diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index 09cc2f1fa6..52033ca5d0 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -2,6 +2,7 @@ #include "Sessions.h" #include "Desc.h" #include "IP.h" +#include "IntrusivePtr.h" #include "iosource/Manager.h" extern "C" { @@ -590,9 +591,9 @@ void Packet::ProcessLayer2() hdr_size = (pdata - data); } -RecordVal* Packet::BuildPktHdrVal() const +IntrusivePtr Packet::ToRawPktHdrVal() const { - RecordVal* pkt_hdr = new RecordVal(raw_pkt_hdr_type); + auto pkt_hdr = make_intrusive(raw_pkt_hdr_type); RecordVal* l2_hdr = new RecordVal(l2_hdr_type); bool is_ethernet = link_type == DLT_EN10MB; @@ -652,19 +653,24 @@ RecordVal* Packet::BuildPktHdrVal() const if ( l3_proto == L3_IPV4 ) { IP_Hdr ip_hdr((const struct ip*)(data + hdr_size), false); - return ip_hdr.BuildPktHdrVal(pkt_hdr, 1); + return ip_hdr.ToPktHdrVal(std::move(pkt_hdr), 1); } else if ( l3_proto == L3_IPV6 ) { IP_Hdr ip6_hdr((const struct ip6_hdr*)(data + hdr_size), false, cap_len); - return ip6_hdr.BuildPktHdrVal(pkt_hdr, 1); + return ip6_hdr.ToPktHdrVal(std::move(pkt_hdr), 1); } else return pkt_hdr; } +RecordVal* Packet::BuildPktHdrVal() const + { + return ToRawPktHdrVal().release(); + } + Val *Packet::FmtEUI48(const u_char *mac) const { char buf[20]; diff --git a/src/iosource/Packet.h b/src/iosource/Packet.h index 2da4836b7b..ce2e3b928a 100644 --- a/src/iosource/Packet.h +++ b/src/iosource/Packet.h @@ -16,6 +16,7 @@ class Val; class ODesc; class IP_Hdr; class RecordVal; +template class IntrusivePtr; /** * The Layer 3 type of a packet, as determined by the parsing code in Packet. @@ -127,6 +128,9 @@ public: * Returns a \c raw_pkt_hdr RecordVal, which includes layer 2 and * also everything in IP_Hdr (i.e., IP4/6 + TCP/UDP/ICMP). */ + IntrusivePtr ToRawPktHdrVal() const; + + [[deprecated("Remove in v4.1. Use ToRawPktHdrval() instead.")]] RecordVal* BuildPktHdrVal() const; /** diff --git a/src/zeek.bif b/src/zeek.bif index 77d3a11838..70674fe43b 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -3427,7 +3427,7 @@ function get_current_packet_header%(%) : raw_pkt_hdr if ( current_pktsrc && current_pktsrc->GetCurrentPacket(&p) ) { - return IntrusivePtr{AdoptRef{}, p->BuildPktHdrVal()}; + return p->ToRawPktHdrVal(); } auto hdr = make_intrusive(raw_pkt_hdr_type); From 2cfbbd8cdb94a801c6f6bb1cecc1bc6033a89a2d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 10:32:25 -0700 Subject: [PATCH 002/151] Deprecate TunnelEncapsulation BuildRecordVal/BuildVectorVal methods Replaced with ToVal methods that return IntrusivePtr --- src/Conn.cc | 10 ++++------ src/TunnelEncapsulation.cc | 4 ++-- src/TunnelEncapsulation.h | 17 +++++++++++++---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Conn.cc b/src/Conn.cc index 8b017b5686..dc8b63bb9c 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -146,7 +146,7 @@ void Connection::CheckEncapsulation(const EncapsulationStack* arg_encap) { if ( tunnel_changed ) EnqueueEvent(tunnel_changed, nullptr, ConnVal(), - IntrusivePtr{AdoptRef{}, arg_encap->GetVectorVal()}); + arg_encap->ToVal()); delete encapsulation; encapsulation = new EncapsulationStack(*arg_encap); @@ -158,8 +158,7 @@ void Connection::CheckEncapsulation(const EncapsulationStack* arg_encap) if ( tunnel_changed ) { EncapsulationStack empty; - EnqueueEvent(tunnel_changed, nullptr, ConnVal(), - IntrusivePtr{AdoptRef{}, empty.GetVectorVal()}); + EnqueueEvent(tunnel_changed, nullptr, ConnVal(), empty.ToVal()); } delete encapsulation; @@ -169,8 +168,7 @@ void Connection::CheckEncapsulation(const EncapsulationStack* arg_encap) else if ( arg_encap ) { if ( tunnel_changed ) - EnqueueEvent(tunnel_changed, nullptr, ConnVal(), - IntrusivePtr{AdoptRef{}, arg_encap->GetVectorVal()}); + EnqueueEvent(tunnel_changed, nullptr, ConnVal(), arg_encap->ToVal()); encapsulation = new EncapsulationStack(*arg_encap); } @@ -390,7 +388,7 @@ const IntrusivePtr& Connection::ConnVal() conn_val->Assign(7, make_intrusive(uid.Base62("C").c_str())); if ( encapsulation && encapsulation->Depth() > 0 ) - conn_val->Assign(8, encapsulation->GetVectorVal()); + conn_val->Assign(8, encapsulation->ToVal()); if ( vlan != 0 ) conn_val->Assign(9, val_mgr->Int(vlan)); diff --git a/src/TunnelEncapsulation.cc b/src/TunnelEncapsulation.cc index 2f3deb9e14..2f58df3bd0 100644 --- a/src/TunnelEncapsulation.cc +++ b/src/TunnelEncapsulation.cc @@ -16,9 +16,9 @@ EncapsulatingConn::EncapsulatingConn(Connection* c, BifEnum::Tunnel::Type t) } } -RecordVal* EncapsulatingConn::GetRecordVal() const +IntrusivePtr EncapsulatingConn::ToVal() const { - RecordVal *rv = new RecordVal(BifType::Record::Tunnel::EncapsulatingConn); + auto rv = make_intrusive(BifType::Record::Tunnel::EncapsulatingConn); auto id_val = make_intrusive(conn_id); id_val->Assign(0, make_intrusive(src_addr)); diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 4fc0d19b3e..106d5dfb74 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -3,6 +3,7 @@ #pragma once #include "zeek-config.h" +#include "IntrusivePtr.h" #include "NetVar.h" #include "IPAddr.h" #include "Var.h" // for internal_type() @@ -79,7 +80,11 @@ public: /** * Returns record value of type "EncapsulatingConn" representing the tunnel. */ - RecordVal* GetRecordVal() const; + IntrusivePtr ToVal() const; + + [[deprecated("Remove in v4.1. Use ToVal() instead.")]] + RecordVal* GetRecordVal() const + { return ToVal().release(); } friend bool operator==(const EncapsulatingConn& ec1, const EncapsulatingConn& ec2) @@ -190,20 +195,24 @@ public: * Get the value of type "EncapsulatingConnVector" represented by the * entire encapsulation chain. */ - VectorVal* GetVectorVal() const + IntrusivePtr ToVal() const { - VectorVal* vv = new VectorVal( + auto vv = make_intrusive( internal_type("EncapsulatingConnVector")->AsVectorType()); if ( conns ) { for ( size_t i = 0; i < conns->size(); ++i ) - vv->Assign(i, (*conns)[i].GetRecordVal()); + vv->Assign(i, (*conns)[i].ToVal()); } return vv; } + [[deprecated("Remove in v4.1. Use ToVal() instead.")]] + VectorVal* GetVectorVal() const + { return ToVal().release(); } + friend bool operator==(const EncapsulationStack& e1, const EncapsulationStack& e2); From df65d1e82901a5a3824af571cd17f23cd51eef54 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 10:40:55 -0700 Subject: [PATCH 003/151] Deprecate ListVal::ConvertToSet(), add ListVal::ToSetVal() --- src/DNS_Mgr.cc | 10 +++------- src/Val.cc | 9 +++++++-- src/Val.h | 3 +++ src/zeek.bif | 5 ++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 9d1ec75e87..fcd3cd7eb5 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -297,7 +297,7 @@ IntrusivePtr DNS_Mapping::AddrsSet() { if ( ! l ) return empty_addr_set(); - return {AdoptRef{}, l->ConvertToSet()}; + return l->ToSetVal(); } IntrusivePtr DNS_Mapping::Host() @@ -479,7 +479,7 @@ static IntrusivePtr fake_name_lookup_result(const char* name) KeyedHash::StaticHash128(name, strlen(name), &hash); auto hv = make_intrusive(TYPE_ADDR); hv->Append(new AddrVal(reinterpret_cast(&hash))); - return {AdoptRef{}, hv->ConvertToSet()}; + return hv->ToSetVal(); } static const char* fake_text_lookup_result(const char* name) @@ -715,11 +715,7 @@ void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* dm, if ( ! e ) return; - mgr.Enqueue(e, - BuildMappingVal(dm), - IntrusivePtr{AdoptRef{}, l1->ConvertToSet()}, - IntrusivePtr{AdoptRef{}, l2->ConvertToSet()} - ); + mgr.Enqueue(e, BuildMappingVal(dm), l1->ToSetVal(), l2->ToSetVal()); } void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* old_dm, DNS_Mapping* new_dm) diff --git a/src/Val.cc b/src/Val.cc index 24c423993f..aba7d6722b 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1226,7 +1226,7 @@ void ListVal::Append(Val* v) type->AsTypeList()->Append({NewRef{}, v->Type()}); } -TableVal* ListVal::ConvertToSet() const +IntrusivePtr ListVal::ToSetVal() const { if ( tag == TYPE_ANY ) Internal("conversion of heterogeneous list to set"); @@ -1235,7 +1235,7 @@ TableVal* ListVal::ConvertToSet() const IntrusivePtr{NewRef{}, type->AsTypeList()->PureType()}); set_index->Append(base_type(tag)); auto s = make_intrusive(std::move(set_index), nullptr); - TableVal* t = new TableVal(std::move(s)); + auto t = make_intrusive(std::move(s)); for ( const auto& val : vals ) t->Assign(val, nullptr); @@ -1243,6 +1243,11 @@ TableVal* ListVal::ConvertToSet() const return t; } +TableVal* ListVal::ConvertToSet() const + { + return ToSetVal().release(); + } + void ListVal::Describe(ODesc* d) const { if ( d->IsBinary() || d->IsPortable() ) diff --git a/src/Val.h b/src/Val.h index 1bcc5cc147..0ba76d7e33 100644 --- a/src/Val.h +++ b/src/Val.h @@ -644,6 +644,9 @@ public: void Append(Val* v); // Returns a Set representation of the list (which must be homogeneous). + IntrusivePtr ToSetVal() const; + + [[deprecated("Remove in v4.1. Use ToSetVal() instead.")]] TableVal* ConvertToSet() const; const val_list* Vals() const { return &vals; } diff --git a/src/zeek.bif b/src/zeek.bif index 70674fe43b..f3b498e80c 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -3525,9 +3525,8 @@ public: { ListVal* lv = new ListVal(TYPE_ADDR); lv->Append(new AddrVal("0.0.0.0")); - Val* result = lv->ConvertToSet(); - trigger->Cache(call, result); - Unref(result); + auto result = lv->ToSetVal(); + trigger->Cache(call, result.get()); Unref(lv); } From b422f68b88cde294c8773dff7548b9a062e3fa1d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 11:36:35 -0700 Subject: [PATCH 004/151] Deprecant ListVal::Append(Val*) and add IntrusivePtr version --- src/CompHash.cc | 11 +++++------ src/DNS_Mgr.cc | 6 +++--- src/Expr.cc | 10 +++++----- src/Val.cc | 22 ++++++++++++++-------- src/Val.h | 7 +++++++ src/broker/Data.cc | 4 ++-- src/file_analysis/AnalyzerSet.cc | 4 ++-- src/input/Manager.cc | 8 ++++---- src/zeek.bif | 2 +- 9 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index f6f982685d..e403036fff 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -229,7 +229,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, while ( tbl->NextEntry(k, it) ) { hashkeys[k] = idx++; - lv->Append(tv->RecoverIndex(k).release()); + lv->Append(tv->RecoverIndex(k)); } for ( auto& kv : hashkeys ) @@ -349,9 +349,8 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const // re-introduce const on the recursive call, it should // be okay; the only thing is that the ListVal unref's it. Val* ncv = (Val*) v; - ncv->Ref(); - lv.Append(ncv); - HashKey* hk = ComputeHash(&lv, type_check); + lv.Append({NewRef{}, ncv}); + HashKey* hk = ComputeHash(&lv, type_check); return hk; } @@ -726,7 +725,7 @@ IntrusivePtr CompositeHash::RecoverVals(const HashKey* k) const IntrusivePtr v; kp = RecoverOneVal(k, kp, k_end, type, &v, false); ASSERT(v); - l->Append(v.release()); + l->Append(std::move(v)); } if ( kp != k_end ) @@ -1016,7 +1015,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, IntrusivePtr v; BroType* it = (*tl->Types())[i]; kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false); - lv->Append(v.release()); + lv->Append(std::move(v)); } *pval = std::move(lv); diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index fcd3cd7eb5..e40c06e1dd 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -285,7 +285,7 @@ IntrusivePtr DNS_Mapping::Addrs() auto addrs_val = make_intrusive(TYPE_ADDR); for ( int i = 0; i < num_addrs; ++i ) - addrs_val->Append(new AddrVal(addrs[i])); + addrs_val->Append(make_intrusive(addrs[i])); } return addrs_val; @@ -478,7 +478,7 @@ static IntrusivePtr fake_name_lookup_result(const char* name) hash128_t hash; KeyedHash::StaticHash128(name, strlen(name), &hash); auto hv = make_intrusive(TYPE_ADDR); - hv->Append(new AddrVal(reinterpret_cast(&hash))); + hv->Append(make_intrusive(reinterpret_cast(&hash))); return hv->ToSetVal(); } @@ -900,7 +900,7 @@ IntrusivePtr DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2) if ( j >= al2->Length() ) // Didn't find it. - delta->Append(al1->Index(i)->Ref()); + delta->Append({NewRef{}, al1->Index(i)}); } return delta; diff --git a/src/Expr.cc b/src/Expr.cc index eaa94ea4e6..468efeb114 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3830,13 +3830,13 @@ IntrusivePtr FlattenExpr::Fold(Val* v) const { if ( Val* fv = rv->Lookup(i) ) { - l->Append(fv->Ref()); + l->Append({NewRef{}, fv}); continue; } const RecordType* rv_t = rv->Type()->AsRecordType(); if ( const Attr* fa = rv_t->FieldDecl(i)->FindAttr(ATTR_DEFAULT) ) - l->Append(fa->AttrExpr()->Eval(nullptr).release()); + l->Append(fa->AttrExpr()->Eval(nullptr)); else RuntimeError("missing field value"); @@ -4478,7 +4478,7 @@ IntrusivePtr ListExpr::Eval(Frame* f) const return nullptr; } - v->Append(ev.release()); + v->Append(std::move(ev)); } return v; @@ -4570,7 +4570,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co if ( ! vi ) return nullptr; - v->Append(vi.release()); + v->Append(std::move(vi)); } return v; @@ -4601,7 +4601,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co if ( ! vi ) return nullptr; - v->Append(vi.release()); + v->Append(std::move(vi)); } return v; diff --git a/src/Val.cc b/src/Val.cc index aba7d6722b..c6af0d4be1 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1214,7 +1214,7 @@ RE_Matcher* ListVal::BuildRE() const return re; } -void ListVal::Append(Val* v) +void ListVal::Append(IntrusivePtr v) { if ( type->AsTypeList()->IsPure() ) { @@ -1222,8 +1222,14 @@ void ListVal::Append(Val* v) Internal("heterogeneous list in ListVal::Append"); } - vals.push_back(v); - type->AsTypeList()->Append({NewRef{}, v->Type()}); + auto vt = v->Type(); + vals.push_back(v.release()); + type->AsTypeList()->Append({NewRef{}, vt}); + } + +void ListVal::Append(Val* v) + { + Append({AdoptRef{}, v}); } IntrusivePtr ListVal::ToSetVal() const @@ -1280,7 +1286,7 @@ IntrusivePtr ListVal::DoClone(CloneState* state) state->NewClone(this, lv); for ( const auto& val : vals ) - lv->Append(val->Clone(state).release()); + lv->Append(val->Clone(state)); return lv; } @@ -2116,14 +2122,14 @@ ListVal* TableVal::ConvertToList(TypeTag t) const auto index = table_hash->RecoverVals(k); if ( t == TYPE_ANY ) - l->Append(index.release()); + l->Append(std::move(index)); else { // We're expecting a pure list, flatten the ListVal. if ( index->Length() != 1 ) InternalWarning("bad index in TableVal::ConvertToList"); - l->Append(index->Index(0)->Ref()); + l->Append({NewRef{}, index->Index(0)}); } delete k; @@ -2249,9 +2255,9 @@ bool TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr new_ loop_over_list(*vl, j) { if ( j == k ) - expd->Append(ind_k_i->Ref()); + expd->Append({NewRef{}, ind_k_i}); else - expd->Append((*vl)[j]->Ref()); + expd->Append({NewRef{}, (*vl)[j]}); } if ( ! ExpandAndInit(std::move(expd), new_val) ) diff --git a/src/Val.h b/src/Val.h index 0ba76d7e33..9e7d2b7dee 100644 --- a/src/Val.h +++ b/src/Val.h @@ -641,6 +641,13 @@ public: // The return RE_Matcher has not yet been compiled. RE_Matcher* BuildRE() const; + /** + * Appends a value to the list. + * @param v the value to append. + */ + void Append(IntrusivePtr v); + + [[deprecated("Remove in v4.1. Use Append(IntrusivePtr) instead.")]] void Append(Val* v); // Returns a Set representation of the list (which must be homogeneous). diff --git a/src/broker/Data.cc b/src/broker/Data.cc index ecea94861a..6e27cc7dd5 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -252,7 +252,7 @@ struct val_converter { if ( ! index_val ) return nullptr; - list_val->Append(index_val.release()); + list_val->Append(std::move(index_val)); } @@ -312,7 +312,7 @@ struct val_converter { if ( ! index_val ) return nullptr; - list_val->Append(index_val.release()); + list_val->Append(std::move(index_val)); } auto value_val = bro_broker::data_to_val(move(item.second), diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index 3ea6f5f925..1a7941a026 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -164,8 +164,8 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set) HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const { ListVal* lv = new ListVal(TYPE_ANY); - lv->Append(t.AsEnumVal()->Ref()); - lv->Append(args->Ref()); + lv->Append({NewRef{}, t.AsEnumVal()}); + lv->Append({NewRef{}, args}); HashKey* key = analyzer_hash->ComputeHash(lv, true); Unref(lv); if ( ! key ) diff --git a/src/input/Manager.cc b/src/input/Manager.cc index dcbc4f53c0..1947015b8f 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1010,7 +1010,7 @@ Val* Manager::RecordValToIndexVal(RecordVal *r) const { auto l = make_intrusive(TYPE_ANY); for ( int j = 0 ; j < num_fields; j++ ) - l->Append(r->LookupWithDefault(j).release()); + l->Append(r->LookupWithDefault(j)); idxval = std::move(l); } @@ -1037,11 +1037,11 @@ Val* Manager::ValueToIndexVal(const Stream* i, int num_fields, const RecordType for ( int j = 0 ; j < type->NumFields(); j++ ) { if ( type->FieldType(j)->Tag() == TYPE_RECORD ) - l->Append(ValueToRecordVal(i, vals, - type->FieldType(j)->AsRecordType(), &position, have_error)); + l->Append({AdoptRef{}, ValueToRecordVal(i, vals, + type->FieldType(j)->AsRecordType(), &position, have_error)}); else { - l->Append(ValueToVal(i, vals[position], type->FieldType(j), have_error)); + l->Append({AdoptRef{}, ValueToVal(i, vals[position], type->FieldType(j), have_error)}); position++; } } diff --git a/src/zeek.bif b/src/zeek.bif index f3b498e80c..be60804d7d 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -3524,7 +3524,7 @@ public: else { ListVal* lv = new ListVal(TYPE_ADDR); - lv->Append(new AddrVal("0.0.0.0")); + lv->Append(make_intrusive("0.0.0.0")); auto result = lv->ToSetVal(); trigger->Cache(call, result.get()); Unref(lv); From 5f57ceb70afba55c25e8b86d9ebdf19ce518dfcf Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 14:13:14 -0700 Subject: [PATCH 005/151] Switch ListVal to store IntrusivePtrs * Deprecates ListVal::Index() methods and replaces with ListVal::Idx() * Replaces ListVal::Vals() method with one that returns std::vector> rather than val_list --- src/CompHash.cc | 31 +++++----- src/DNS_Mgr.cc | 8 +-- src/Expr.cc | 24 ++++---- src/PrefixTable.cc | 6 +- src/Reporter.cc | 2 +- src/RuleMatcher.cc | 6 +- src/Sessions.cc | 2 +- src/Stmt.cc | 2 +- src/Val.cc | 82 +++++++++++++------------ src/Val.h | 22 ++++--- src/analyzer/Manager.cc | 2 +- src/broker/Data.cc | 2 +- src/broker/messaging.bif | 2 +- src/file_analysis/analyzer/x509/X509.cc | 4 +- src/input/Manager.cc | 4 +- src/logging/Manager.cc | 4 +- src/reporter.bif | 2 +- src/supervisor/Supervisor.cc | 2 +- src/zeek.bif | 4 +- 19 files changed, 111 insertions(+), 100 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index e403036fff..057858b719 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -238,7 +238,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, for ( auto& kv : hashkeys ) { auto idx = kv.second; - Val* key = lv->Index(idx); + Val* key = lv->Idx(idx).get(); if ( ! (kp1 = SingleValHash(type_check, kp1, key->Type(), key, false)) ) @@ -292,7 +292,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, kp1 = reinterpret_cast(kp+1); for ( int i = 0; i < lv->Length(); ++i ) { - Val* v = lv->Index(i); + Val* v = lv->Idx(i).get(); if ( ! (kp1 = SingleValHash(type_check, kp1, v->Type(), v, false)) ) return nullptr; @@ -371,14 +371,15 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const if ( type_check && v->Type()->Tag() != TYPE_LIST ) return nullptr; - const val_list* vl = v->AsListVal()->Vals(); - if ( type_check && vl->length() != tl->length() ) + auto lv = v->AsListVal(); + + if ( type_check && lv->Length() != tl->length() ) return nullptr; char* kp = k; loop_over_list(*tl, i) { - kp = SingleValHash(type_check, kp, (*tl)[i], (*vl)[i], false); + kp = SingleValHash(type_check, kp, (*tl)[i], lv->Idx(i).get(), false); if ( ! kp ) return nullptr; } @@ -390,11 +391,12 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) cons { if ( v->Type()->Tag() == TYPE_LIST ) { - const val_list* vl = v->AsListVal()->Vals(); - if ( type_check && vl->length() != 1 ) + auto lv = v->AsListVal(); + + if ( type_check && lv->Length() != 1 ) return nullptr; - v = (*vl)[0]; + v = lv->Idx(0).get(); } if ( type_check && v->Type()->InternalType() != singleton_tag ) @@ -536,7 +538,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, ListVal* lv = tv->ConvertToList(); for ( int i = 0; i < tv->Size(); ++i ) { - Val* key = lv->Index(i); + Val* key = lv->Idx(i).get(); sz = SingleTypeKeySize(key->Type(), key, type_check, sz, false, calc_static_size); if ( ! sz ) @@ -594,7 +596,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, ListVal* lv = const_cast(v->AsListVal()); for ( int i = 0; i < lv->Length(); ++i ) { - sz = SingleTypeKeySize(lv->Index(i)->Type(), lv->Index(i), + sz = SingleTypeKeySize(lv->Idx(i)->Type(), lv->Idx(i).get(), type_check, sz, false, calc_static_size); if ( ! sz) return 0; } @@ -631,21 +633,22 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_static_size) const { const type_list* tl = type->Types(); - const val_list* vl = nullptr; + if ( v ) { if ( type_check && v->Type()->Tag() != TYPE_LIST ) return 0; - vl = v->AsListVal()->Vals(); - if ( type_check && vl->length() != tl->length() ) + auto lv = v->AsListVal(); + + if ( type_check && lv->Length() != tl->length() ) return 0; } int sz = 0; loop_over_list(*tl, i) { - sz = SingleTypeKeySize((*tl)[i], v ? v->AsListVal()->Index(i) : nullptr, + sz = SingleTypeKeySize((*tl)[i], v ? v->AsListVal()->Idx(i).get() : nullptr, type_check, sz, false, calc_static_size); if ( ! sz ) return 0; diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index e40c06e1dd..a97c333a6a 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -888,19 +888,19 @@ IntrusivePtr DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2) for ( int i = 0; i < al1->Length(); ++i ) { - const IPAddr& al1_i = al1->Index(i)->AsAddr(); + const IPAddr& al1_i = al1->Idx(i)->AsAddr(); int j; for ( j = 0; j < al2->Length(); ++j ) { - const IPAddr& al2_j = al2->Index(j)->AsAddr(); + const IPAddr& al2_j = al2->Idx(j)->AsAddr(); if ( al1_i == al2_j ) break; } if ( j >= al2->Length() ) // Didn't find it. - delta->Append({NewRef{}, al1->Index(i)}); + delta->Append(al1->Idx(i)); } return delta; @@ -910,7 +910,7 @@ void DNS_Mgr::DumpAddrList(FILE* f, ListVal* al) { for ( int i = 0; i < al->Length(); ++i ) { - const IPAddr& al_i = al->Index(i)->AsAddr(); + const IPAddr& al_i = al->Idx(i)->AsAddr(); fprintf(f, "%s%s", i > 0 ? "," : "", al_i.AsString().c_str()); } } diff --git a/src/Expr.cc b/src/Expr.cc index 468efeb114..bad6240e7d 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -311,7 +311,7 @@ ConstExpr::ConstExpr(IntrusivePtr arg_val) : Expr(EXPR_CONST), val(std::move(arg_val)) { if ( val->Type()->Tag() == TYPE_LIST && val->AsListVal()->Length() == 1 ) - val = {NewRef{}, val->AsListVal()->Index(0)}; + val = val->AsListVal()->Idx(0); SetType({NewRef{}, val->Type()}); } @@ -2587,7 +2587,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const if ( ! v2 ) return nullptr; - Val* indv = v2->AsListVal()->Index(0); + Val* indv = v2->AsListVal()->Idx(0).get(); if ( is_vector(indv) ) { @@ -2662,8 +2662,8 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const size_t len = vect->Size(); auto result = make_intrusive(vect->Type()->AsVectorType()); - bro_int_t first = get_slice_index(lv->Index(0)->CoerceToInt(), len); - bro_int_t last = get_slice_index(lv->Index(1)->CoerceToInt(), len); + bro_int_t first = get_slice_index(lv->Idx(0)->CoerceToInt(), len); + bro_int_t last = get_slice_index(lv->Idx(1)->CoerceToInt(), len); bro_int_t sub_length = last - first; if ( sub_length >= 0 ) @@ -2695,7 +2695,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const if ( lv->Length() == 1 ) { - bro_int_t idx = lv->Index(0)->AsInt(); + bro_int_t idx = lv->Idx(0)->AsInt(); if ( idx < 0 ) idx += len; @@ -2705,8 +2705,8 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const } else { - bro_int_t first = get_slice_index(lv->Index(0)->AsInt(), len); - bro_int_t last = get_slice_index(lv->Index(1)->AsInt(), len); + bro_int_t first = get_slice_index(lv->Idx(0)->AsInt(), len); + bro_int_t last = get_slice_index(lv->Idx(1)->AsInt(), len); bro_int_t substring_len = last - first; if ( substring_len < 0 ) @@ -2759,8 +2759,8 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) if ( lv->Length() > 1 ) { auto len = v1_vect->Size(); - bro_int_t first = get_slice_index(lv->Index(0)->CoerceToInt(), len); - bro_int_t last = get_slice_index(lv->Index(1)->CoerceToInt(), len); + bro_int_t first = get_slice_index(lv->Idx(0)->CoerceToInt(), len); + bro_int_t last = get_slice_index(lv->Idx(1)->CoerceToInt(), len); // Remove the elements from the vector within the slice for ( auto idx = first; idx < last; idx++ ) @@ -3053,7 +3053,7 @@ IntrusivePtr RecordConstructorExpr::Fold(Val* v) const auto rv = make_intrusive(rt); for ( int i = 0; i < lv->Length(); ++i ) - rv->Assign(i, lv->Index(i)->Ref()); + rv->Assign(i, lv->Idx(i)); return rv; } @@ -4764,11 +4764,11 @@ void ListExpr::Assign(Frame* f, IntrusivePtr v) { ListVal* lv = v->AsListVal(); - if ( exprs.length() != lv->Vals()->length() ) + if ( exprs.length() != lv->Length() ) RuntimeError("mismatch in list lengths"); loop_over_list(exprs, i) - exprs[i]->Assign(f, {NewRef{}, (*lv->Vals())[i]}); + exprs[i]->Assign(f, lv->Idx(i)); } TraversalCode ListExpr::Traverse(TraversalCallback* cb) const diff --git a/src/PrefixTable.cc b/src/PrefixTable.cc index 765108f507..9506539b69 100644 --- a/src/PrefixTable.cc +++ b/src/PrefixTable.cc @@ -45,7 +45,7 @@ void* PrefixTable::Insert(const Val* value, void* data) // [elem] -> elem if ( value->Type()->Tag() == TYPE_LIST && value->AsListVal()->Length() == 1 ) - value = value->AsListVal()->Index(0); + value = value->AsListVal()->Idx(0).get(); switch ( value->Type()->Tag() ) { case TYPE_ADDR: @@ -105,7 +105,7 @@ void* PrefixTable::Lookup(const Val* value, bool exact) const // [elem] -> elem if ( value->Type()->Tag() == TYPE_LIST && value->AsListVal()->Length() == 1 ) - value = value->AsListVal()->Index(0); + value = value->AsListVal()->Idx(0).get(); switch ( value->Type()->Tag() ) { case TYPE_ADDR: @@ -144,7 +144,7 @@ void* PrefixTable::Remove(const Val* value) // [elem] -> elem if ( value->Type()->Tag() == TYPE_LIST && value->AsListVal()->Length() == 1 ) - value = value->AsListVal()->Index(0); + value = value->AsListVal()->Idx(0).get(); switch ( value->Type()->Tag() ) { case TYPE_ADDR: diff --git a/src/Reporter.cc b/src/Reporter.cc index b0e1955b45..4f6393d78d 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -79,7 +79,7 @@ void Reporter::InitOptions() while ( (v = wl_table->NextEntry(k, c)) ) { auto index = wl_val->RecoverIndex(k); - std::string key = index->Index(0)->AsString()->CheckString(); + std::string key = index->Idx(0)->AsString()->CheckString(); weird_sampling_whitelist.emplace(move(key)); delete k; } diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index c3d7a805f1..2cfc56b750 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -1362,9 +1362,9 @@ void id_to_maskedvallist(const char* id, maskedvalue_list* append_to, if ( v->Type()->Tag() == TYPE_TABLE ) { ListVal* lv = v->AsTableVal()->ConvertToPureList(); - val_list* vals = lv->Vals(); - for ( const auto& val : *vals ) - if ( ! val_to_maskedval(val, append_to, prefix_vector) ) + + for ( const auto& val : lv->Vals() ) + if ( ! val_to_maskedval(val.get(), append_to, prefix_vector) ) { Unref(lv); return; diff --git a/src/Sessions.cc b/src/Sessions.cc index a2dc0fe248..fd40f5cc40 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -1220,7 +1220,7 @@ bool NetSessions::IsLikelyServerPort(uint32_t port, TransportProto proto) const { ListVal* lv = likely_server_ports->ConvertToPureList(); for ( int i = 0; i < lv->Length(); i++ ) - port_cache.insert(lv->Index(i)->InternalUnsigned()); + port_cache.insert(lv->Idx(i)->InternalUnsigned()); have_cache = true; Unref(lv); } diff --git a/src/Stmt.cc b/src/Stmt.cc index 9ea9639225..fdb4b96c4b 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1196,7 +1196,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const f->SetElement(value_var.get(), current_tev->Value()->Ref()); for ( int i = 0; i < ind_lv->Length(); i++ ) - f->SetElement((*loop_vars)[i], ind_lv->Index(i)->Ref()); + f->SetElement((*loop_vars)[i], ind_lv->Idx(i)->Ref()); flow = FLOW_NEXT; diff --git a/src/Val.cc b/src/Val.cc index c6af0d4be1..5e75aee7f3 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -538,7 +538,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* { auto lv = tval->RecoverIndex(k); delete k; - Val* entry_key = lv->Length() == 1 ? lv->Index(0) : lv.get(); + Val* entry_key = lv->Length() == 1 ? lv->Idx(0).get() : lv.get(); if ( tval->Type()->IsSet() ) BuildJSON(writer, entry_key, only_loggable, re); @@ -608,7 +608,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* auto* lval = val->AsListVal(); size_t size = lval->Length(); for (size_t i = 0; i < size; i++) - BuildJSON(writer, lval->Index(i), only_loggable, re); + BuildJSON(writer, lval->Idx(i).get(), only_loggable, re); writer.EndArray(); break; @@ -1189,14 +1189,12 @@ ListVal::ListVal(TypeTag t) ListVal::~ListVal() { - for ( const auto& val : vals ) - Unref(val); Unref(type); } IntrusivePtr ListVal::SizeVal() const { - return val_mgr->Count(vals.length()); + return val_mgr->Count(vals.size()); } RE_Matcher* ListVal::BuildRE() const @@ -1223,7 +1221,7 @@ void ListVal::Append(IntrusivePtr v) } auto vt = v->Type(); - vals.push_back(v.release()); + vals.emplace_back(std::move(v)); type->AsTypeList()->Append({NewRef{}, vt}); } @@ -1244,7 +1242,7 @@ IntrusivePtr ListVal::ToSetVal() const auto t = make_intrusive(std::move(s)); for ( const auto& val : vals ) - t->Assign(val, nullptr); + t->Assign(val.get(), nullptr); return t; } @@ -1260,13 +1258,13 @@ void ListVal::Describe(ODesc* d) const { type->Describe(d); d->SP(); - d->Add(vals.length()); + d->Add(static_cast(vals.size())); d->SP(); } - loop_over_list(vals, i) + for ( auto i = 0u; i < vals.size(); ++i ) { - if ( i > 0 ) + if ( i > 0u ) { if ( d->IsReadable() || d->IsPortable() ) { @@ -1282,7 +1280,7 @@ void ListVal::Describe(ODesc* d) const IntrusivePtr ListVal::DoClone(CloneState* state) { auto lv = make_intrusive(tag); - lv->vals.resize(vals.length()); + lv->vals.reserve(vals.size()); state->NewClone(this, lv); for ( const auto& val : vals ) @@ -1297,8 +1295,8 @@ unsigned int ListVal::MemoryAllocation() const for ( const auto& val : vals ) size += val->MemoryAllocation(); - return size + padded_sizeof(*this) + vals.MemoryAllocation() - padded_sizeof(vals) - + type->MemoryAllocation(); + size += pad_size(vals.capacity() * sizeof(decltype(vals)::value_type)); + return size + padded_sizeof(*this) + type->MemoryAllocation(); } TableEntryVal* TableEntryVal::Clone(Val::CloneState* state) @@ -1772,7 +1770,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) reporter->InternalError("bad singleton list index"); for ( int i = 0; i < iv->Length(); ++i ) - if ( ! ExpandAndInit({NewRef{}, iv->Index(i)}, new_val) ) + if ( ! ExpandAndInit(iv->Idx(i), new_val) ) return false; return true; @@ -1780,22 +1778,25 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) else { // Compound table. - val_list* vl = iv->Vals(); - loop_over_list(*vl, i) + int i; + + for ( i = 0; i < iv->Length(); ++i ) { + const auto& v = iv->Idx(i); // ### if CompositeHash::ComputeHash did flattening // of 1-element lists (like ComputeSingletonHash does), // then we could optimize here. - BroType* t = (*vl)[i]->Type(); + BroType* t = v->Type(); + if ( t->IsSet() || t->Tag() == TYPE_LIST ) break; } - if ( i >= vl->length() ) + if ( i >= iv->Length() ) // Nothing to expand. return CheckAndAssign(index.get(), std::move(new_val)); else - return ExpandCompoundAndInit(vl, i, std::move(new_val)); + return ExpandCompoundAndInit(iv, i, std::move(new_val)); } } @@ -1855,11 +1856,11 @@ IntrusivePtr TableVal::Default(Val* index) if ( index->Type()->Tag() == TYPE_LIST ) { - const val_list* vl0 = index->AsListVal()->Vals(); - vl.reserve(vl0->length()); + auto lv = index->AsListVal(); + vl.reserve(lv->Length()); - for ( const auto& v : *vl0 ) - vl.emplace_back(NewRef{}, v); + for ( const auto& v : lv->Vals() ) + vl.emplace_back(v); } else vl.emplace_back(NewRef{}, index); @@ -2026,10 +2027,10 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe } const Func* f = thefunc->AsFunc(); - const auto& index_list = *index->AsListVal()->Vals(); + auto lv = index->AsListVal(); zeek::Args vl; - vl.reserve(2 + index_list.length() + table_type->IsTable()); + vl.reserve(2 + lv->Length() + table_type->IsTable()); vl.emplace_back(NewRef{}, this); switch ( tpe ) @@ -2047,8 +2048,8 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe vl.emplace_back(BifType::Enum::TableChange->GetVal(BifEnum::TableChange::TABLE_ELEMENT_EXPIRED)); } - for ( const auto& v : *index->AsListVal()->Vals() ) - vl.emplace_back(NewRef{}, v); + for ( const auto& v : lv->Vals() ) + vl.emplace_back(v); if ( table_type->IsTable() ) vl.emplace_back(NewRef{}, old_value); @@ -2129,7 +2130,7 @@ ListVal* TableVal::ConvertToList(TypeTag t) const if ( index->Length() != 1 ) InternalWarning("bad index in TableVal::ConvertToList"); - l->Append({NewRef{}, index->Index(0)}); + l->Append(index->Idx(0)); } delete k; @@ -2241,23 +2242,26 @@ void TableVal::Describe(ODesc* d) const } } -bool TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr new_val) +bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr new_val) { - Val* ind_k_v = (*vl)[k]; + Val* ind_k_v = lv->Idx(k).get(); auto ind_k = ind_k_v->Type()->IsSet() ? IntrusivePtr{AdoptRef{}, ind_k_v->AsTableVal()->ConvertToList()} : IntrusivePtr{NewRef{}, ind_k_v->AsListVal()}; for ( int i = 0; i < ind_k->Length(); ++i ) { - Val* ind_k_i = ind_k->Index(i); + const auto& ind_k_i = ind_k->Idx(i); auto expd = make_intrusive(TYPE_ANY); - loop_over_list(*vl, j) + + for ( auto j = 0; j < lv->Length(); ++j ) { + const auto& v = lv->Idx(j); + if ( j == k ) - expd->Append({NewRef{}, ind_k_i}); + expd->Append(ind_k_i); else - expd->Append({NewRef{}, (*vl)[j]}); + expd->Append(v); } if ( ! ExpandAndInit(std::move(expd), new_val) ) @@ -2474,12 +2478,12 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) if ( ! any_idiom ) { - const auto& index_list = *idx->AsListVal()->Vals(); - vl.reserve(1 + index_list.length()); + auto lv = idx->AsListVal(); + vl.reserve(1 + lv->Length()); vl.emplace_back(NewRef{}, this); - for ( const auto& v : index_list ) - vl.emplace_back(NewRef{}, v); + for ( const auto& v : lv->Vals() ) + vl.emplace_back(v); } else { @@ -2489,7 +2493,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) ListVal* idx_list = idx->AsListVal(); // Flatten if only one element if ( idx_list->Length() == 1 ) - vl.emplace_back(NewRef{}, idx_list->Index(0)); + vl.emplace_back(idx_list->Idx(0)); else vl.emplace_back(std::move(idx)); } diff --git a/src/Val.h b/src/Val.h index 9e7d2b7dee..7b35629d38 100644 --- a/src/Val.h +++ b/src/Val.h @@ -627,9 +627,14 @@ public: IntrusivePtr SizeVal() const override; - int Length() const { return vals.length(); } - Val* Index(const int n) { return vals[n]; } - const Val* Index(const int n) const { return vals[n]; } + int Length() const { return vals.size(); } + + const IntrusivePtr& Idx(size_t i) const { return vals[i]; } + + [[deprecated("Remove in v4.1. Use Idx() instead")]] + Val* Index(const int n) { return vals[n].get(); } + [[deprecated("Remove in v4.1. Use Idx() instead")]] + const Val* Index(const int n) const { return vals[n].get(); } // Returns an RE_Matcher() that will match any string that // includes embedded within it one of the patterns listed @@ -656,8 +661,7 @@ public: [[deprecated("Remove in v4.1. Use ToSetVal() instead.")]] TableVal* ConvertToSet() const; - const val_list* Vals() const { return &vals; } - val_list* Vals() { return &vals; } + const std::vector>& Vals() const { return vals; } void Describe(ODesc* d) const override; @@ -666,7 +670,7 @@ public: protected: IntrusivePtr DoClone(CloneState* state) override; - val_list vals; + std::vector> vals; TypeTag tag; }; @@ -867,7 +871,7 @@ protected: void RebuildTable(ParseTimeTableState ptts); void CheckExpireAttr(attr_tag at); - bool ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr new_val); + bool ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr new_val); bool CheckAndAssign(Val* index, IntrusivePtr new_val); // Calculates default value for index. Returns 0 if none. @@ -1014,7 +1018,7 @@ public: template bool Assign(Val* index, E&& element) { - return Assign(index->AsListVal()->Index(0)->CoerceToUnsigned(), + return Assign(index->AsListVal()->Idx(0)->CoerceToUnsigned(), std::forward(element)); } @@ -1032,7 +1036,7 @@ public: Val* Lookup(unsigned int index) const; Val* Lookup(Val* index) { - bro_uint_t i = index->AsListVal()->Index(0)->CoerceToUnsigned(); + bro_uint_t i = index->AsListVal()->Idx(0)->CoerceToUnsigned(); return Lookup(static_cast(i)); } diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index c9c3546f60..b7c9b1af3d 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -99,7 +99,7 @@ void Manager::InitPostScript() auto port_list = table_val->ConvertToPureList(); for ( auto i = 0; i < port_list->Length(); ++i ) - vxlan_ports.emplace_back(port_list->Index(i)->AsPortVal()->Port()); + vxlan_ports.emplace_back(port_list->Idx(i)->AsPortVal()->Port()); Unref(port_list); } diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 6e27cc7dd5..6324c0339b 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -912,7 +912,7 @@ broker::expected bro_broker::val_to_data(const Val* v) for ( auto k = 0; k < vl->Length(); ++k ) { - auto key_part = val_to_data((*vl->Vals())[k]); + auto key_part = val_to_data(vl->Idx(k).get()); if ( ! key_part ) return broker::ec::invalid_data; diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index caa373cb68..fdc0fa848b 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -39,7 +39,7 @@ std::set val_to_topic_set(Val* val) while ( tbl->NextEntry(k, c) ) { auto index = val->AsTableVal()->RecoverIndex(k); - rval.emplace(index->Index(0)->AsString()->CheckString()); + rval.emplace(index->Idx(0)->AsString()->CheckString()); delete k; } } diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 535dbc27d1..6e58a8f183 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -249,8 +249,8 @@ X509_STORE* file_analysis::X509::GetRootStore(TableVal* root_certs) // Build the validation store for ( int i = 0; i < idxs->Length(); ++i ) { - Val* key = idxs->Index(i); - StringVal *sv = root_certs->Lookup(key)->AsStringVal(); + const auto& key = idxs->Idx(i); + StringVal *sv = root_certs->Lookup(key.get())->AsStringVal(); assert(sv); const uint8_t* data = sv->Bytes(); ::X509* x = d2i_X509(NULL, &data, sv->Len()); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 1947015b8f..250b790893 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -284,7 +284,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) while ( (v = info->config->AsTable()->NextEntry(k, c)) ) { auto index = info->config->RecoverIndex(k); - string key = index->Index(0)->AsString()->CheckString(); + string key = index->Idx(0)->AsString()->CheckString(); string value = v->Value()->AsString()->CheckString(); rinfo.config.insert(std::make_pair(copy_string(key.c_str()), copy_string(value.c_str()))); delete k; @@ -1919,7 +1919,7 @@ RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType *request_type, fieldVal = ListValToRecordVal(list, request_type->FieldType(i)->AsRecordType(), position); else { - fieldVal = list->Index(*position); + fieldVal = list->Idx(*position).get(); (*position)++; } diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index a41b204369..f68f5be4d9 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -870,7 +870,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) while ( (v = filter->config->AsTable()->NextEntry(k, c)) ) { auto index = filter->config->RecoverIndex(k); - string key = index->Index(0)->AsString()->CheckString(); + string key = index->Idx(0)->AsString()->CheckString(); string value = v->Value()->AsString()->CheckString(); info->config.insert(std::make_pair(copy_string(key.c_str()), copy_string(value.c_str()))); delete k; @@ -1022,7 +1022,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) lval->val.set_val.vals = new threading::Value* [lval->val.set_val.size]; for ( int i = 0; i < lval->val.set_val.size; i++ ) - lval->val.set_val.vals[i] = ValToLogVal(set->Index(i)); + lval->val.set_val.vals[i] = ValToLogVal(set->Idx(i).get()); Unref(set); break; diff --git a/src/reporter.bif b/src/reporter.bif index 87ac5f9338..e37691da5f 100644 --- a/src/reporter.bif +++ b/src/reporter.bif @@ -180,7 +180,7 @@ function Reporter::set_weird_sampling_whitelist%(weird_sampling_whitelist: strin while ( (v = wl_table->NextEntry(k, c)) ) { auto index = wl_val->RecoverIndex(k); - string key = index->Index(0)->AsString()->CheckString(); + string key = index->Idx(0)->AsString()->CheckString(); whitelist_set.emplace(move(key)); delete k; } diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 28b03434c5..75e08bdef1 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1026,7 +1026,7 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node) { auto key = cluster_table_val->RecoverIndex(k); delete k; - auto name = key->Index(0)->AsStringVal()->ToStdString(); + auto name = key->Idx(0)->AsStringVal()->ToStdString(); auto rv = v->Value()->AsRecordVal(); Supervisor::ClusterEndpoint ep; diff --git a/src/zeek.bif b/src/zeek.bif index be60804d7d..de067d7b40 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -405,8 +405,8 @@ static bool prepare_environment(TableVal* tbl, bool set) for ( int i = 0; i < idxs->Length(); ++i ) { - Val* key = idxs->Index(i); - auto val = tbl->Lookup(key, false); + const auto& key = idxs->Idx(i); + auto val = tbl->Lookup(key.get(), false); if ( key->Type()->Tag() != TYPE_STRING || val->Type()->Tag() != TYPE_STRING ) From b096e552d37b07b4a254441b300eca28ad3d8199 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 14:58:43 -0700 Subject: [PATCH 006/151] Deprecate TableVal::ConvertToList() and TableVal::ConvertToPureList() Replaced with ToListVal() and ToPureListVal() that return IntrusivePtr --- src/CompHash.cc | 10 +--------- src/RuleMatcher.cc | 7 +------ src/Sessions.cc | 3 +-- src/Val.cc | 26 +++++++++++++++++-------- src/Val.h | 8 ++++++++ src/Var.cc | 4 ++-- src/analyzer/Manager.cc | 4 +--- src/file_analysis/analyzer/x509/X509.cc | 4 +--- src/logging/Manager.cc | 7 +++---- src/zeek.bif | 2 +- 10 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index 057858b719..749dda19ab 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -535,17 +535,14 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, sz = SizeAlign(sz, sizeof(int)); TableVal* tv = const_cast(v->AsTableVal()); - ListVal* lv = tv->ConvertToList(); + auto lv = tv->ToListVal(); for ( int i = 0; i < tv->Size(); ++i ) { Val* key = lv->Idx(i).get(); sz = SingleTypeKeySize(key->Type(), key, type_check, sz, false, calc_static_size); if ( ! sz ) - { - Unref(lv); return 0; - } if ( ! bt->IsSet() ) { @@ -553,15 +550,10 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, sz = SingleTypeKeySize(val->Type(), val.get(), type_check, sz, false, calc_static_size); if ( ! sz ) - { - Unref(lv); return 0; - } } } - Unref(lv); - break; } diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index 2cfc56b750..b624008271 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -1361,16 +1361,11 @@ void id_to_maskedvallist(const char* id, maskedvalue_list* append_to, if ( v->Type()->Tag() == TYPE_TABLE ) { - ListVal* lv = v->AsTableVal()->ConvertToPureList(); + auto lv = v->AsTableVal()->ToPureListVal(); for ( const auto& val : lv->Vals() ) if ( ! val_to_maskedval(val.get(), append_to, prefix_vector) ) - { - Unref(lv); return; - } - - Unref(lv); } else diff --git a/src/Sessions.cc b/src/Sessions.cc index fd40f5cc40..8843300f02 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -1218,11 +1218,10 @@ bool NetSessions::IsLikelyServerPort(uint32_t port, TransportProto proto) const if ( ! have_cache ) { - ListVal* lv = likely_server_ports->ConvertToPureList(); + auto lv = likely_server_ports->ToPureListVal(); for ( int i = 0; i < lv->Length(); i++ ) port_cache.insert(lv->Idx(i)->InternalUnsigned()); have_cache = true; - Unref(lv); } // We exploit our knowledge of PortVal's internal storage mechanism diff --git a/src/Val.cc b/src/Val.cc index 5e75aee7f3..925a1c4c76 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1755,7 +1755,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) if ( index_type->IsSet() ) { - index = {AdoptRef{}, index->AsTableVal()->ConvertToList()}; + index = index->AsTableVal()->ToListVal(); return ExpandAndInit(std::move(index), std::move(new_val)); } @@ -2110,9 +2110,9 @@ IntrusivePtr TableVal::Delete(const HashKey* k) return va; } -ListVal* TableVal::ConvertToList(TypeTag t) const +IntrusivePtr TableVal::ToListVal(TypeTag t) const { - ListVal* l = new ListVal(t); + auto l = make_intrusive(t); const PDict* tbl = AsTable(); IterCookie* c = tbl->InitForIteration(); @@ -2128,7 +2128,7 @@ ListVal* TableVal::ConvertToList(TypeTag t) const { // We're expecting a pure list, flatten the ListVal. if ( index->Length() != 1 ) - InternalWarning("bad index in TableVal::ConvertToList"); + InternalWarning("bad index in TableVal::ToListVal"); l->Append(index->Idx(0)); } @@ -2139,16 +2139,26 @@ ListVal* TableVal::ConvertToList(TypeTag t) const return l; } -ListVal* TableVal::ConvertToPureList() const +ListVal* TableVal::ConvertToList(TypeTag t) const + { + return ToListVal().release(); + } + +IntrusivePtr TableVal::ToPureListVal() const { type_list* tl = table_type->Indices()->Types(); if ( tl->length() != 1 ) { - InternalWarning("bad index type in TableVal::ConvertToPureList"); + InternalWarning("bad index type in TableVal::ToPureListVal"); return nullptr; } - return ConvertToList((*tl)[0]->Tag()); + return ToListVal((*tl)[0]->Tag()); + } + +ListVal* TableVal::ConvertToPureList() const + { + return ToPureListVal().release(); } Attr* TableVal::FindAttr(attr_tag t) const @@ -2246,7 +2256,7 @@ bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr new_v { Val* ind_k_v = lv->Idx(k).get(); auto ind_k = ind_k_v->Type()->IsSet() ? - IntrusivePtr{AdoptRef{}, ind_k_v->AsTableVal()->ConvertToList()} : + ind_k_v->AsTableVal()->ToListVal() : IntrusivePtr{NewRef{}, ind_k_v->AsListVal()}; for ( int i = 0; i < ind_k->Length(); ++i ) diff --git a/src/Val.h b/src/Val.h index 7b35629d38..3aa128c5f6 100644 --- a/src/Val.h +++ b/src/Val.h @@ -808,7 +808,15 @@ public: IntrusivePtr Delete(const HashKey* k); // Returns a ListVal representation of the table (which must be a set). + IntrusivePtr ToListVal(TypeTag t = TYPE_ANY) const; + + // Returns a ListVal representation of the table (which must be a set + // with non-composite index type). + IntrusivePtr ToPureListVal() const; + + [[deprecated("Remove in v4.1. Use ToListVal() instead.")]] ListVal* ConvertToList(TypeTag t=TYPE_ANY) const; + [[deprecated("Remove in v4.1. Use ToPureListVal() instead.")]] ListVal* ConvertToPureList() const; // must be single index type void SetAttrs(IntrusivePtr attrs); diff --git a/src/Var.cc b/src/Var.cc index b170c20ddc..54837ae8c3 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -749,8 +749,8 @@ ListVal* internal_list_val(const char* name) else if ( v->Type()->IsSet() ) { TableVal* tv = v->AsTableVal(); - ListVal* lv = tv->ConvertToPureList(); - return lv; + auto lv = tv->ToPureListVal(); + return lv.release(); } else diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index b7c9b1af3d..acea5cc813 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -96,12 +96,10 @@ void Manager::InitPostScript() reporter->FatalError("Tunnel::vxlan_ports not defined"); auto table_val = id->ID_Val()->AsTableVal(); - auto port_list = table_val->ConvertToPureList(); + auto port_list = table_val->ToPureListVal(); for ( auto i = 0; i < port_list->Length(); ++i ) vxlan_ports.emplace_back(port_list->Idx(i)->AsPortVal()->Port()); - - Unref(port_list); } void Manager::DumpDebug() diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 6e58a8f183..d32c8434e8 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -244,7 +244,7 @@ X509_STORE* file_analysis::X509::GetRootStore(TableVal* root_certs) return x509_stores[root_certs]; X509_STORE* ctx = X509_STORE_new(); - ListVal* idxs = root_certs->ConvertToPureList(); + auto idxs = root_certs->ToPureListVal(); // Build the validation store for ( int i = 0; i < idxs->Length(); ++i ) @@ -264,8 +264,6 @@ X509_STORE* file_analysis::X509::GetRootStore(TableVal* root_certs) X509_free(x); } - delete idxs; - // Save the newly constructed certificate store into the cacheing map. x509_stores[root_certs] = ctx; diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index f68f5be4d9..a09c0fa0d4 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1012,11 +1012,11 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) case TYPE_TABLE: { - ListVal* set = val->AsTableVal()->ConvertToPureList(); + auto set = val->AsTableVal()->ToPureListVal(); if ( ! set ) - // ConvertToPureList has reported an internal warning + // ToPureListVal has reported an internal warning // already. Just keep going by making something up. - set = new ListVal(TYPE_INT); + set = make_intrusive(TYPE_INT); lval->val.set_val.size = set->Length(); lval->val.set_val.vals = new threading::Value* [lval->val.set_val.size]; @@ -1024,7 +1024,6 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) for ( int i = 0; i < lval->val.set_val.size; i++ ) lval->val.set_val.vals[i] = ValToLogVal(set->Idx(i).get()); - Unref(set); break; } diff --git a/src/zeek.bif b/src/zeek.bif index de067d7b40..bea7c94761 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -401,7 +401,7 @@ function terminate%(%): bool // is false). static bool prepare_environment(TableVal* tbl, bool set) { - IntrusivePtr idxs{AdoptRef{}, tbl->ConvertToPureList()}; + auto idxs = tbl->ToPureListVal(); for ( int i = 0; i < idxs->Length(); ++i ) { From 1abed4fd4cb041b7a9c7519aa8728ccb5294738b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 17:10:34 -0700 Subject: [PATCH 007/151] Migrate Tag classes to use IntrusivePtr Deprecates various methods that previously took raw pointers --- NEWS | 3 ++ src/Tag.cc | 45 ++++++++++++++--------------- src/Tag.h | 12 +++++++- src/analyzer/Analyzer.cc | 25 +++++----------- src/analyzer/Manager.cc | 8 ++--- src/analyzer/Tag.cc | 17 +++++++++-- src/analyzer/Tag.h | 8 ++++- src/analyzer/analyzer.bif | 5 ++-- src/analyzer/protocol/pia/PIA.cc | 18 +++++------- src/file_analysis/AnalyzerSet.cc | 4 +-- src/file_analysis/Manager.cc | 8 ++--- src/file_analysis/Tag.cc | 17 +++++++++-- src/file_analysis/Tag.h | 8 ++++- src/file_analysis/file_analysis.bif | 3 +- src/input/Tag.cc | 17 +++++++++-- src/input/Tag.h | 8 ++++- src/logging/Tag.cc | 17 +++++++++-- src/logging/Tag.h | 8 ++++- src/plugin/ComponentManager.h | 24 +++++++++++++-- src/zeekygen/Target.cc | 4 +-- 20 files changed, 174 insertions(+), 85 deletions(-) diff --git a/NEWS b/NEWS index 0a35e5d69d..5b08e81d69 100644 --- a/NEWS +++ b/NEWS @@ -137,6 +137,9 @@ Deprecated Functionality to associated ``Val`` type are now deprecated, the deprecation warning message will advice what new method to use instead. +- Various methods of ``Tag`` classes are deprecated with the warning + message advising what new method to use instead. + Zeek 3.1.0 ========== diff --git a/src/Tag.cc b/src/Tag.cc index e0145afd6d..a964760fcb 100644 --- a/src/Tag.cc +++ b/src/Tag.cc @@ -4,37 +4,40 @@ #include "Val.h" #include "IntrusivePtr.h" -Tag::Tag(EnumType* etype, type_t arg_type, subtype_t arg_subtype) +Tag::Tag(const IntrusivePtr& etype, type_t arg_type, subtype_t arg_subtype) { assert(arg_type > 0); type = arg_type; subtype = arg_subtype; int64_t i = (int64_t)(type) | ((int64_t)subtype << 31); - Ref(etype); - val = etype->GetVal(i).release(); + val = etype->GetVal(i); } -Tag::Tag(EnumVal* arg_val) +Tag::Tag(EnumType* etype, type_t arg_type, subtype_t arg_subtype) + : Tag({NewRef{}, etype}, arg_type, arg_subtype) + { } + +Tag::Tag(IntrusivePtr arg_val) { assert(arg_val); - val = arg_val; - Ref(val); + val = std::move(arg_val); int64_t i = val->InternalInt(); type = i & 0xffffffff; subtype = (i >> 31) & 0xffffffff; } +Tag::Tag(EnumVal* arg_val) + : Tag({NewRef{}, arg_val}) + { } + Tag::Tag(const Tag& other) { type = other.type; subtype = other.subtype; val = other.val; - - if ( val ) - Ref(val); } Tag::Tag() @@ -44,11 +47,7 @@ Tag::Tag() val = nullptr; } -Tag::~Tag() - { - Unref(val); - val = nullptr; - } +Tag::~Tag() = default; Tag& Tag::operator=(const Tag& other) { @@ -56,11 +55,7 @@ Tag& Tag::operator=(const Tag& other) { type = other.type; subtype = other.subtype; - Unref(val); val = other.val; - - if ( val ) - Ref(val); } return *this; @@ -72,26 +67,28 @@ Tag& Tag::operator=(const Tag&& other) noexcept { type = other.type; subtype = other.subtype; - Unref(val); - val = other.val; - other.val = nullptr; + val = std::move(other.val); } return *this; } -EnumVal* Tag::AsEnumVal(EnumType* etype) const +const IntrusivePtr& Tag::AsVal(const IntrusivePtr& etype) const { if ( ! val ) { assert(type == 0 && subtype == 0); - Ref(etype); - val = etype->GetVal(0).release(); + val = etype->GetVal(0); } return val; } +EnumVal* Tag::AsEnumVal(EnumType* etype) const + { + return AsVal({NewRef{}, etype}).get(); + } + std::string Tag::AsString() const { return fmt("%" PRIu32 "/%" PRIu32, type, subtype); diff --git a/src/Tag.h b/src/Tag.h index f10c59cd4b..68e7f34b80 100644 --- a/src/Tag.h +++ b/src/Tag.h @@ -3,6 +3,7 @@ #pragma once #include "zeek-config.h" +#include "IntrusivePtr.h" #include @@ -114,6 +115,9 @@ protected: * * @param etype the script-layer enum type associated with the tag. */ + const IntrusivePtr& AsVal(const IntrusivePtr& etype) const; + + [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal(EnumType* etype) const; /** @@ -127,6 +131,9 @@ protected: * @param subtype The sub type, which is left to an analyzer for * interpretation. By default it's set to zero. */ + Tag(const IntrusivePtr& etype, type_t type, subtype_t subtype = 0); + + [[deprecated("Remove in v4.1. Construct from IntrusivePtr& instead.")]] Tag(EnumType* etype, type_t type, subtype_t subtype = 0); /** @@ -134,10 +141,13 @@ protected: * * @param val An enum value of script type \c Analyzer::Tag. */ + explicit Tag(IntrusivePtr val); + + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit Tag(EnumVal* val); private: type_t type; // Main type. subtype_t subtype; // Subtype. - mutable EnumVal* val; // Script-layer value. + mutable IntrusivePtr val; // Script-layer value. }; diff --git a/src/analyzer/Analyzer.cc b/src/analyzer/Analyzer.cc index 85398f19f1..5b8cf67a08 100644 --- a/src/analyzer/Analyzer.cc +++ b/src/analyzer/Analyzer.cc @@ -687,13 +687,8 @@ void Analyzer::ProtocolConfirmation(Tag arg_tag) if ( ! protocol_confirmation ) return; - EnumVal* tval = arg_tag ? arg_tag.AsEnumVal() : tag.AsEnumVal(); - - mgr.Enqueue(protocol_confirmation, - ConnVal(), - IntrusivePtr{NewRef{}, tval}, - val_mgr->Count(id) - ); + const auto& tval = arg_tag ? arg_tag.AsVal() : tag.AsVal(); + mgr.Enqueue(protocol_confirmation, ConnVal(), tval, val_mgr->Count(id)); } void Analyzer::ProtocolViolation(const char* reason, const char* data, int len) @@ -701,27 +696,21 @@ void Analyzer::ProtocolViolation(const char* reason, const char* data, int len) if ( ! protocol_violation ) return; - StringVal* r; + IntrusivePtr r; if ( data && len ) { const char *tmp = copy_string(reason); - r = new StringVal(fmt("%s [%s%s]", tmp, + r = make_intrusive(fmt("%s [%s%s]", tmp, fmt_bytes(data, min(40, len)), len > 40 ? "..." : "")); delete [] tmp; } else - r = new StringVal(reason); + r = make_intrusive(reason); - EnumVal* tval = tag.AsEnumVal(); - - mgr.Enqueue(protocol_violation, - ConnVal(), - IntrusivePtr{NewRef{}, tval}, - val_mgr->Count(id), - IntrusivePtr{AdoptRef{}, r} - ); + const auto& tval = tag.AsVal(); + mgr.Enqueue(protocol_violation, ConnVal(), tval, val_mgr->Count(id), std::move(r)); } void Analyzer::AddTimer(analyzer_timer_func timer, double t, diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index acea5cc813..45f6b7792e 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -572,8 +572,9 @@ void Manager::ScheduleAnalyzer(const IPAddr& orig, const IPAddr& resp, void Manager::ScheduleAnalyzer(const IPAddr& orig, const IPAddr& resp, PortVal* resp_p, Val* analyzer, double timeout) { - EnumVal* ev = analyzer->AsEnumVal(); - return ScheduleAnalyzer(orig, resp, resp_p->Port(), resp_p->PortType(), Tag(ev), timeout); + IntrusivePtr ev{NewRef{}, analyzer->AsEnumVal()}; + return ScheduleAnalyzer(orig, resp, resp_p->Port(), resp_p->PortType(), + Tag(std::move(ev)), timeout); } Manager::tag_set Manager::GetScheduled(const Connection* conn) @@ -624,8 +625,7 @@ bool Manager::ApplyScheduledAnalyzers(Connection* conn, bool init, TransportLaye if ( scheduled_analyzer_applied ) conn->EnqueueEvent(scheduled_analyzer_applied, nullptr, - conn->ConnVal(), - IntrusivePtr{NewRef{}, it->AsEnumVal()}); + conn->ConnVal(), it->AsVal()); DBG_ANALYZER_ARGS(conn, "activated %s analyzer as scheduled", analyzer_mgr->GetComponentName(*it).c_str()); diff --git a/src/analyzer/Tag.cc b/src/analyzer/Tag.cc index 128449175e..228668e15d 100644 --- a/src/analyzer/Tag.cc +++ b/src/analyzer/Tag.cc @@ -6,7 +6,7 @@ const analyzer::Tag analyzer::Tag::Error; analyzer::Tag::Tag(type_t type, subtype_t subtype) - : ::Tag(analyzer_mgr->GetTagEnumType(), type, subtype) + : ::Tag(analyzer_mgr->GetTagType(), type, subtype) { } @@ -16,7 +16,20 @@ analyzer::Tag& analyzer::Tag::operator=(const analyzer::Tag& other) return *this; } +const IntrusivePtr& analyzer::Tag::AsVal() const + { + return ::Tag::AsVal(analyzer_mgr->GetTagType()); + } + EnumVal* analyzer::Tag::AsEnumVal() const { - return ::Tag::AsEnumVal(analyzer_mgr->GetTagEnumType()); + return AsVal().get(); } + +analyzer::Tag::Tag(IntrusivePtr val) + : ::Tag(std::move(val)) + { } + +analyzer::Tag::Tag(EnumVal* val) + : ::Tag({NewRef{}, val}) + { } diff --git a/src/analyzer/Tag.h b/src/analyzer/Tag.h index 46545e4bd1..39cdc3ed45 100644 --- a/src/analyzer/Tag.h +++ b/src/analyzer/Tag.h @@ -83,6 +83,9 @@ public: * * @param etype the script-layer enum type associated with the tag. */ + const IntrusivePtr& AsVal() const; + + [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal() const; static const Tag Error; @@ -109,7 +112,10 @@ protected: * * @param val An enum value of script type \c Analyzer::Tag. */ - explicit Tag(EnumVal* val) : ::Tag(val) {} + explicit Tag(IntrusivePtr val); + + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead")]] + explicit Tag(EnumVal* val); }; } diff --git a/src/analyzer/analyzer.bif b/src/analyzer/analyzer.bif index efb52e785f..849b75d693 100644 --- a/src/analyzer/analyzer.bif +++ b/src/analyzer/analyzer.bif @@ -41,11 +41,12 @@ function Analyzer::__schedule_analyzer%(orig: addr, resp: addr, resp_p: port, function __name%(atype: Analyzer::Tag%) : string %{ - return make_intrusive(analyzer_mgr->GetComponentName(atype)); + const auto& n = analyzer_mgr->GetComponentName(IntrusivePtr{NewRef{}, atype->AsEnumVal()}); + return make_intrusive(n); %} function __tag%(name: string%) : Analyzer::Tag %{ analyzer::Tag t = analyzer_mgr->GetComponentTag(name->CheckString()); - return IntrusivePtr{NewRef{}, t.AsEnumVal()}; + return t.AsVal(); %} diff --git a/src/analyzer/protocol/pia/PIA.cc b/src/analyzer/protocol/pia/PIA.cc index fe5797d6d1..8e0d7e9295 100644 --- a/src/analyzer/protocol/pia/PIA.cc +++ b/src/analyzer/protocol/pia/PIA.cc @@ -156,12 +156,11 @@ void PIA_UDP::ActivateAnalyzer(analyzer::Tag tag, const Rule* rule) if ( protocol_late_match ) { // Queue late match event - EnumVal *tval = tag ? tag.AsEnumVal() : GetAnalyzerTag().AsEnumVal(); + if ( ! tag ) + tag = GetAnalyzerTag(); - mgr.Enqueue(protocol_late_match, - ConnVal(), - IntrusivePtr{NewRef{}, tval} - ); + const auto& tval = tag.AsVal(); + mgr.Enqueue(protocol_late_match, ConnVal(), tval); } pkt_buffer.state = dpd_late_match_stop ? SKIPPING : MATCHING_ONLY; @@ -304,12 +303,11 @@ void PIA_TCP::ActivateAnalyzer(analyzer::Tag tag, const Rule* rule) if ( protocol_late_match ) { // Queue late match event - EnumVal *tval = tag ? tag.AsEnumVal() : GetAnalyzerTag().AsEnumVal(); + if ( ! tag ) + tag = GetAnalyzerTag(); - mgr.Enqueue(protocol_late_match, - ConnVal(), - IntrusivePtr{NewRef{}, tval} - ); + const auto& tval = tag.AsVal(); + mgr.Enqueue(protocol_late_match, ConnVal(), tval); } stream_buffer.state = dpd_late_match_stop ? SKIPPING : MATCHING_ONLY; diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index 1a7941a026..8c5c5eecc2 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -21,7 +21,7 @@ static void analyzer_del_func(void* v) AnalyzerSet::AnalyzerSet(File* arg_file) : file(arg_file) { auto t = make_intrusive(); - t->Append({NewRef{}, file_mgr->GetTagEnumType()}); + t->Append(file_mgr->GetTagType()); t->Append({NewRef{}, BifType::Record::Files::AnalyzerArgs}); analyzer_hash = new CompositeHash(std::move(t)); analyzer_map.SetDeleteFunc(analyzer_del_func); @@ -164,7 +164,7 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set) HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const { ListVal* lv = new ListVal(TYPE_ANY); - lv->Append({NewRef{}, t.AsEnumVal()}); + lv->Append(t.AsVal()); lv->Append({NewRef{}, args}); HashKey* key = analyzer_hash->ComputeHash(lv, true); Unref(lv); diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index f3face2d79..f9e843ddf3 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -422,13 +422,9 @@ string Manager::GetFileID(const analyzer::Tag& tag, Connection* c, bool is_orig) DBG_LOG(DBG_FILE_ANALYSIS, "Raise get_file_handle() for protocol analyzer %s", analyzer_mgr->GetComponentName(tag).c_str()); - EnumVal* tagval = tag.AsEnumVal(); + const auto& tagval = tag.AsVal(); - mgr.Enqueue(get_file_handle, - IntrusivePtr{NewRef{}, tagval}, - c->ConnVal(), - val_mgr->Bool(is_orig) - ); + mgr.Enqueue(get_file_handle, tagval, c->ConnVal(), val_mgr->Bool(is_orig)); mgr.Drain(); // need file handle immediately so we don't have to buffer data return current_file_id; } diff --git a/src/file_analysis/Tag.cc b/src/file_analysis/Tag.cc index 30958ed605..1789600f26 100644 --- a/src/file_analysis/Tag.cc +++ b/src/file_analysis/Tag.cc @@ -8,7 +8,7 @@ using namespace file_analysis; const file_analysis::Tag file_analysis::Tag::Error; file_analysis::Tag::Tag(type_t type, subtype_t subtype) - : ::Tag(file_mgr->GetTagEnumType(), type, subtype) + : ::Tag(file_mgr->GetTagType(), type, subtype) { } @@ -18,7 +18,20 @@ file_analysis::Tag& file_analysis::Tag::operator=(const file_analysis::Tag& othe return *this; } +const IntrusivePtr& file_analysis::Tag::AsVal() const + { + return ::Tag::AsVal(file_mgr->GetTagType()); + } + EnumVal* file_analysis::Tag::AsEnumVal() const { - return ::Tag::AsEnumVal(file_mgr->GetTagEnumType()); + return AsVal().get(); } + +file_analysis::Tag::Tag(IntrusivePtr val) + : ::Tag(std::move(val)) + { } + +file_analysis::Tag::Tag(EnumVal* val) + : ::Tag({NewRef{}, val}) + { } diff --git a/src/file_analysis/Tag.h b/src/file_analysis/Tag.h index 6f5dae6b03..8c434e20e6 100644 --- a/src/file_analysis/Tag.h +++ b/src/file_analysis/Tag.h @@ -82,6 +82,9 @@ public: * * @param etype the script-layer enum type associated with the tag. */ + const IntrusivePtr& AsVal() const; + + [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal() const; static const Tag Error; @@ -107,7 +110,10 @@ protected: * * @param val An enum value of script type \c Files::Tag. */ - explicit Tag(EnumVal* val) : ::Tag(val) {} + explicit Tag(IntrusivePtr val); + + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] + explicit Tag(EnumVal* val); }; } diff --git a/src/file_analysis/file_analysis.bif b/src/file_analysis/file_analysis.bif index 24222a7a45..91bc6929aa 100644 --- a/src/file_analysis/file_analysis.bif +++ b/src/file_analysis/file_analysis.bif @@ -68,7 +68,8 @@ function Files::__stop%(file_id: string%): bool ## :zeek:see:`Files::analyzer_name`. function Files::__analyzer_name%(tag: Files::Tag%) : string %{ - return make_intrusive(file_mgr->GetComponentName(tag)); + const auto& n = file_mgr->GetComponentName(IntrusivePtr{NewRef{}, tag->AsEnumVal()}); + return make_intrusive(n); %} ## :zeek:see:`Files::file_exists`. diff --git a/src/input/Tag.cc b/src/input/Tag.cc index a2c0708583..cbdcd59aae 100644 --- a/src/input/Tag.cc +++ b/src/input/Tag.cc @@ -6,7 +6,7 @@ const input::Tag input::Tag::Error; input::Tag::Tag(type_t type, subtype_t subtype) - : ::Tag(input_mgr->GetTagEnumType(), type, subtype) + : ::Tag(input_mgr->GetTagType(), type, subtype) { } @@ -16,7 +16,20 @@ input::Tag& input::Tag::operator=(const input::Tag& other) return *this; } +const IntrusivePtr& input::Tag::AsVal() const + { + return ::Tag::AsVal(input_mgr->GetTagType()); + } + EnumVal* input::Tag::AsEnumVal() const { - return ::Tag::AsEnumVal(input_mgr->GetTagEnumType()); + return AsVal().get(); } + +input::Tag::Tag(IntrusivePtr val) + : ::Tag(std::move(val)) + { } + +input::Tag::Tag(EnumVal* val) + : ::Tag({NewRef{}, val}) + { } diff --git a/src/input/Tag.h b/src/input/Tag.h index 86f85ac36b..20a163da23 100644 --- a/src/input/Tag.h +++ b/src/input/Tag.h @@ -83,6 +83,9 @@ public: * * @param etype the script-layer enum type associated with the tag. */ + const IntrusivePtr& AsVal() const; + + [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal() const; static const Tag Error; @@ -108,7 +111,10 @@ protected: * * @param val An enum value of script type \c Input::Reader. */ - explicit Tag(EnumVal* val) : ::Tag(val) {} + explicit Tag(IntrusivePtr val); + + [[deprecated("Remove in v4.1. Construct from IntrusivePtr isntead.")]] + explicit Tag(EnumVal* val); }; } diff --git a/src/logging/Tag.cc b/src/logging/Tag.cc index 2ab2844e25..69d9e0ad67 100644 --- a/src/logging/Tag.cc +++ b/src/logging/Tag.cc @@ -6,7 +6,7 @@ const logging::Tag logging::Tag::Error; logging::Tag::Tag(type_t type, subtype_t subtype) - : ::Tag(log_mgr->GetTagEnumType(), type, subtype) + : ::Tag(log_mgr->GetTagType(), type, subtype) { } @@ -22,7 +22,20 @@ logging::Tag& logging::Tag::operator=(const logging::Tag&& other) noexcept return *this; } +const IntrusivePtr& logging::Tag::AsVal() const + { + return ::Tag::AsVal(log_mgr->GetTagType()); + } + EnumVal* logging::Tag::AsEnumVal() const { - return ::Tag::AsEnumVal(log_mgr->GetTagEnumType()); + return AsVal().get(); } + +logging::Tag::Tag(IntrusivePtr val) + : ::Tag(std::move(val)) + { } + +logging::Tag::Tag(EnumVal* val) + : ::Tag({NewRef{}, val}) + { } diff --git a/src/logging/Tag.h b/src/logging/Tag.h index 29c7fd6cd4..78aee1a3d0 100644 --- a/src/logging/Tag.h +++ b/src/logging/Tag.h @@ -88,6 +88,9 @@ public: * * @param etype the script-layer enum type associated with the tag. */ + const IntrusivePtr& AsVal() const; + + [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal() const; static const Tag Error; @@ -113,7 +116,10 @@ protected: * * @param val An enum value of script type \c Log::Writer. */ - explicit Tag(EnumVal* val) : ::Tag(val) {} + explicit Tag(IntrusivePtr val); + + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] + explicit Tag(EnumVal* val); }; } diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index 2448597004..3c66fe9dd7 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -52,6 +52,9 @@ public: /** * @return The enum type associated with the script-layer "Tag". */ + const IntrusivePtr& GetTagType() const; + + [[deprecated("Remove in v4.1. Use GetTagType() instead.")]] EnumType* GetTagEnumType() const; /** @@ -68,6 +71,9 @@ public: * @param val A component's enum value. * @return The canonical component name. */ + const std::string& GetComponentName(IntrusivePtr val) const; + + [[deprecated("Remove in v4.1. Use IntrusivePtr argument instead.")]] const std::string& GetComponentName(Val* val) const; /** @@ -156,6 +162,12 @@ std::list ComponentManager::GetComponents() const return rval; } +template +const IntrusivePtr& ComponentManager::GetTagType() const + { + return tag_enum_type; + } + template EnumType* ComponentManager::GetTagEnumType() const { @@ -180,10 +192,16 @@ const std::string& ComponentManager::GetComponentName(T tag) const return error; } +template +const std::string& ComponentManager::GetComponentName(IntrusivePtr val) const + { + return GetComponentName(T(std::move(val))); + } + template const std::string& ComponentManager::GetComponentName(Val* val) const { - return GetComponentName(T(val->AsEnumVal())); + return GetComponentName(T({NewRef{}, val->AsEnumVal()})); } template @@ -239,12 +257,12 @@ void ComponentManager::RegisterComponent(C* component, components_by_name.insert(std::make_pair(cname, component)); components_by_tag.insert(std::make_pair(component->Tag(), component)); components_by_val.insert(std::make_pair( - component->Tag().AsEnumVal()->InternalInt(), component)); + component->Tag().AsVal()->InternalInt(), component)); // Install an identfier for enum value std::string id = fmt("%s%s", prefix.c_str(), cname.c_str()); tag_enum_type->AddName(module, id.c_str(), - component->Tag().AsEnumVal()->InternalInt(), true, + component->Tag().AsVal()->InternalInt(), true, nullptr); } diff --git a/src/zeekygen/Target.cc b/src/zeekygen/Target.cc index 9aae9b82fe..34e6f3519a 100644 --- a/src/zeekygen/Target.cc +++ b/src/zeekygen/Target.cc @@ -35,7 +35,7 @@ static void write_plugin_section_heading(FILE* f, const plugin::Plugin* p) static void write_analyzer_component(FILE* f, const analyzer::Component* c) { - EnumType* atag = analyzer_mgr->GetTagEnumType(); + const auto& atag = analyzer_mgr->GetTagType(); string tag = fmt("ANALYZER_%s", c->CanonicalName().c_str()); if ( atag->Lookup("Analyzer", tag.c_str()) < 0 ) @@ -46,7 +46,7 @@ static void write_analyzer_component(FILE* f, const analyzer::Component* c) static void write_analyzer_component(FILE* f, const file_analysis::Component* c) { - EnumType* atag = file_mgr->GetTagEnumType(); + const auto& atag = file_mgr->GetTagType(); string tag = fmt("ANALYZER_%s", c->CanonicalName().c_str()); if ( atag->Lookup("Files", tag.c_str()) < 0 ) From 0f2b176f754cebb0f6a8473e229f472f25e2b226 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 17:39:24 -0700 Subject: [PATCH 008/151] Migrate DNS analyzer to use IntrusivePtr --- src/analyzer/protocol/dns/DNS.cc | 154 ++++++++++++++----------------- src/analyzer/protocol/dns/DNS.h | 21 ++--- 2 files changed, 79 insertions(+), 96 deletions(-) diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 19f40757c1..849b611525 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -51,7 +51,7 @@ void DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) analyzer->EnqueueConnEvent(dns_message, analyzer->ConnVal(), val_mgr->Bool(is_query), - IntrusivePtr{AdoptRef{}, msg.BuildHdrVal()}, + msg.BuildHdrVal(), val_mgr->Count(len) ); @@ -135,7 +135,7 @@ void DNS_Interpreter::EndMessage(DNS_MsgInfo* msg) if ( dns_end ) analyzer->EnqueueConnEvent(dns_end, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()} + msg->BuildHdrVal() ); } @@ -229,8 +229,7 @@ bool DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg, // Note that the exact meaning of some of these fields will be // re-interpreted by other, more adventurous RR types. - Unref(msg->query_name); - msg->query_name = new StringVal(new BroString(name, name_end - name, true)); + msg->query_name = make_intrusive(new BroString(name, name_end - name, true)); msg->atype = RR_Type(ExtractShort(data, len)); msg->aclass = ExtractShort(data, len); msg->ttl = ExtractLong(data, len); @@ -338,8 +337,8 @@ bool DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg, if ( dns_unknown_reply && ! msg->skip_event ) analyzer->EnqueueConnEvent(dns_unknown_reply, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()} + msg->BuildHdrVal(), + msg->BuildAnswerVal() ); analyzer->Weird("DNS_RR_unknown_type", fmt("%d", msg->atype)); @@ -551,8 +550,8 @@ bool DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg, if ( reply_event && ! msg->skip_event ) analyzer->EnqueueConnEvent(reply_event, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), make_intrusive(new BroString(name, name_end - name, true)) ); @@ -604,8 +603,8 @@ bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, analyzer->EnqueueConnEvent(dns_SOA_reply, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), std::move(r) ); } @@ -634,8 +633,8 @@ bool DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg, if ( dns_MX_reply && ! msg->skip_event ) analyzer->EnqueueConnEvent(dns_MX_reply, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), make_intrusive(new BroString(name, name_end - name, true)), val_mgr->Count(preference) ); @@ -675,8 +674,8 @@ bool DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg, if ( dns_SRV_reply && ! msg->skip_event ) analyzer->EnqueueConnEvent(dns_SRV_reply, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), make_intrusive(new BroString(name, name_end - name, true)), val_mgr->Count(priority), val_mgr->Count(weight), @@ -696,8 +695,8 @@ bool DNS_Interpreter::ParseRR_EDNS(DNS_MsgInfo* msg, if ( dns_EDNS_addl && ! msg->skip_event ) analyzer->EnqueueConnEvent(dns_EDNS_addl, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildEDNS_Val()} + msg->BuildHdrVal(), + msg->BuildEDNS_Val() ); // Currently EDNS supports the movement of type:data pairs @@ -773,8 +772,8 @@ bool DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg, analyzer->EnqueueConnEvent(dns_TSIG_addl, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildTSIG_Val(&tsig)} + msg->BuildHdrVal(), + msg->BuildTSIG_Val(&tsig) ); } @@ -874,9 +873,9 @@ bool DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg, analyzer->EnqueueConnEvent(dns_RRSIG, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildRRSIG_Val(&rrsig)} + msg->BuildHdrVal(), + msg->BuildAnswerVal(), + msg->BuildRRSIG_Val(&rrsig) ); } @@ -969,9 +968,9 @@ bool DNS_Interpreter::ParseRR_DNSKEY(DNS_MsgInfo* msg, analyzer->EnqueueConnEvent(dns_DNSKEY, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildDNSKEY_Val(&dnskey)} + msg->BuildHdrVal(), + msg->BuildAnswerVal(), + msg->BuildDNSKEY_Val(&dnskey) ); } @@ -1021,8 +1020,8 @@ bool DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, if ( dns_NSEC ) analyzer->EnqueueConnEvent(dns_NSEC, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), make_intrusive(new BroString(name, name_end - name, true)), std::move(char_strings) ); @@ -1074,7 +1073,7 @@ bool DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, int typebitmaps_len = rdlength - (data - data_start); - VectorVal* char_strings = new VectorVal(string_vec); + auto char_strings = make_intrusive(string_vec); while ( typebitmaps_len > 0 && len > 0 ) { @@ -1103,17 +1102,15 @@ bool DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, nsec3.nsec_salt = salt_val; nsec3.nsec_hlen = hash_len; nsec3.nsec_hash = hash_val; - nsec3.bitmaps = char_strings; + nsec3.bitmaps = std::move(char_strings); analyzer->EnqueueConnEvent(dns_NSEC3, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildNSEC3_Val(&nsec3)} + msg->BuildHdrVal(), + msg->BuildAnswerVal(), + msg->BuildNSEC3_Val(&nsec3) ); } - else - Unref(char_strings); return true; } @@ -1167,9 +1164,9 @@ bool DNS_Interpreter::ParseRR_DS(DNS_MsgInfo* msg, analyzer->EnqueueConnEvent(dns_DS, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildDS_Val(&ds)} + msg->BuildHdrVal(), + msg->BuildAnswerVal(), + msg->BuildDS_Val(&ds) ); } @@ -1190,8 +1187,8 @@ bool DNS_Interpreter::ParseRR_A(DNS_MsgInfo* msg, if ( dns_A_reply && ! msg->skip_event ) analyzer->EnqueueConnEvent(dns_A_reply, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), make_intrusive(htonl(addr)) ); @@ -1226,8 +1223,8 @@ bool DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg, if ( event && ! msg->skip_event ) analyzer->EnqueueConnEvent(event, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), make_intrusive(addr) ); @@ -1252,8 +1249,9 @@ bool DNS_Interpreter::ParseRR_HINFO(DNS_MsgInfo* msg, return true; } -static StringVal* extract_char_string(analyzer::Analyzer* analyzer, - const u_char*& data, int& len, int& rdlen) +static IntrusivePtr +extract_char_string(analyzer::Analyzer* analyzer, + const u_char*& data, int& len, int& rdlen) { if ( rdlen <= 0 ) return nullptr; @@ -1270,8 +1268,7 @@ static StringVal* extract_char_string(analyzer::Analyzer* analyzer, return nullptr; } - StringVal* rval = new StringVal(str_size, - reinterpret_cast(data)); + auto rval = make_intrusive(str_size, reinterpret_cast(data)); rdlen -= str_size; len -= str_size; @@ -1292,16 +1289,16 @@ bool DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, } auto char_strings = make_intrusive(string_vec); - StringVal* char_string; + IntrusivePtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) - char_strings->Assign(char_strings->Size(), char_string); + char_strings->Assign(char_strings->Size(), std::move(char_string)); if ( dns_TXT_reply ) analyzer->EnqueueConnEvent(dns_TXT_reply, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), std::move(char_strings) ); @@ -1320,16 +1317,16 @@ bool DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, } auto char_strings = make_intrusive(string_vec); - StringVal* char_string; + IntrusivePtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) - char_strings->Assign(char_strings->Size(), char_string); + char_strings->Assign(char_strings->Size(), std::move(char_string)); if ( dns_SPF_reply ) analyzer->EnqueueConnEvent(dns_SPF_reply, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), std::move(char_strings) ); @@ -1369,8 +1366,8 @@ bool DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg, if ( dns_CAA_reply ) analyzer->EnqueueConnEvent(dns_CAA_reply, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, - IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, + msg->BuildHdrVal(), + msg->BuildAnswerVal(), val_mgr->Count(flags), make_intrusive(tag), make_intrusive(value) @@ -1397,7 +1394,7 @@ void DNS_Interpreter::SendReplyOrRejectEvent(DNS_MsgInfo* msg, analyzer->EnqueueConnEvent(event, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, + msg->BuildHdrVal(), make_intrusive(question_name), val_mgr->Count(qtype), val_mgr->Count(qclass) @@ -1428,7 +1425,6 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query) id = ntohs(hdr->id); is_query = arg_is_query; - query_name = nullptr; atype = TYPE_ALL; aclass = 0; ttl = 0; @@ -1437,14 +1433,9 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query) skip_event = 0; } -DNS_MsgInfo::~DNS_MsgInfo() +IntrusivePtr DNS_MsgInfo::BuildHdrVal() { - Unref(query_name); - } - -Val* DNS_MsgInfo::BuildHdrVal() - { - RecordVal* r = new RecordVal(dns_msg); + auto r = make_intrusive(dns_msg); r->Assign(0, val_mgr->Count(id)); r->Assign(1, val_mgr->Count(opcode)); @@ -1463,11 +1454,10 @@ Val* DNS_MsgInfo::BuildHdrVal() return r; } -Val* DNS_MsgInfo::BuildAnswerVal() +IntrusivePtr DNS_MsgInfo::BuildAnswerVal() { - RecordVal* r = new RecordVal(dns_answer); + auto r = make_intrusive(dns_answer); - Ref(query_name); r->Assign(0, val_mgr->Count(int(answer_type))); r->Assign(1, query_name); r->Assign(2, val_mgr->Count(atype)); @@ -1477,13 +1467,12 @@ Val* DNS_MsgInfo::BuildAnswerVal() return r; } -Val* DNS_MsgInfo::BuildEDNS_Val() +IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() { // We have to treat the additional record type in EDNS differently // than a regular resource record. - RecordVal* r = new RecordVal(dns_edns_additional); + auto r = make_intrusive(dns_edns_additional); - Ref(query_name); r->Assign(0, val_mgr->Count(int(answer_type))); r->Assign(1, query_name); @@ -1513,12 +1502,11 @@ Val* DNS_MsgInfo::BuildEDNS_Val() return r; } -Val* DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) +IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) { - RecordVal* r = new RecordVal(dns_tsig_additional); + auto r = make_intrusive(dns_tsig_additional); double rtime = tsig->time_s + tsig->time_ms / 1000.0; - Ref(query_name); // r->Assign(0, val_mgr->Count(int(answer_type))); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); @@ -1533,11 +1521,10 @@ Val* DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) return r; } -Val* DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) +IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) { - RecordVal* r = new RecordVal(dns_rrsig_rr); + auto r = make_intrusive(dns_rrsig_rr); - Ref(query_name); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); r->Assign(2, val_mgr->Count(rrsig->type_covered)); @@ -1554,11 +1541,10 @@ Val* DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) return r; } -Val* DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) +IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) { - RecordVal* r = new RecordVal(dns_dnskey_rr); + auto r = make_intrusive(dns_dnskey_rr); - Ref(query_name); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); r->Assign(2, val_mgr->Count(dnskey->dflags)); @@ -1570,11 +1556,10 @@ Val* DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) return r; } -Val* DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) +IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) { - RecordVal* r = new RecordVal(dns_nsec3_rr); + auto r = make_intrusive(dns_nsec3_rr); - Ref(query_name); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); r->Assign(2, val_mgr->Count(nsec3->nsec_flags)); @@ -1584,17 +1569,16 @@ Val* DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) r->Assign(6, make_intrusive(nsec3->nsec_salt)); r->Assign(7, val_mgr->Count(nsec3->nsec_hlen)); r->Assign(8, make_intrusive(nsec3->nsec_hash)); - r->Assign(9, nsec3->bitmaps); + r->Assign(9, std::move(nsec3->bitmaps)); r->Assign(10, val_mgr->Count(is_query)); return r; } -Val* DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) +IntrusivePtr DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) { - RecordVal* r = new RecordVal(dns_ds_rr); + auto r = make_intrusive(dns_ds_rr); - Ref(query_name); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); r->Assign(2, val_mgr->Count(ds->key_tag)); diff --git a/src/analyzer/protocol/dns/DNS.h b/src/analyzer/protocol/dns/DNS.h index 5b7666ac5a..ff6ae42de8 100644 --- a/src/analyzer/protocol/dns/DNS.h +++ b/src/analyzer/protocol/dns/DNS.h @@ -165,7 +165,7 @@ struct NSEC3_DATA { BroString* nsec_salt; unsigned short nsec_hlen; BroString* nsec_hash; - VectorVal* bitmaps; + IntrusivePtr bitmaps; }; struct DS_DATA { @@ -178,16 +178,15 @@ struct DS_DATA { class DNS_MsgInfo { public: DNS_MsgInfo(DNS_RawMsgHdr* hdr, int is_query); - ~DNS_MsgInfo(); - Val* BuildHdrVal(); - Val* BuildAnswerVal(); - Val* BuildEDNS_Val(); - Val* BuildTSIG_Val(struct TSIG_DATA*); - Val* BuildRRSIG_Val(struct RRSIG_DATA*); - Val* BuildDNSKEY_Val(struct DNSKEY_DATA*); - Val* BuildNSEC3_Val(struct NSEC3_DATA*); - Val* BuildDS_Val(struct DS_DATA*); + IntrusivePtr BuildHdrVal(); + IntrusivePtr BuildAnswerVal(); + IntrusivePtr BuildEDNS_Val(); + IntrusivePtr BuildTSIG_Val(struct TSIG_DATA*); + IntrusivePtr BuildRRSIG_Val(struct RRSIG_DATA*); + IntrusivePtr BuildDNSKEY_Val(struct DNSKEY_DATA*); + IntrusivePtr BuildNSEC3_Val(struct NSEC3_DATA*); + IntrusivePtr BuildDS_Val(struct DS_DATA*); int id; int opcode; ///< query type, see DNS_Opcode @@ -204,7 +203,7 @@ public: int arcount; ///< number of additional RRs int is_query; ///< whether it came from the session initiator - StringVal* query_name; + IntrusivePtr query_name; RR_Type atype; int aclass; ///< normally = 1, inet uint32_t ttl; From 46e27bbf7d7cfa3420900e839da873aa9238274b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 18:29:38 -0700 Subject: [PATCH 009/151] Migrate ICMP analyzer to use IntrusivePtr --- src/analyzer/protocol/icmp/ICMP.cc | 85 +++++++++++++++--------------- src/analyzer/protocol/icmp/ICMP.h | 14 ++--- 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 7363c3c429..8575e5e59c 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -30,7 +30,7 @@ ICMP_Analyzer::ICMP_Analyzer(Connection* c) void ICMP_Analyzer::Done() { TransportLayerAnalyzer::Done(); - Unref(icmp_conn_val); + icmp_conn_val = nullptr; matcher_state.FinishEndpointMatcher(); } @@ -204,7 +204,7 @@ void ICMP_Analyzer::ICMP_Sent(const struct icmp* icmpp, int len, int caplen, if ( icmp_sent ) EnqueueConnEvent(icmp_sent, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, icmpv6, ip_hdr)} + BuildICMPVal(icmpp, len, icmpv6, ip_hdr) ); if ( icmp_sent_payload ) @@ -213,18 +213,19 @@ void ICMP_Analyzer::ICMP_Sent(const struct icmp* icmpp, int len, int caplen, EnqueueConnEvent(icmp_sent_payload, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, icmpv6, ip_hdr)}, + BuildICMPVal(icmpp, len, icmpv6, ip_hdr), make_intrusive(payload) ); } } -RecordVal* ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, - int icmpv6, const IP_Hdr* ip_hdr) +IntrusivePtr +ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, + int icmpv6, const IP_Hdr* ip_hdr) { if ( ! icmp_conn_val ) { - icmp_conn_val = new RecordVal(icmp_conn); + icmp_conn_val = make_intrusive(icmp_conn); icmp_conn_val->Assign(0, make_intrusive(Conn()->OrigAddr())); icmp_conn_val->Assign(1, make_intrusive(Conn()->RespAddr())); @@ -235,8 +236,6 @@ RecordVal* ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, icmp_conn_val->Assign(6, val_mgr->Bool(icmpv6)); } - Ref(icmp_conn_val); - return icmp_conn_val; } @@ -305,7 +304,7 @@ TransportProto ICMP_Analyzer::GetContextProtocol(const IP_Hdr* ip_hdr, uint32_t* return proto; } -RecordVal* ICMP_Analyzer::ExtractICMP4Context(int len, const u_char*& data) +IntrusivePtr ICMP_Analyzer::ExtractICMP4Context(int len, const u_char*& data) { const IP_Hdr ip_hdr_data((const struct ip*) data, false); const IP_Hdr* ip_hdr = &ip_hdr_data; @@ -351,15 +350,15 @@ RecordVal* ICMP_Analyzer::ExtractICMP4Context(int len, const u_char*& data) } } - RecordVal* iprec = new RecordVal(icmp_context); - RecordVal* id_val = new RecordVal(conn_id); + auto iprec = make_intrusive(icmp_context); + auto id_val = make_intrusive(conn_id); id_val->Assign(0, make_intrusive(src_addr)); id_val->Assign(1, val_mgr->Port(src_port, proto)); id_val->Assign(2, make_intrusive(dst_addr)); id_val->Assign(3, val_mgr->Port(dst_port, proto)); - iprec->Assign(0, id_val); + iprec->Assign(0, std::move(id_val)); iprec->Assign(1, val_mgr->Count(ip_len)); iprec->Assign(2, val_mgr->Count(proto)); iprec->Assign(3, val_mgr->Count(frag_offset)); @@ -371,7 +370,7 @@ RecordVal* ICMP_Analyzer::ExtractICMP4Context(int len, const u_char*& data) return iprec; } -RecordVal* ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data) +IntrusivePtr ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data) { int DF = 0, MF = 0, bad_hdr_len = 0; TransportProto proto = TRANSPORT_UNKNOWN; @@ -410,15 +409,15 @@ RecordVal* ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data) } } - RecordVal* iprec = new RecordVal(icmp_context); - RecordVal* id_val = new RecordVal(conn_id); + auto iprec = make_intrusive(icmp_context); + auto id_val = make_intrusive(conn_id); id_val->Assign(0, make_intrusive(src_addr)); id_val->Assign(1, val_mgr->Port(src_port, proto)); id_val->Assign(2, make_intrusive(dst_addr)); id_val->Assign(3, val_mgr->Port(dst_port, proto)); - iprec->Assign(0, id_val); + iprec->Assign(0, std::move(id_val)); iprec->Assign(1, val_mgr->Count(ip_len)); iprec->Assign(2, val_mgr->Count(proto)); iprec->Assign(3, val_mgr->Count(frag_offset)); @@ -457,21 +456,23 @@ void ICMP_Analyzer::Describe(ODesc* d) const void ICMP_Analyzer::UpdateConnVal(RecordVal *conn_val) { - RecordVal *orig_endp = conn_val->Lookup("orig")->AsRecordVal(); - RecordVal *resp_endp = conn_val->Lookup("resp")->AsRecordVal(); + auto orig_endp = conn_val->Lookup("orig"); + auto resp_endp = conn_val->Lookup("resp"); - UpdateEndpointVal(orig_endp, true); - UpdateEndpointVal(resp_endp, false); + UpdateEndpointVal(&orig_endp, true); + UpdateEndpointVal(&resp_endp, false); // Call children's UpdateConnVal Analyzer::UpdateConnVal(conn_val); } -void ICMP_Analyzer::UpdateEndpointVal(RecordVal* endp, bool is_orig) +void ICMP_Analyzer::UpdateEndpointVal(IntrusivePtr* endp_arg, bool is_orig) { Conn()->EnableStatusUpdateTimer(); int size = is_orig ? request_len : reply_len; + auto endp = (*endp_arg)->AsRecordVal(); + if ( size < 0 ) { endp->Assign(0, val_mgr->Count(0)); @@ -516,7 +517,7 @@ void ICMP_Analyzer::Echo(double t, const struct icmp* icmpp, int len, EnqueueConnEvent(f, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, ip_hdr->NextProto() != IPPROTO_ICMP, ip_hdr)}, + BuildICMPVal(icmpp, len, ip_hdr->NextProto() != IPPROTO_ICMP, ip_hdr), val_mgr->Count(iid), val_mgr->Count(iseq), make_intrusive(payload) @@ -544,7 +545,7 @@ void ICMP_Analyzer::RouterAdvert(double t, const struct icmp* icmpp, int len, EnqueueConnEvent(f, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, 1, ip_hdr)}, + BuildICMPVal(icmpp, len, 1, ip_hdr), val_mgr->Count(icmpp->icmp_num_addrs), // Cur Hop Limit val_mgr->Bool(icmpp->icmp_wpa & 0x80), // Managed val_mgr->Bool(icmpp->icmp_wpa & 0x40), // Other @@ -555,7 +556,7 @@ void ICMP_Analyzer::RouterAdvert(double t, const struct icmp* icmpp, int len, make_intrusive((double)ntohs(icmpp->icmp_lifetime), Seconds), make_intrusive((double)ntohl(reachable), Milliseconds), make_intrusive((double)ntohl(retrans), Milliseconds), - IntrusivePtr{AdoptRef{}, BuildNDOptionsVal(caplen - opt_offset, data + opt_offset)} + BuildNDOptionsVal(caplen - opt_offset, data + opt_offset) ); } @@ -577,12 +578,12 @@ void ICMP_Analyzer::NeighborAdvert(double t, const struct icmp* icmpp, int len, EnqueueConnEvent(f, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, 1, ip_hdr)}, + BuildICMPVal(icmpp, len, 1, ip_hdr), val_mgr->Bool(icmpp->icmp_num_addrs & 0x80), // Router val_mgr->Bool(icmpp->icmp_num_addrs & 0x40), // Solicited val_mgr->Bool(icmpp->icmp_num_addrs & 0x20), // Override make_intrusive(tgtaddr), - IntrusivePtr{AdoptRef{}, BuildNDOptionsVal(caplen - opt_offset, data + opt_offset)} + BuildNDOptionsVal(caplen - opt_offset, data + opt_offset) ); } @@ -604,9 +605,9 @@ void ICMP_Analyzer::NeighborSolicit(double t, const struct icmp* icmpp, int len, EnqueueConnEvent(f, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, 1, ip_hdr)}, + BuildICMPVal(icmpp, len, 1, ip_hdr), make_intrusive(tgtaddr), - IntrusivePtr{AdoptRef{}, BuildNDOptionsVal(caplen - opt_offset, data + opt_offset)} + BuildNDOptionsVal(caplen - opt_offset, data + opt_offset) ); } @@ -631,10 +632,10 @@ void ICMP_Analyzer::Redirect(double t, const struct icmp* icmpp, int len, EnqueueConnEvent(f, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, 1, ip_hdr)}, + BuildICMPVal(icmpp, len, 1, ip_hdr), make_intrusive(tgtaddr), make_intrusive(dstaddr), - IntrusivePtr{AdoptRef{}, BuildNDOptionsVal(caplen - opt_offset, data + opt_offset)} + BuildNDOptionsVal(caplen - opt_offset, data + opt_offset) ); } @@ -649,8 +650,8 @@ void ICMP_Analyzer::RouterSolicit(double t, const struct icmp* icmpp, int len, EnqueueConnEvent(f, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, 1, ip_hdr)}, - IntrusivePtr{AdoptRef{}, BuildNDOptionsVal(caplen, data)} + BuildICMPVal(icmpp, len, 1, ip_hdr), + BuildNDOptionsVal(caplen, data) ); } @@ -674,9 +675,9 @@ void ICMP_Analyzer::Context4(double t, const struct icmp* icmpp, if ( f ) EnqueueConnEvent(f, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, 0, ip_hdr)}, + BuildICMPVal(icmpp, len, 0, ip_hdr), val_mgr->Count(icmpp->icmp_code), - IntrusivePtr{AdoptRef{}, ExtractICMP4Context(caplen, data)} + ExtractICMP4Context(caplen, data) ); } @@ -712,13 +713,13 @@ void ICMP_Analyzer::Context6(double t, const struct icmp* icmpp, if ( f ) EnqueueConnEvent(f, ConnVal(), - IntrusivePtr{AdoptRef{}, BuildICMPVal(icmpp, len, 1, ip_hdr)}, + BuildICMPVal(icmpp, len, 1, ip_hdr), val_mgr->Count(icmpp->icmp_code), - IntrusivePtr{AdoptRef{}, ExtractICMP6Context(caplen, data)} + ExtractICMP6Context(caplen, data) ); } -VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) +IntrusivePtr ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) { static RecordType* icmp6_nd_option_type = nullptr; static RecordType* icmp6_nd_prefix_info_type = nullptr; @@ -730,7 +731,7 @@ VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) internal_type("icmp6_nd_prefix_info")->AsRecordType(); } - VectorVal* vv = new VectorVal( + auto vv = make_intrusive( internal_type("icmp6_nd_options")->AsVectorType()); while ( caplen > 0 ) @@ -751,7 +752,7 @@ VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) break; } - RecordVal* rv = new RecordVal(icmp6_nd_option_type); + auto rv = make_intrusive(icmp6_nd_option_type); rv->Assign(0, val_mgr->Count(type)); rv->Assign(1, val_mgr->Count(length)); @@ -785,7 +786,7 @@ VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) { if ( caplen >= 30 ) { - RecordVal* info = new RecordVal(icmp6_nd_prefix_info_type); + auto info = make_intrusive(icmp6_nd_prefix_info_type); uint8_t prefix_len = *((const uint8_t*)(data)); bool L_flag = (*((const uint8_t*)(data + 1)) & 0x80) != 0; bool A_flag = (*((const uint8_t*)(data + 1)) & 0x40) != 0; @@ -798,7 +799,7 @@ VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) info->Assign(3, make_intrusive((double)ntohl(valid_life), Seconds)); info->Assign(4, make_intrusive((double)ntohl(prefer_life), Seconds)); info->Assign(5, make_intrusive(IPAddr(prefix))); - rv->Assign(3, info); + rv->Assign(3, std::move(info)); } else @@ -848,7 +849,7 @@ VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) data += length; caplen -= length; - vv->Assign(vv->Size(), rv); + vv->Assign(vv->Size(), std::move(rv)); } return vv; diff --git a/src/analyzer/protocol/icmp/ICMP.h b/src/analyzer/protocol/icmp/ICMP.h index 93626e0f63..3a91b26a5f 100644 --- a/src/analyzer/protocol/icmp/ICMP.h +++ b/src/analyzer/protocol/icmp/ICMP.h @@ -51,13 +51,13 @@ protected: void Describe(ODesc* d) const; - RecordVal* BuildICMPVal(const struct icmp* icmpp, int len, int icmpv6, - const IP_Hdr* ip_hdr); + IntrusivePtr BuildICMPVal(const struct icmp* icmpp, int len, + int icmpv6, const IP_Hdr* ip_hdr); void NextICMP4(double t, const struct icmp* icmpp, int len, int caplen, const u_char*& data, const IP_Hdr* ip_hdr ); - RecordVal* ExtractICMP4Context(int len, const u_char*& data); + IntrusivePtr ExtractICMP4Context(int len, const u_char*& data); void Context4(double t, const struct icmp* icmpp, int len, int caplen, const u_char*& data, const IP_Hdr* ip_hdr); @@ -68,15 +68,15 @@ protected: void NextICMP6(double t, const struct icmp* icmpp, int len, int caplen, const u_char*& data, const IP_Hdr* ip_hdr ); - RecordVal* ExtractICMP6Context(int len, const u_char*& data); + IntrusivePtr ExtractICMP6Context(int len, const u_char*& data); void Context6(double t, const struct icmp* icmpp, int len, int caplen, const u_char*& data, const IP_Hdr* ip_hdr); // RFC 4861 Neighbor Discover message options - VectorVal* BuildNDOptionsVal(int caplen, const u_char* data); + IntrusivePtr BuildNDOptionsVal(int caplen, const u_char* data); - RecordVal* icmp_conn_val; + IntrusivePtr icmp_conn_val; int type; int code; int request_len, reply_len; @@ -84,7 +84,7 @@ protected: RuleMatcherState matcher_state; private: - void UpdateEndpointVal(RecordVal* endp, bool is_orig); + void UpdateEndpointVal(IntrusivePtr* endp, bool is_orig); }; // Returns the counterpart type to the given type (e.g., the counterpart From 61b75ddd0265765035226cf50566387aa4a9e309 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 19:19:36 -0700 Subject: [PATCH 010/151] Migrate HTTP/MIME analyzers to use IntrusivePtr --- src/analyzer/protocol/http/HTTP.cc | 99 ++++++++++-------------------- src/analyzer/protocol/http/HTTP.h | 17 +++-- src/analyzer/protocol/mime/MIME.cc | 45 +++++++------- src/analyzer/protocol/mime/MIME.h | 18 +++--- 4 files changed, 71 insertions(+), 108 deletions(-) diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index 94412b110f..77c9071ed2 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -613,9 +613,9 @@ HTTP_Message::~HTTP_Message() delete [] entity_data_buffer; } -Val* HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) +IntrusivePtr HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) { - RecordVal* stat = new RecordVal(http_message_stat); + auto stat = make_intrusive(http_message_stat); int field = 0; stat->Assign(field++, make_intrusive(start_time, TYPE_TIME)); stat->Assign(field++, val_mgr->Bool(interrupted)); @@ -652,7 +652,7 @@ void HTTP_Message::Done(bool interrupted, const char* detail) GetAnalyzer()->EnqueueConnEvent(http_message_done, analyzer->ConnVal(), val_mgr->Bool(is_orig), - IntrusivePtr{AdoptRef{}, BuildMessageStat(interrupted, detail)} + BuildMessageStat(interrupted, detail) ); MyHTTP_Analyzer()->HTTP_MessageDone(is_orig, this); @@ -737,21 +737,16 @@ void HTTP_Message::SubmitAllHeaders(mime::MIME_HeaderList& hlist) analyzer->EnqueueConnEvent(http_all_headers, analyzer->ConnVal(), val_mgr->Bool(is_orig), - IntrusivePtr{AdoptRef{}, BuildHeaderTable(hlist)} + BuildHeaderTable(hlist) ); if ( http_content_type ) - { - StringVal* ty = current_entity->ContentType(); - StringVal* subty = current_entity->ContentSubType(); - analyzer->EnqueueConnEvent(http_content_type, analyzer->ConnVal(), val_mgr->Bool(is_orig), - IntrusivePtr{NewRef{}, ty}, - IntrusivePtr{NewRef{}, subty} + current_entity->ContentType(), + current_entity->ContentSubType() ); - } } void HTTP_Message::SubmitTrailingHeaders(mime::MIME_HeaderList& /* hlist */) @@ -842,12 +837,9 @@ HTTP_Analyzer::HTTP_Analyzer(Connection* conn) reply_state = EXPECT_REPLY_LINE; request_ongoing = 0; - request_method = request_URI = nullptr; - unescaped_URI = nullptr; reply_ongoing = 0; reply_code = 0; - reply_reason_phrase = nullptr; connect_request = false; pia = nullptr; @@ -863,14 +855,6 @@ HTTP_Analyzer::HTTP_Analyzer(Connection* conn) AddSupportAnalyzer(content_line_resp); } -HTTP_Analyzer::~HTTP_Analyzer() - { - Unref(request_method); - Unref(request_URI); - Unref(unescaped_URI); - Unref(reply_reason_phrase); - } - void HTTP_Analyzer::Done() { if ( IsFinished() ) @@ -889,11 +873,7 @@ void HTTP_Analyzer::Done() GenStats(); - while ( ! unanswered_requests.empty() ) - { - Unref(unanswered_requests.front()); - unanswered_requests.pop(); - } + unanswered_requests = {}; file_mgr->EndOfFile(GetAnalyzerTag(), Conn(), true); @@ -970,7 +950,7 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig) request_state = EXPECT_REQUEST_MESSAGE; request_ongoing = 1; - unanswered_requests.push(request_method->Ref()); + unanswered_requests.push(request_method); HTTP_Request(); InitHTTPMessage(content_line, request_message, is_orig, HTTP_BODY_MAYBE, len); @@ -1260,7 +1240,7 @@ int HTTP_Analyzer::HTTP_RequestLine(const char* line, const char* end_of_line) return -1; } - request_method = new StringVal(end_of_method - line, line); + request_method = make_intrusive(end_of_method - line, line); Conn()->Match(Rule::HTTP_REQUEST, (const u_char*) unescaped_URI->AsString()->Bytes(), @@ -1330,9 +1310,9 @@ bool HTTP_Analyzer::ParseRequest(const char* line, const char* end_of_line) // NormalizeURI(line, end_of_uri); - request_URI = new StringVal(end_of_uri - line, line); - unescaped_URI = new StringVal(unescape_URI((const u_char*) line, - (const u_char*) end_of_uri, this)); + request_URI = make_intrusive(end_of_uri - line, line); + unescaped_URI = make_intrusive( + unescape_URI((const u_char*) line, (const u_char*) end_of_uri, this)); return true; } @@ -1351,7 +1331,7 @@ HTTP_Analyzer::HTTP_VersionNumber HTTP_Analyzer::HTTP_Version(int len, const cha } else { - HTTP_Event("bad_HTTP_version", mime::new_string_val(len, data)); + HTTP_Event("bad_HTTP_version", mime::new_string_val(len, data)); return {}; } } @@ -1370,23 +1350,21 @@ void HTTP_Analyzer::SetVersion(HTTP_VersionNumber* version, HTTP_VersionNumber n void HTTP_Analyzer::HTTP_Event(const char* category, const char* detail) { - HTTP_Event(category, new StringVal(detail)); + HTTP_Event(category, make_intrusive(detail)); } -void HTTP_Analyzer::HTTP_Event(const char* category, StringVal* detail) +void HTTP_Analyzer::HTTP_Event(const char* category, IntrusivePtr detail) { if ( http_event ) // DEBUG_MSG("%.6f http_event\n", network_time); EnqueueConnEvent(http_event, ConnVal(), make_intrusive(category), - IntrusivePtr{AdoptRef{}, detail} - ); - else - Unref(detail); + std::move(detail)); } -StringVal* HTTP_Analyzer::TruncateURI(StringVal* uri) +IntrusivePtr +HTTP_Analyzer::TruncateURI(const IntrusivePtr& uri) { const BroString* str = uri->AsString(); @@ -1395,13 +1373,10 @@ StringVal* HTTP_Analyzer::TruncateURI(StringVal* uri) u_char* s = new u_char[truncate_http_URI + 4]; memcpy(s, str->Bytes(), truncate_http_URI); memcpy(s + truncate_http_URI, "...", 4); - return new StringVal(new BroString(true, s, truncate_http_URI+3)); + return make_intrusive(new BroString(true, s, truncate_http_URI+3)); } else - { - Ref(uri); return uri; - } } void HTTP_Analyzer::HTTP_Request() @@ -1418,9 +1393,9 @@ void HTTP_Analyzer::HTTP_Request() // DEBUG_MSG("%.6f http_request\n", network_time); EnqueueConnEvent(http_request, ConnVal(), - IntrusivePtr{NewRef{}, request_method}, - IntrusivePtr{AdoptRef{}, TruncateURI(request_URI->AsStringVal())}, - IntrusivePtr{AdoptRef{}, TruncateURI(unescaped_URI->AsStringVal())}, + request_method, + TruncateURI(request_URI), + TruncateURI(unescaped_URI), make_intrusive(fmt("%.1f", request_version.ToDouble())) ); } @@ -1433,14 +1408,11 @@ void HTTP_Analyzer::HTTP_Reply() make_intrusive(fmt("%.1f", reply_version.ToDouble())), val_mgr->Count(reply_code), reply_reason_phrase ? - IntrusivePtr{NewRef{}, reply_reason_phrase} : + reply_reason_phrase : make_intrusive("") ); else - { - Unref(reply_reason_phrase); reply_reason_phrase = nullptr; - } } void HTTP_Analyzer::RequestMade(bool interrupted, const char* msg) @@ -1455,11 +1427,9 @@ void HTTP_Analyzer::RequestMade(bool interrupted, const char* msg) // DEBUG_MSG("%.6f request made\n", network_time); - Unref(request_method); - Unref(unescaped_URI); - Unref(request_URI); - - request_method = request_URI = unescaped_URI = nullptr; + request_method = nullptr; + unescaped_URI = nullptr; + request_URI = nullptr; num_request_lines = 0; @@ -1484,16 +1454,10 @@ void HTTP_Analyzer::ReplyMade(bool interrupted, const char* msg) // 1xx replies do not indicate the final response to a request, // so don't pop an unanswered request in that case. if ( (reply_code < 100 || reply_code >= 200) && ! unanswered_requests.empty() ) - { - Unref(unanswered_requests.front()); unanswered_requests.pop(); - } if ( reply_reason_phrase ) - { - Unref(reply_reason_phrase); reply_reason_phrase = nullptr; - } // unanswered requests = 1 because there is no pop after 101. if ( reply_code == 101 && unanswered_requests.size() == 1 && upgrade_connection && @@ -1585,7 +1549,7 @@ int HTTP_Analyzer::HTTP_ReplyLine(const char* line, const char* end_of_line) rest = skip_whitespace(rest, end_of_line); reply_reason_phrase = - new StringVal(end_of_line - rest, (const char *) rest); + make_intrusive(end_of_line - rest, (const char *) rest); return 1; } @@ -1669,12 +1633,15 @@ void HTTP_Analyzer::HTTP_Header(bool is_orig, mime::MIME_Header* h) if ( DEBUG_http ) DEBUG_MSG("%.6f http_header\n", network_time); + auto upper_hn = mime::new_string_val(h->get_name()); + upper_hn->ToUpper(); + EnqueueConnEvent(http_header, ConnVal(), val_mgr->Bool(is_orig), - IntrusivePtr{AdoptRef{}, mime::new_string_val(h->get_name())}, - IntrusivePtr{AdoptRef{}, mime::new_string_val(h->get_name())->ToUpper()}, - IntrusivePtr{AdoptRef{}, mime::new_string_val(h->get_value())} + mime::new_string_val(h->get_name()), + std::move(upper_hn), + mime::new_string_val(h->get_value()) ); } } diff --git a/src/analyzer/protocol/http/HTTP.h b/src/analyzer/protocol/http/HTTP.h index 20a1e1f239..63ddfbbb7c 100644 --- a/src/analyzer/protocol/http/HTTP.h +++ b/src/analyzer/protocol/http/HTTP.h @@ -145,19 +145,18 @@ protected: HTTP_Entity* current_entity; - Val* BuildMessageStat(bool interrupted, const char* msg); + IntrusivePtr BuildMessageStat(bool interrupted, const char* msg); }; class HTTP_Analyzer final : public tcp::TCP_ApplicationAnalyzer { public: HTTP_Analyzer(Connection* conn); - ~HTTP_Analyzer() override; void HTTP_Header(bool is_orig, mime::MIME_Header* h); void HTTP_EntityData(bool is_orig, BroString* entity_data); void HTTP_MessageDone(bool is_orig, HTTP_Message* message); void HTTP_Event(const char* category, const char* detail); - void HTTP_Event(const char* category, StringVal *detail); + void HTTP_Event(const char* category, IntrusivePtr detail); void SkipEntityData(bool is_orig); @@ -238,7 +237,7 @@ protected: int HTTP_ReplyCode(const char* code_str); int ExpectReplyMessageBody(); - StringVal* TruncateURI(StringVal* uri); + IntrusivePtr TruncateURI(const IntrusivePtr& uri); int request_state, reply_state; int num_requests, num_replies; @@ -258,19 +257,19 @@ protected: // in a reply. std::string upgrade_protocol; - Val* request_method; + IntrusivePtr request_method; // request_URI is in the original form (may contain '%' // sequences). - Val* request_URI; + IntrusivePtr request_URI; // unescaped_URI does not contain escaped sequences. - Val* unescaped_URI; + IntrusivePtr unescaped_URI; - std::queue unanswered_requests; + std::queue> unanswered_requests; int reply_code; - Val* reply_reason_phrase; + IntrusivePtr reply_reason_phrase; tcp::ContentLine_Analyzer* content_line_orig; tcp::ContentLine_Analyzer* content_line_resp; diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index 8f5c00f811..dab28cc608 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -108,17 +108,17 @@ bool is_lws(char ch) return ch == 9 || ch == 32; } -StringVal* new_string_val(int length, const char* data) +IntrusivePtr new_string_val(int length, const char* data) { - return new StringVal(length, data); + return make_intrusive(length, data); } -StringVal* new_string_val(const char* data, const char* end_of_data) +IntrusivePtr new_string_val(const char* data, const char* end_of_data) { - return new StringVal(end_of_data - data, data); + return make_intrusive(end_of_data - data, data); } -StringVal* new_string_val(const data_chunk_t buf) +IntrusivePtr new_string_val(const data_chunk_t buf) { return new_string_val(buf.length, buf.data); } @@ -551,8 +551,8 @@ void MIME_Entity::init() need_to_parse_parameters = 0; - content_type_str = new StringVal("TEXT"); - content_subtype_str = new StringVal("PLAIN"); + content_type_str = make_intrusive("TEXT"); + content_subtype_str = make_intrusive("PLAIN"); content_encoding_str = nullptr; multipart_boundary = nullptr; @@ -581,8 +581,6 @@ MIME_Entity::~MIME_Entity() "missing MIME_Entity::EndOfData() before ~MIME_Entity"); delete current_header_line; - Unref(content_type_str); - Unref(content_subtype_str); delete content_encoding_str; delete multipart_boundary; @@ -804,10 +802,10 @@ bool MIME_Entity::ParseContentTypeField(MIME_Header* h) data += offset; len -= offset; - Unref(content_type_str); - content_type_str = (new StringVal(ty.length, ty.data))->ToUpper(); - Unref(content_subtype_str); - content_subtype_str = (new StringVal(subty.length, subty.data))->ToUpper(); + content_type_str = make_intrusive(ty.length, ty.data); + content_type_str->ToUpper(); + content_subtype_str = make_intrusive(subty.length, subty.data); + content_subtype_str->ToUpper(); ParseContentType(ty, subty); @@ -1289,27 +1287,26 @@ void MIME_Entity::DebugPrintHeaders() #endif } -RecordVal* MIME_Message::BuildHeaderVal(MIME_Header* h) +IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) { - RecordVal* header_record = new RecordVal(mime_header_rec); + auto header_record = make_intrusive(mime_header_rec); header_record->Assign(0, new_string_val(h->get_name())); - header_record->Assign(1, new_string_val(h->get_name())->ToUpper()); + auto upper_hn = new_string_val(h->get_name()); + upper_hn->ToUpper(); + header_record->Assign(1, std::move(upper_hn)); header_record->Assign(2, new_string_val(h->get_value())); return header_record; } -TableVal* MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) +IntrusivePtr MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) { - TableVal* t = new TableVal({NewRef{}, mime_header_list}); + auto t = make_intrusive(IntrusivePtr{NewRef{}, mime_header_list}); for ( unsigned int i = 0; i < hlist.size(); ++i ) { auto index = val_mgr->Count(i + 1); // index starting from 1 - MIME_Header* h = hlist[i]; - RecordVal* header_record = BuildHeaderVal(h); - - t->Assign(index.get(), header_record); + t->Assign(index.get(), BuildHeaderVal(h)); } return t; @@ -1428,7 +1425,7 @@ void MIME_Mail::SubmitHeader(MIME_Header* h) if ( mime_one_header ) analyzer->EnqueueConnEvent(mime_one_header, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, BuildHeaderVal(h)} + BuildHeaderVal(h) ); } @@ -1437,7 +1434,7 @@ void MIME_Mail::SubmitAllHeaders(MIME_HeaderList& hlist) if ( mime_all_headers ) analyzer->EnqueueConnEvent(mime_all_headers, analyzer->ConnVal(), - IntrusivePtr{AdoptRef{}, BuildHeaderTable(hlist)} + BuildHeaderTable(hlist) ); } diff --git a/src/analyzer/protocol/mime/MIME.h b/src/analyzer/protocol/mime/MIME.h index 000ad77d15..f897b094a7 100644 --- a/src/analyzer/protocol/mime/MIME.h +++ b/src/analyzer/protocol/mime/MIME.h @@ -97,8 +97,8 @@ public: MIME_Entity* Parent() const { return parent; } int MIMEContentType() const { return content_type; } - StringVal* ContentType() const { return content_type_str; } - StringVal* ContentSubType() const { return content_subtype_str; } + const IntrusivePtr& ContentType() const { return content_type_str; } + const IntrusivePtr& ContentSubType() const { return content_subtype_str; } int ContentTransferEncoding() const { return content_encoding; } protected: @@ -154,8 +154,8 @@ protected: int current_field_type; int need_to_parse_parameters; - StringVal* content_type_str; - StringVal* content_subtype_str; + IntrusivePtr content_type_str; + IntrusivePtr content_subtype_str; BroString* content_encoding_str; BroString* multipart_boundary; @@ -225,8 +225,8 @@ protected: MIME_Entity* top_level; bool finished; - RecordVal* BuildHeaderVal(MIME_Header* h); - TableVal* BuildHeaderTable(MIME_HeaderList& hlist); + IntrusivePtr BuildHeaderVal(MIME_Header* h); + IntrusivePtr BuildHeaderTable(MIME_HeaderList& hlist); }; class MIME_Mail final : public MIME_Message { @@ -265,9 +265,9 @@ protected: extern bool is_null_data_chunk(data_chunk_t b); -extern StringVal* new_string_val(int length, const char* data); -extern StringVal* new_string_val(const char* data, const char* end_of_data); -extern StringVal* new_string_val(const data_chunk_t buf); +extern IntrusivePtr new_string_val(int length, const char* data); +extern IntrusivePtr new_string_val(const char* data, const char* end_of_data); +extern IntrusivePtr new_string_val(const data_chunk_t buf); extern int fputs(data_chunk_t b, FILE* fp); extern bool istrequal(data_chunk_t s, const char* t); extern bool is_lws(char ch); From ad6dbada716952c15623fbd4f823ddfcafe21158 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 19:23:54 -0700 Subject: [PATCH 011/151] Migrate ARP analyzer to use IntrusivePtr --- src/analyzer/protocol/arp/ARP.cc | 28 ++++++++++++++-------------- src/analyzer/protocol/arp/ARP.h | 6 +++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/analyzer/protocol/arp/ARP.cc b/src/analyzer/protocol/arp/ARP.cc index 25a48e45a8..ec5906bdde 100644 --- a/src/analyzer/protocol/arp/ARP.cc +++ b/src/analyzer/protocol/arp/ARP.cc @@ -192,10 +192,10 @@ void ARP_Analyzer::BadARP(const struct arp_pkthdr* hdr, const char* msg) return; mgr.Enqueue(bad_arp, - IntrusivePtr{AdoptRef{}, ConstructAddrVal(ar_spa(hdr))}, - IntrusivePtr{AdoptRef{}, EthAddrToStr((const u_char*) ar_sha(hdr))}, - IntrusivePtr{AdoptRef{}, ConstructAddrVal(ar_tpa(hdr))}, - IntrusivePtr{AdoptRef{}, EthAddrToStr((const u_char*) ar_tha(hdr))}, + ConstructAddrVal(ar_spa(hdr)), + EthAddrToStr((const u_char*) ar_sha(hdr)), + ConstructAddrVal(ar_tpa(hdr)), + EthAddrToStr((const u_char*) ar_tha(hdr)), make_intrusive(msg) ); } @@ -214,25 +214,25 @@ void ARP_Analyzer::RREvent(EventHandlerPtr e, return; mgr.Enqueue(e, - IntrusivePtr{AdoptRef{}, EthAddrToStr(src)}, - IntrusivePtr{AdoptRef{}, EthAddrToStr(dst)}, - IntrusivePtr{AdoptRef{}, ConstructAddrVal(spa)}, - IntrusivePtr{AdoptRef{}, EthAddrToStr((const u_char*) sha)}, - IntrusivePtr{AdoptRef{}, ConstructAddrVal(tpa)}, - IntrusivePtr{AdoptRef{}, EthAddrToStr((const u_char*) tha)} + EthAddrToStr(src), + EthAddrToStr(dst), + ConstructAddrVal(spa), + EthAddrToStr((const u_char*) sha), + ConstructAddrVal(tpa), + EthAddrToStr((const u_char*) tha) ); } -AddrVal* ARP_Analyzer::ConstructAddrVal(const void* addr) +IntrusivePtr ARP_Analyzer::ConstructAddrVal(const void* addr) { // ### For now, we only handle IPv4 addresses. - return new AddrVal(*(const uint32_t*) addr); + return make_intrusive(*(const uint32_t*) addr); } -StringVal* ARP_Analyzer::EthAddrToStr(const u_char* addr) +IntrusivePtr ARP_Analyzer::EthAddrToStr(const u_char* addr) { char buf[1024]; snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); - return new StringVal(buf); + return make_intrusive(buf); } diff --git a/src/analyzer/protocol/arp/ARP.h b/src/analyzer/protocol/arp/ARP.h index 9037a42b27..62e1fbd8bb 100644 --- a/src/analyzer/protocol/arp/ARP.h +++ b/src/analyzer/protocol/arp/ARP.h @@ -45,10 +45,10 @@ public: const char* tpa, const char* tha); protected: - AddrVal* ConstructAddrVal(const void* addr); - StringVal* EthAddrToStr(const u_char* addr); + IntrusivePtr ConstructAddrVal(const void* addr); + IntrusivePtr EthAddrToStr(const u_char* addr); void BadARP(const struct arp_pkthdr* hdr, const char* string); void Corrupted(const char* string); }; -} } // namespace analyzer::* +} } // namespace analyzer::* From a60e5e95825995f9a23b157af7692b226fc82ccb Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 5 May 2020 22:56:38 -0700 Subject: [PATCH 012/151] Migrate SMB analyzer to use IntrusivePtr Deprecates the utf16_bytestring_to_utf8_val() function with replacement being utf16_to_utf8_val(). --- NEWS | 3 + src/analyzer/protocol/ntlm/ntlm-analyzer.pac | 24 +- src/analyzer/protocol/rdp/rdp-analyzer.pac | 6 +- src/analyzer/protocol/smb/smb-strings.pac | 102 +++---- src/analyzer/protocol/smb/smb-time.pac | 49 ++-- .../protocol/smb/smb1-com-check-directory.pac | 2 +- .../smb/smb1-com-create-directory.pac | 2 +- .../protocol/smb/smb1-com-negotiate.pac | 45 ++-- .../protocol/smb/smb1-com-nt-create-andx.pac | 6 +- .../smb/smb1-com-query-information.pac | 2 +- .../smb/smb1-com-session-setup-andx.pac | 19 +- .../protocol/smb/smb1-com-transaction.pac | 2 +- .../protocol/smb/smb1-com-transaction2.pac | 4 +- .../smb/smb1-com-tree-connect-andx.pac | 8 +- src/analyzer/protocol/smb/smb2-com-close.pac | 6 +- src/analyzer/protocol/smb/smb2-com-create.pac | 13 +- .../protocol/smb/smb2-com-negotiate.pac | 8 +- src/analyzer/protocol/smb/smb2-com-read.pac | 4 +- .../protocol/smb/smb2-com-session-setup.pac | 4 +- .../protocol/smb/smb2-com-set-info.pac | 82 +++--- .../smb/smb2-com-transform-header.pac | 24 +- .../protocol/smb/smb2-com-tree-connect.pac | 6 +- .../protocol/smb/smb2-com-tree-disconnect.pac | 4 +- src/analyzer/protocol/smb/smb2-com-write.pac | 6 +- src/analyzer/protocol/smb/smb2-protocol.pac | 253 +++++++++--------- src/binpac_bro-lib.pac | 31 ++- src/binpac_bro.h | 5 + src/bro.pac | 1 - 28 files changed, 377 insertions(+), 344 deletions(-) diff --git a/NEWS b/NEWS index 5b08e81d69..ee26a55cba 100644 --- a/NEWS +++ b/NEWS @@ -140,6 +140,9 @@ Deprecated Functionality - Various methods of ``Tag`` classes are deprecated with the warning message advising what new method to use instead. +- The ``utf16_bytestring_to_utf8_val()`` function is deprecated, use + ``utf16_to_utf8_val()`` instead. + Zeek 3.1.0 ========== diff --git a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac index a8cc0f8f02..97c012814c 100644 --- a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac +++ b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac @@ -45,19 +45,19 @@ refine connection NTLM_Conn += { case 0: return result; case 1: - result->Assign(0, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].nb_computer_name.data})); + result->Assign(0, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].nb_computer_name.data})); break; case 2: - result->Assign(1, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].nb_domain_name.data})); + result->Assign(1, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].nb_domain_name.data})); break; case 3: - result->Assign(2, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].dns_computer_name.data})); + result->Assign(2, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].dns_computer_name.data})); break; case 4: - result->Assign(3, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].dns_domain_name.data})); + result->Assign(3, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].dns_domain_name.data})); break; case 5: - result->Assign(4, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].dns_tree_name.data})); + result->Assign(4, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].dns_tree_name.data})); break; case 6: result->Assign(5, val_mgr->Bool(${val.pairs[i].constrained_auth})); @@ -69,7 +69,7 @@ refine connection NTLM_Conn += { result->Assign(7, val_mgr->Count(${val.pairs[i].single_host.machine_id})); break; case 9: - result->Assign(8, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].target_name.data})); + result->Assign(8, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.pairs[i].target_name.data})); break; } } @@ -114,10 +114,10 @@ refine connection NTLM_Conn += { result->Assign(0, build_negotiate_flag_record(${val.flags})); if ( ${val}->has_domain_name() ) - result->Assign(1, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.domain_name.string.data})); + result->Assign(1, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.domain_name.string.data})); if ( ${val}->has_workstation() ) - result->Assign(2, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.workstation.string.data})); + result->Assign(2, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.workstation.string.data})); if ( ${val}->has_version() ) result->Assign(3, build_version_record(${val.version})); @@ -138,7 +138,7 @@ refine connection NTLM_Conn += { result->Assign(0, build_negotiate_flag_record(${val.flags})); if ( ${val}->has_target_name() ) - result->Assign(1, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.target_name.string.data})); + result->Assign(1, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.target_name.string.data})); if ( ${val}->has_version() ) result->Assign(2, build_version_record(${val.version})); @@ -162,13 +162,13 @@ refine connection NTLM_Conn += { result->Assign(0, build_negotiate_flag_record(${val.flags})); if ( ${val}->has_domain_name() > 0 ) - result->Assign(1, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.domain_name.string.data})); + result->Assign(1, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.domain_name.string.data})); if ( ${val}->has_user_name() > 0 ) - result->Assign(2, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.user_name.string.data})); + result->Assign(2, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.user_name.string.data})); if ( ${val}->has_workstation() > 0 ) - result->Assign(3, utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), ${val.workstation.string.data})); + result->Assign(3, utf16_to_utf8_val(bro_analyzer()->Conn(), ${val.workstation.string.data})); if ( ${val}->has_encrypted_session_key() > 0 ) result->Assign(4, to_stringval(${val.encrypted_session_key.string.data})); diff --git a/src/analyzer/protocol/rdp/rdp-analyzer.pac b/src/analyzer/protocol/rdp/rdp-analyzer.pac index a66de5d8ef..b80129bfc2 100644 --- a/src/analyzer/protocol/rdp/rdp-analyzer.pac +++ b/src/analyzer/protocol/rdp/rdp-analyzer.pac @@ -81,18 +81,18 @@ refine flow RDP_Flow += { ccd->Assign(5, val_mgr->Count(${ccore.sas_sequence})); ccd->Assign(6, val_mgr->Count(${ccore.keyboard_layout})); ccd->Assign(7, val_mgr->Count(${ccore.client_build})); - ccd->Assign(8, utf16_bytestring_to_utf8_val(connection()->bro_analyzer()->Conn(), ${ccore.client_name})); + ccd->Assign(8, utf16_to_utf8_val(connection()->bro_analyzer()->Conn(), ${ccore.client_name})); ccd->Assign(9, val_mgr->Count(${ccore.keyboard_type})); ccd->Assign(10, val_mgr->Count(${ccore.keyboard_sub})); ccd->Assign(11, val_mgr->Count(${ccore.keyboard_function_key})); - ccd->Assign(12, utf16_bytestring_to_utf8_val(connection()->bro_analyzer()->Conn(), ${ccore.ime_file_name})); + ccd->Assign(12, utf16_to_utf8_val(connection()->bro_analyzer()->Conn(), ${ccore.ime_file_name})); ccd->Assign(13, val_mgr->Count(${ccore.post_beta2_color_depth})); ccd->Assign(14, val_mgr->Count(${ccore.client_product_id})); ccd->Assign(15, val_mgr->Count(${ccore.serial_number})); ccd->Assign(16, val_mgr->Count(${ccore.high_color_depth})); ccd->Assign(17, val_mgr->Count(${ccore.supported_color_depths})); ccd->Assign(18, std::move(ec_flags)); - ccd->Assign(19, utf16_bytestring_to_utf8_val(connection()->bro_analyzer()->Conn(), ${ccore.dig_product_id})); + ccd->Assign(19, utf16_to_utf8_val(connection()->bro_analyzer()->Conn(), ${ccore.dig_product_id})); BifEvent::enqueue_rdp_client_core_data(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), diff --git a/src/analyzer/protocol/smb/smb-strings.pac b/src/analyzer/protocol/smb/smb-strings.pac index 5d025f162a..2c7988b37c 100644 --- a/src/analyzer/protocol/smb/smb-strings.pac +++ b/src/analyzer/protocol/smb/smb-strings.pac @@ -1,7 +1,61 @@ +%extern{ +#include "binpac_bro.h" +%} + +%code{ +IntrusivePtr binpac::SMB::SMB_Conn::uint8s_to_stringval(std::vector* data) + { + int length = data->size(); + auto buf = std::make_unique(length); + + for ( int i = 0; i < length; ++i) + buf[i] = (*data)[i]; + + const bytestring bs = bytestring(buf.get(), length); + return utf16_to_utf8_val(bro_analyzer()->Conn(), bs); + } + +IntrusivePtr binpac::SMB::SMB_Conn::extract_string(SMB_string* s) + { + if ( s->unicode() == false ) + { + int length = s->a()->size(); + auto buf = std::make_unique(length); + + for ( int i = 0; i < length; i++) + { + unsigned char t = (*(s->a()))[i]; + buf[i] = t; + } + + if ( length > 0 && buf[length-1] == 0x00 ) + length--; + + return make_intrusive(length, buf.get()); + } + else + return uint8s_to_stringval(s->u()->s()); + } + +IntrusivePtr binpac::SMB::SMB_Conn::smb_string2stringval(SMB_string* s) + { + return extract_string(s); + } + +IntrusivePtr binpac::SMB::SMB_Conn::smb2_string2stringval(SMB2_string* s) + { + return uint8s_to_stringval(s->s()); + } +%} refine connection SMB_Conn += { %member{ - SMB_unicode_string *me; + IntrusivePtr uint8s_to_stringval(std::vector* data); + IntrusivePtr extract_string(SMB_string* s); + IntrusivePtr smb_string2stringval(SMB_string* s); + IntrusivePtr smb2_string2stringval(SMB2_string* s); + + SMB_unicode_string* me; %} %init{ @@ -23,52 +77,6 @@ refine connection SMB_Conn += { else return 0xFF; %} - - function uint8s_to_stringval(data: uint8[]): StringVal - %{ - int length = data->size(); - auto buf = std::make_unique(length); - - for ( int i = 0; i < length; ++i) - buf[i] = (*data)[i]; - - const bytestring bs = bytestring(buf.get(), length); - return utf16_bytestring_to_utf8_val(bro_analyzer()->Conn(), bs); - %} - - function extract_string(s: SMB_string) : StringVal - %{ - if ( s->unicode() == false ) - { - int length = s->a()->size(); - auto buf = std::make_unique(length); - - for ( int i = 0; i < length; i++) - { - unsigned char t = (*(s->a()))[i]; - buf[i] = t; - } - - if ( length > 0 && buf[length-1] == 0x00 ) - length--; - - return new StringVal(length, buf.get()); - } - else - { - return uint8s_to_stringval(s->u()->s()); - } - %} - - function smb_string2stringval(s: SMB_string) : StringVal - %{ - return extract_string(s); - %} - - function smb2_string2stringval(s: SMB2_string) : StringVal - %{ - return uint8s_to_stringval(s->s()); - %} }; type SMB_ascii_string = uint8[] &until($element == 0x00); diff --git a/src/analyzer/protocol/smb/smb-time.pac b/src/analyzer/protocol/smb/smb-time.pac index 52654c7a2b..a7ec9508eb 100644 --- a/src/analyzer/protocol/smb/smb-time.pac +++ b/src/analyzer/protocol/smb/smb-time.pac @@ -1,28 +1,22 @@ -function SMB_BuildMACTimes(modify: uint64, access: uint64, create: uint64, change: uint64): BroVal - %{ - RecordVal* r = new RecordVal(BifType::Record::SMB::MACTimes); +%header{ +IntrusivePtr filetime2brotime(uint64_t ts); +IntrusivePtr time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz); - r->Assign(0, filetime2brotime(modify)); - r->Assign(1, filetime2brotime(access)); - r->Assign(2, filetime2brotime(create)); - r->Assign(3, filetime2brotime(change)); +IntrusivePtr SMB_BuildMACTimes(uint64_t modify, uint64_t access, + uint64_t create, uint64_t change); +%} - return r; - %} - -function filetime2brotime(ts: uint64): Val - %{ +%code{ +IntrusivePtr filetime2brotime(uint64_t ts) + { // Bro can't support times back to the 1600's // so we subtract a lot of seconds. double secs = (ts / 10000000.0L) - 11644473600.0L; + return make_intrusive(secs, TYPE_TIME); + } - Val* bro_ts = new Val(secs, TYPE_TIME); - - return bro_ts; - %} - -function time_from_lanman(t: SMB_time, d: SMB_date, tz: uint16): Val - %{ +IntrusivePtr time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz) + { tm lTime; lTime.tm_sec = ${t.two_seconds} * 2; lTime.tm_min = ${t.minutes}; @@ -30,11 +24,22 @@ function time_from_lanman(t: SMB_time, d: SMB_date, tz: uint16): Val lTime.tm_mday = ${d.day}; lTime.tm_mon = ${d.month}; lTime.tm_year = 1980 + ${d.year}; - lTime.tm_isdst = -1; + lTime.tm_isdst = -1; double lResult = mktime(&lTime); - return new Val(lResult + tz, TYPE_TIME); - %} + return make_intrusive(lResult + tz, TYPE_TIME); + } +IntrusivePtr SMB_BuildMACTimes(uint64_t modify, uint64_t access, + uint64_t create, uint64_t change) + { + auto r = make_intrusive(BifType::Record::SMB::MACTimes); + r->Assign(0, filetime2brotime(modify)); + r->Assign(1, filetime2brotime(access)); + r->Assign(2, filetime2brotime(create)); + r->Assign(3, filetime2brotime(change)); + return r; + } +%} type SMB_timestamp32 = uint32; type SMB_timestamp = uint64; diff --git a/src/analyzer/protocol/smb/smb1-com-check-directory.pac b/src/analyzer/protocol/smb/smb1-com-check-directory.pac index 53b5ff9f0d..8643192a59 100644 --- a/src/analyzer/protocol/smb/smb1-com-check-directory.pac +++ b/src/analyzer/protocol/smb/smb1-com-check-directory.pac @@ -6,7 +6,7 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb1_check_directory_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), - {AdoptRef{}, smb_string2stringval(${val.directory_name})}); + smb_string2stringval(${val.directory_name})); return true; %} diff --git a/src/analyzer/protocol/smb/smb1-com-create-directory.pac b/src/analyzer/protocol/smb/smb1-com-create-directory.pac index e1dd85f55a..adc84619a8 100644 --- a/src/analyzer/protocol/smb/smb1-com-create-directory.pac +++ b/src/analyzer/protocol/smb/smb1-com-create-directory.pac @@ -5,7 +5,7 @@ refine connection SMB_Conn += { if ( smb1_create_directory_request ) BifEvent::enqueue_smb1_create_directory_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), - {AdoptRef{}, smb_string2stringval(${val.directory_name})}); + smb_string2stringval(${val.directory_name})); return true; %} function proc_smb1_create_directory_response(header: SMB_Header, val: SMB1_create_directory_response): bool diff --git a/src/analyzer/protocol/smb/smb1-com-negotiate.pac b/src/analyzer/protocol/smb/smb1-com-negotiate.pac index 62842b33c3..73ee56693f 100644 --- a/src/analyzer/protocol/smb/smb1-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb1-com-negotiate.pac @@ -19,8 +19,8 @@ refine connection SMB_Conn += { for ( unsigned int i = 0; i < ${val.dialects}->size(); ++i ) { - StringVal* dia = smb_string2stringval((*${val.dialects})[i]->name()); - dialects->Assign(i, dia); + auto dia = smb_string2stringval((*${val.dialects})[i]->name()); + dialects->Assign(i, std::move(dia)); } BifEvent::enqueue_smb1_negotiate_request(bro_analyzer(), bro_analyzer()->Conn(), @@ -37,57 +37,55 @@ refine connection SMB_Conn += { { auto response = make_intrusive(BifType::Record::SMB1::NegotiateResponse); - RecordVal* core; - RecordVal* lanman; - RecordVal* ntlm; - - RecordVal* security; - RecordVal* raw; - RecordVal* capabilities; switch ( ${val.word_count} ) { case 0x01: - core = new RecordVal(BifType::Record::SMB1::NegotiateResponseCore); + { + auto core = make_intrusive(BifType::Record::SMB1::NegotiateResponseCore); core->Assign(0, val_mgr->Count(${val.dialect_index})); - response->Assign(0, core); + response->Assign(0, std::move(core)); + } break; case 0x0d: - security = new RecordVal(BifType::Record::SMB1::NegotiateResponseSecurity); + { + auto security = make_intrusive(BifType::Record::SMB1::NegotiateResponseSecurity); security->Assign(0, val_mgr->Bool(${val.lanman.security_user_level})); security->Assign(1, val_mgr->Bool(${val.lanman.security_challenge_response})); - raw = new RecordVal(BifType::Record::SMB1::NegotiateRawMode); + auto raw = make_intrusive(BifType::Record::SMB1::NegotiateRawMode); raw->Assign(0, val_mgr->Bool(${val.lanman.raw_read_supported})); raw->Assign(1, val_mgr->Bool(${val.lanman.raw_write_supported})); - lanman = new RecordVal(BifType::Record::SMB1::NegotiateResponseLANMAN); + auto lanman = make_intrusive(BifType::Record::SMB1::NegotiateResponseLANMAN); lanman->Assign(0, val_mgr->Count(${val.word_count})); lanman->Assign(1, val_mgr->Count(${val.dialect_index})); - lanman->Assign(2, security); + lanman->Assign(2, std::move(security)); lanman->Assign(3, val_mgr->Count(${val.lanman.max_buffer_size})); lanman->Assign(4, val_mgr->Count(${val.lanman.max_mpx_count})); lanman->Assign(5, val_mgr->Count(${val.lanman.max_number_vcs})); - lanman->Assign(6, raw); + lanman->Assign(6, std::move(raw)); lanman->Assign(7, val_mgr->Count(${val.lanman.session_key})); lanman->Assign(8, time_from_lanman(${val.lanman.server_time}, ${val.lanman.server_date}, ${val.lanman.server_tz})); lanman->Assign(9, to_stringval(${val.lanman.encryption_key})); lanman->Assign(10, smb_string2stringval(${val.lanman.primary_domain})); - response->Assign(1, lanman); + response->Assign(1, std::move(lanman)); + } break; case 0x11: - security = new RecordVal(BifType::Record::SMB1::NegotiateResponseSecurity); + { + auto security = make_intrusive(BifType::Record::SMB1::NegotiateResponseSecurity); security->Assign(0, val_mgr->Bool(${val.ntlm.security_user_level})); security->Assign(1, val_mgr->Bool(${val.ntlm.security_challenge_response})); security->Assign(2, val_mgr->Bool(${val.ntlm.security_signatures_enabled})); security->Assign(3, val_mgr->Bool(${val.ntlm.security_signatures_required})); - capabilities = new RecordVal(BifType::Record::SMB1::NegotiateCapabilities); + auto capabilities = make_intrusive(BifType::Record::SMB1::NegotiateCapabilities); capabilities->Assign(0, val_mgr->Bool(${val.ntlm.capabilities_raw_mode})); capabilities->Assign(1, val_mgr->Bool(${val.ntlm.capabilities_mpx_mode})); capabilities->Assign(2, val_mgr->Bool(${val.ntlm.capabilities_unicode})); @@ -110,17 +108,17 @@ refine connection SMB_Conn += { capabilities->Assign(16, val_mgr->Bool(${val.ntlm.capabilities_compressed_data})); capabilities->Assign(17, val_mgr->Bool(${val.ntlm.capabilities_extended_security})); - ntlm = new RecordVal(BifType::Record::SMB1::NegotiateResponseNTLM); + auto ntlm = make_intrusive(BifType::Record::SMB1::NegotiateResponseNTLM); ntlm->Assign(0, val_mgr->Count(${val.word_count})); ntlm->Assign(1, val_mgr->Count(${val.dialect_index})); - ntlm->Assign(2, security); + ntlm->Assign(2, std::move(security)); ntlm->Assign(3, val_mgr->Count(${val.ntlm.max_buffer_size})); ntlm->Assign(4, val_mgr->Count(${val.ntlm.max_mpx_count})); ntlm->Assign(5, val_mgr->Count(${val.ntlm.max_number_vcs})); ntlm->Assign(6, val_mgr->Count(${val.ntlm.max_raw_size})); ntlm->Assign(7, val_mgr->Count(${val.ntlm.session_key})); - ntlm->Assign(8, capabilities); + ntlm->Assign(8, std::move(capabilities)); ntlm->Assign(9, filetime2brotime(${val.ntlm.server_time})); if ( ${val.ntlm.capabilities_extended_security} == false ) @@ -133,7 +131,8 @@ refine connection SMB_Conn += { ntlm->Assign(12, to_stringval(${val.ntlm.server_guid})); } - response->Assign(2, ntlm); + response->Assign(2, std::move(ntlm)); + } break; } BifEvent::enqueue_smb1_negotiate_response(bro_analyzer(), diff --git a/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac b/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac index c8022c1bf6..05fc5d3014 100644 --- a/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac @@ -1,7 +1,7 @@ refine connection SMB_Conn += { function proc_smb1_nt_create_andx_request(header: SMB_Header, val: SMB1_nt_create_andx_request): bool %{ - auto filename = IntrusivePtr{AdoptRef{}, smb_string2stringval(${val.filename})}; + auto filename = smb_string2stringval(${val.filename}); if ( ! ${header.is_pipe} && BifConst::SMB::pipe_filenames->AsTable()->Lookup(filename->CheckString()) ) @@ -33,10 +33,10 @@ refine connection SMB_Conn += { SMBHeaderVal(header), ${val.file_id}, ${val.end_of_file}, - {AdoptRef{}, SMB_BuildMACTimes(${val.last_write_time}, + SMB_BuildMACTimes(${val.last_write_time}, ${val.last_access_time}, ${val.create_time}, - ${val.last_change_time})}); + ${val.last_change_time})); } return true; diff --git a/src/analyzer/protocol/smb/smb1-com-query-information.pac b/src/analyzer/protocol/smb/smb1-com-query-information.pac index 29ffcf089c..fd458222f1 100644 --- a/src/analyzer/protocol/smb/smb1-com-query-information.pac +++ b/src/analyzer/protocol/smb/smb1-com-query-information.pac @@ -6,7 +6,7 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb1_query_information_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), - {AdoptRef{}, smb_string2stringval(${val.filename})}); + smb_string2stringval(${val.filename})); return true; %} diff --git a/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac b/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac index d2eadde58a..f6dddc345e 100644 --- a/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac @@ -13,7 +13,6 @@ refine connection SMB_Conn += { if ( smb1_session_setup_andx_request ) { auto request = make_intrusive(BifType::Record::SMB1::SessionSetupAndXRequest); - RecordVal* capabilities; request->Assign(0, val_mgr->Count(${val.word_count})); switch ( ${val.word_count} ) { @@ -31,7 +30,8 @@ refine connection SMB_Conn += { break; case 12: // NT LM 0.12 with extended security - capabilities = new RecordVal(BifType::Record::SMB1::SessionSetupAndXCapabilities); + { + auto capabilities = make_intrusive(BifType::Record::SMB1::SessionSetupAndXCapabilities); capabilities->Assign(0, val_mgr->Bool(${val.ntlm_extended_security.capabilities.unicode})); capabilities->Assign(1, val_mgr->Bool(${val.ntlm_extended_security.capabilities.large_files})); capabilities->Assign(2, val_mgr->Bool(${val.ntlm_extended_security.capabilities.nt_smbs})); @@ -47,11 +47,13 @@ refine connection SMB_Conn += { request->Assign(5, smb_string2stringval(${val.ntlm_extended_security.native_os})); request->Assign(6, smb_string2stringval(${val.ntlm_extended_security.native_lanman})); - request->Assign(13, capabilities); + request->Assign(13, std::move(capabilities)); + } break; case 13: // NT LM 0.12 without extended security - capabilities = new RecordVal(BifType::Record::SMB1::SessionSetupAndXCapabilities); + { + auto capabilities = make_intrusive(BifType::Record::SMB1::SessionSetupAndXCapabilities); capabilities->Assign(0, val_mgr->Bool(${val.ntlm_nonextended_security.capabilities.unicode})); capabilities->Assign(1, val_mgr->Bool(${val.ntlm_nonextended_security.capabilities.large_files})); capabilities->Assign(2, val_mgr->Bool(${val.ntlm_nonextended_security.capabilities.nt_smbs})); @@ -71,7 +73,8 @@ refine connection SMB_Conn += { request->Assign(10, to_stringval(${val.ntlm_nonextended_security.case_insensitive_password})); request->Assign(11, to_stringval(${val.ntlm_nonextended_security.case_sensitive_password})); - request->Assign(13, capabilities); + request->Assign(13, std::move(capabilities)); + } break; } @@ -94,9 +97,9 @@ refine connection SMB_Conn += { { case 3: // pre NT LM 0.12 response->Assign(1, val_mgr->Bool(${val.lanman.is_guest})); - response->Assign(2, ${val.lanman.byte_count} == 0 ? val_mgr->EmptyString()->Ref()->AsStringVal() : smb_string2stringval(${val.lanman.native_os[0]})); - response->Assign(3, ${val.lanman.byte_count} == 0 ? val_mgr->EmptyString()->Ref()->AsStringVal() : smb_string2stringval(${val.lanman.native_lanman[0]})); - response->Assign(4, ${val.lanman.byte_count} == 0 ? val_mgr->EmptyString()->Ref()->AsStringVal() : smb_string2stringval(${val.lanman.primary_domain[0]})); + response->Assign(2, ${val.lanman.byte_count} == 0 ? val_mgr->EmptyString() : smb_string2stringval(${val.lanman.native_os[0]})); + response->Assign(3, ${val.lanman.byte_count} == 0 ? val_mgr->EmptyString() : smb_string2stringval(${val.lanman.native_lanman[0]})); + response->Assign(4, ${val.lanman.byte_count} == 0 ? val_mgr->EmptyString() : smb_string2stringval(${val.lanman.primary_domain[0]})); break; case 4: // NT LM 0.12 response->Assign(1, val_mgr->Bool(${val.ntlm.is_guest})); diff --git a/src/analyzer/protocol/smb/smb1-com-transaction.pac b/src/analyzer/protocol/smb/smb1-com-transaction.pac index c227203c6a..1ffc80209f 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction.pac @@ -65,7 +65,7 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb1_transaction_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), - {AdoptRef{}, smb_string2stringval(${val.name})}, + smb_string2stringval(${val.name}), ${val.sub_cmd}, std::move(parameters), std::move(payload_str)); diff --git a/src/analyzer/protocol/smb/smb1-com-transaction2.pac b/src/analyzer/protocol/smb/smb1-com-transaction2.pac index 5bec0b667b..b360c25798 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction2.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction2.pac @@ -220,7 +220,7 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb1_trans2_query_path_info_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), - {AdoptRef{}, smb_string2stringval(${val.file_name})}); + smb_string2stringval(${val.file_name})); } return true; @@ -325,7 +325,7 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb1_trans2_get_dfs_referral_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), - {AdoptRef{}, smb_string2stringval(${val.file_name})}); + smb_string2stringval(${val.file_name})); } return true; %} diff --git a/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac b/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac index 69e53afcf7..a2c415e56c 100644 --- a/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac @@ -6,14 +6,14 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb1_tree_connect_andx_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), - {AdoptRef{}, smb_string2stringval(${val.path})}, - {AdoptRef{}, smb_string2stringval(${val.service})}); + smb_string2stringval(${val.path}), + smb_string2stringval(${val.service})); return true; %} function proc_smb1_tree_connect_andx_response(header: SMB_Header, val: SMB1_tree_connect_andx_response): bool %{ - auto service_string = IntrusivePtr{AdoptRef{}, smb_string2stringval(${val.service})}; + auto service_string = smb_string2stringval(${val.service}); auto s = reinterpret_cast(service_string->Bytes()); if ( strncmp(s, "IPC", 3) == 0 ) @@ -25,7 +25,7 @@ refine connection SMB_Conn += { SMBHeaderVal(header), std::move(service_string), ${val.byte_count} > ${val.service.a}->size() ? - IntrusivePtr{AdoptRef{}, smb_string2stringval(${val.native_file_system[0]})} : + smb_string2stringval(${val.native_file_system[0]}) : val_mgr->EmptyString()); return true; diff --git a/src/analyzer/protocol/smb/smb2-com-close.pac b/src/analyzer/protocol/smb/smb2-com-close.pac index 9ad939f60a..2a4c7baa41 100644 --- a/src/analyzer/protocol/smb/smb2-com-close.pac +++ b/src/analyzer/protocol/smb/smb2-com-close.pac @@ -6,8 +6,8 @@ refine connection SMB_Conn += { { BifEvent::enqueue_smb2_close_request(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, - {AdoptRef{}, BuildSMB2GUID(${val.file_id})}); + BuildSMB2HeaderVal(h), + BuildSMB2GUID(${val.file_id})); } file_mgr->EndOfFile(bro_analyzer()->GetAnalyzerTag(), @@ -32,7 +32,7 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb2_close_response(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, + BuildSMB2HeaderVal(h), std::move(resp)); } diff --git a/src/analyzer/protocol/smb/smb2-com-create.pac b/src/analyzer/protocol/smb/smb2-com-create.pac index 1b42de1b4a..ce4178ad95 100644 --- a/src/analyzer/protocol/smb/smb2-com-create.pac +++ b/src/analyzer/protocol/smb/smb2-com-create.pac @@ -2,7 +2,8 @@ refine connection SMB_Conn += { function proc_smb2_create_request(h: SMB2_Header, val: SMB2_create_request): bool %{ - StringVal *filename = smb2_string2stringval(${val.filename}); + auto filename = smb2_string2stringval(${val.filename}); + if ( ! ${h.is_pipe} && BifConst::SMB::pipe_filenames->AsTable()->Lookup(filename->CheckString()) ) { @@ -16,18 +17,14 @@ refine connection SMB_Conn += { if ( smb2_create_request ) { auto requestinfo = make_intrusive(BifType::Record::SMB2::CreateRequest); - requestinfo->Assign(0, filename); + requestinfo->Assign(0, std::move(filename)); requestinfo->Assign(1, val_mgr->Count(${val.disposition})); requestinfo->Assign(2, val_mgr->Count(${val.create_options})); BifEvent::enqueue_smb2_create_request(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, + BuildSMB2HeaderVal(h), std::move(requestinfo)); } - else - { - delete filename; - } return true; %} @@ -47,7 +44,7 @@ refine connection SMB_Conn += { responseinfo->Assign(4, val_mgr->Count(${val.create_action})); BifEvent::enqueue_smb2_create_response(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, + BuildSMB2HeaderVal(h), std::move(responseinfo)); } diff --git a/src/analyzer/protocol/smb/smb2-com-negotiate.pac b/src/analyzer/protocol/smb/smb2-com-negotiate.pac index 6c3b26e8f5..0ebeda9012 100644 --- a/src/analyzer/protocol/smb/smb2-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb2-com-negotiate.pac @@ -28,7 +28,7 @@ refine connection SMB_Conn += { dialects->Assign(i, val_mgr->Count((*${val.dialects})[i])); BifEvent::enqueue_smb2_negotiate_request(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, + BuildSMB2HeaderVal(h), std::move(dialects)); } @@ -48,7 +48,7 @@ refine connection SMB_Conn += { nr->Assign(4, filetime2brotime(${val.server_start_time})); nr->Assign(5, val_mgr->Count(${val.negotiate_context_count})); - VectorVal* cv = new VectorVal(BifType::Vector::SMB2::NegotiateContextValues); + auto cv = make_intrusive(BifType::Vector::SMB2::NegotiateContextValues); if ( ${val.dialect_revision} == 0x0311 && ${val.negotiate_context_count} > 0 ) { @@ -58,10 +58,10 @@ refine connection SMB_Conn += { cv->Assign(${val.smb3_ncl.list.vals}->size(), BuildSMB2ContextVal(${val.smb3_ncl.list.last_val})); } - nr->Assign(6, cv); + nr->Assign(6, std::move(cv)); BifEvent::enqueue_smb2_negotiate_response(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, + BuildSMB2HeaderVal(h), std::move(nr)); } diff --git a/src/analyzer/protocol/smb/smb2-com-read.pac b/src/analyzer/protocol/smb/smb2-com-read.pac index ce78903401..a3b01e4f5f 100644 --- a/src/analyzer/protocol/smb/smb2-com-read.pac +++ b/src/analyzer/protocol/smb/smb2-com-read.pac @@ -28,8 +28,8 @@ refine connection SMB_Conn += { { BifEvent::enqueue_smb2_read_request(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, - {AdoptRef{}, BuildSMB2GUID(${val.file_id})}, + BuildSMB2HeaderVal(h), + BuildSMB2GUID(${val.file_id}), ${val.offset}, ${val.read_len}); } diff --git a/src/analyzer/protocol/smb/smb2-com-session-setup.pac b/src/analyzer/protocol/smb/smb2-com-session-setup.pac index 4060b18f99..1f38fe1fb2 100644 --- a/src/analyzer/protocol/smb/smb2-com-session-setup.pac +++ b/src/analyzer/protocol/smb/smb2-com-session-setup.pac @@ -9,7 +9,7 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb2_session_setup_request(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, + BuildSMB2HeaderVal(h), std::move(req)); } @@ -30,7 +30,7 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb2_session_setup_response(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, + BuildSMB2HeaderVal(h), std::move(resp)); } diff --git a/src/analyzer/protocol/smb/smb2-com-set-info.pac b/src/analyzer/protocol/smb/smb2-com-set-info.pac index d390c174db..ce6b089986 100644 --- a/src/analyzer/protocol/smb/smb2-com-set-info.pac +++ b/src/analyzer/protocol/smb/smb2-com-set-info.pac @@ -30,13 +30,13 @@ refine connection SMB_Conn += { if ( smb2_file_sattr ) BifEvent::enqueue_smb2_file_sattr(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, - {AdoptRef{}, SMB_BuildMACTimes(${val.last_write_time}, - ${val.last_access_time}, - ${val.creation_time}, - ${val.change_time})}, - {AdoptRef{}, smb2_file_attrs_to_bro(${val.file_attrs})}); + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), + SMB_BuildMACTimes(${val.last_write_time}, + ${val.last_access_time}, + ${val.creation_time}, + ${val.change_time}), + smb2_file_attrs_to_bro(${val.file_attrs})); return true; %} @@ -46,9 +46,9 @@ refine connection SMB_Conn += { if ( smb2_file_rename ) BifEvent::enqueue_smb2_file_rename(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, - {AdoptRef{}, smb2_string2stringval(${val.filename})}); + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), + smb2_string2stringval(${val.filename})); return true; %} @@ -58,8 +58,8 @@ refine connection SMB_Conn += { if ( smb2_file_delete ) BifEvent::enqueue_smb2_file_delete(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), (${val.delete_pending} > 0)); return true; @@ -70,8 +70,8 @@ refine connection SMB_Conn += { if ( smb2_file_allocation ) BifEvent::enqueue_smb2_file_allocation(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), (${val.allocation_size})); return true; @@ -82,8 +82,8 @@ refine connection SMB_Conn += { if ( smb2_file_endoffile ) BifEvent::enqueue_smb2_file_endoffile(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), ${val.endoffile}); return true; @@ -106,9 +106,9 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb2_file_fullea(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, - std::move(eas)); + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), + std::move(eas)); } return true; @@ -119,10 +119,10 @@ refine connection SMB_Conn += { if ( smb2_file_link ) BifEvent::enqueue_smb2_file_link(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), ${val.root_directory}, - {AdoptRef{}, smb2_string2stringval(${val.file_name})}); + smb2_string2stringval(${val.file_name})); return true; %} @@ -132,8 +132,8 @@ refine connection SMB_Conn += { if ( smb2_file_mode ) BifEvent::enqueue_smb2_file_mode(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), ${val.mode}); return true; @@ -144,10 +144,10 @@ refine connection SMB_Conn += { if ( smb2_file_pipe ) BifEvent::enqueue_smb2_file_pipe(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), ${val.read_mode}, - ${val.completion_mode}); + ${val.completion_mode}); return true; %} @@ -157,8 +157,8 @@ refine connection SMB_Conn += { if ( smb2_file_position ) BifEvent::enqueue_smb2_file_position(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), ${val.current_byte_offset}); return true; @@ -169,9 +169,9 @@ refine connection SMB_Conn += { if ( smb2_file_shortname ) BifEvent::enqueue_smb2_file_shortname(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, - {AdoptRef{}, smb2_string2stringval(${val.filename})}); + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), + smb2_string2stringval(${val.filename})); return true; %} @@ -181,8 +181,8 @@ refine connection SMB_Conn += { if ( smb2_file_validdatalength ) BifEvent::enqueue_smb2_file_validdatalength(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), ${val.validdatalength}); return true; @@ -202,9 +202,9 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb2_file_fscontrol(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, - std::move(r)); + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), + std::move(r)); } return true; @@ -215,10 +215,10 @@ refine connection SMB_Conn += { if ( smb2_file_fsobjectid ) BifEvent::enqueue_smb2_file_fsobjectid(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(${val.sir.header})}, - {AdoptRef{}, BuildSMB2GUID(${val.sir.file_id})}, - {AdoptRef{}, BuildSMB2GUID(${val.object_id})}, - {AdoptRef{}, smb2_string2stringval(${val.extended_info})}); + BuildSMB2HeaderVal(${val.sir.header}), + BuildSMB2GUID(${val.sir.file_id}), + BuildSMB2GUID(${val.object_id}), + smb2_string2stringval(${val.extended_info})); return true; %} diff --git a/src/analyzer/protocol/smb/smb2-com-transform-header.pac b/src/analyzer/protocol/smb/smb2-com-transform-header.pac index 2c2da578e6..c9629fa842 100644 --- a/src/analyzer/protocol/smb/smb2-com-transform-header.pac +++ b/src/analyzer/protocol/smb/smb2-com-transform-header.pac @@ -1,24 +1,20 @@ refine connection SMB_Conn += { - function BuildSMB2TransformHeaderVal(hdr: SMB2_transform_header): BroVal - %{ - RecordVal* r = new RecordVal(BifType::Record::SMB2::Transform_header); - - r->Assign(0, to_stringval(${hdr.signature})); - r->Assign(1, to_stringval(${hdr.nonce})); - r->Assign(2, val_mgr->Count(${hdr.orig_msg_size})); - r->Assign(3, val_mgr->Count(${hdr.flags})); - r->Assign(4, val_mgr->Count(${hdr.session_id})); - - return r; - %} - function proc_smb2_transform_header(hdr: SMB2_transform_header) : bool %{ if ( smb2_transform_header ) + { + auto r = make_intrusive(BifType::Record::SMB2::Transform_header); + r->Assign(0, to_stringval(${hdr.signature})); + r->Assign(1, to_stringval(${hdr.nonce})); + r->Assign(2, val_mgr->Count(${hdr.orig_msg_size})); + r->Assign(3, val_mgr->Count(${hdr.flags})); + r->Assign(4, val_mgr->Count(${hdr.session_id})); + BifEvent::enqueue_smb2_transform_header(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2TransformHeaderVal(hdr)}); + std::move(r)); + } return true; %} diff --git a/src/analyzer/protocol/smb/smb2-com-tree-connect.pac b/src/analyzer/protocol/smb/smb2-com-tree-connect.pac index 262c8ef173..68449d999f 100644 --- a/src/analyzer/protocol/smb/smb2-com-tree-connect.pac +++ b/src/analyzer/protocol/smb/smb2-com-tree-connect.pac @@ -5,8 +5,8 @@ refine connection SMB_Conn += { if ( smb2_tree_connect_request ) BifEvent::enqueue_smb2_tree_connect_request(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(header)}, - {AdoptRef{}, smb2_string2stringval(${val.path})}); + BuildSMB2HeaderVal(header), + smb2_string2stringval(${val.path})); return true; %} @@ -23,7 +23,7 @@ refine connection SMB_Conn += { BifEvent::enqueue_smb2_tree_connect_response(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(header)}, + BuildSMB2HeaderVal(header), std::move(resp)); } diff --git a/src/analyzer/protocol/smb/smb2-com-tree-disconnect.pac b/src/analyzer/protocol/smb/smb2-com-tree-disconnect.pac index a4ce9cf21e..f98523e94a 100644 --- a/src/analyzer/protocol/smb/smb2-com-tree-disconnect.pac +++ b/src/analyzer/protocol/smb/smb2-com-tree-disconnect.pac @@ -9,7 +9,7 @@ refine connection SMB_Conn += { { BifEvent::enqueue_smb2_tree_disconnect_request(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(header)}); + BuildSMB2HeaderVal(header)); } return true; @@ -21,7 +21,7 @@ refine connection SMB_Conn += { { BifEvent::enqueue_smb2_tree_disconnect_response(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(header)}); + BuildSMB2HeaderVal(header)); } return true; diff --git a/src/analyzer/protocol/smb/smb2-com-write.pac b/src/analyzer/protocol/smb/smb2-com-write.pac index e638f45a55..773dcd8bcc 100644 --- a/src/analyzer/protocol/smb/smb2-com-write.pac +++ b/src/analyzer/protocol/smb/smb2-com-write.pac @@ -6,8 +6,8 @@ refine connection SMB_Conn += { { BifEvent::enqueue_smb2_write_request(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, - {AdoptRef{}, BuildSMB2GUID(${val.file_id})}, + BuildSMB2HeaderVal(h), + BuildSMB2GUID(${val.file_id}), ${val.offset}, ${val.data_len}); } @@ -29,7 +29,7 @@ refine connection SMB_Conn += { { BifEvent::enqueue_smb2_write_response(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, + BuildSMB2HeaderVal(h), ${val.write_count}); } diff --git a/src/analyzer/protocol/smb/smb2-protocol.pac b/src/analyzer/protocol/smb/smb2-protocol.pac index 00e525ff50..dd5a2a109a 100644 --- a/src/analyzer/protocol/smb/smb2-protocol.pac +++ b/src/analyzer/protocol/smb/smb2-protocol.pac @@ -1,6 +1,137 @@ # Documentation for SMB2 protocol from here: # http://msdn.microsoft.com/en-us/library/cc246497(v=PROT.13).aspx +%header{ +IntrusivePtr BuildSMB2HeaderVal(SMB2_Header* hdr); +IntrusivePtr BuildSMB2GUID(SMB2_guid* file_id); +IntrusivePtr smb2_file_attrs_to_bro(SMB2_file_attributes* val); +IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv); +%} + +%code{ +IntrusivePtr BuildSMB2HeaderVal(SMB2_Header* hdr) + { + auto r = make_intrusive(BifType::Record::SMB2::Header); + r->Assign(0, val_mgr->Count(${hdr.credit_charge})); + r->Assign(1, val_mgr->Count(${hdr.status})); + r->Assign(2, val_mgr->Count(${hdr.command})); + r->Assign(3, val_mgr->Count(${hdr.credits})); + r->Assign(4, val_mgr->Count(${hdr.flags})); + r->Assign(5, val_mgr->Count(${hdr.message_id})); + r->Assign(6, val_mgr->Count(${hdr.process_id})); + r->Assign(7, val_mgr->Count(${hdr.tree_id})); + r->Assign(8, val_mgr->Count(${hdr.session_id})); + r->Assign(9, to_stringval(${hdr.signature})); + return r; + } + +IntrusivePtr BuildSMB2GUID(SMB2_guid* file_id) + { + auto r = make_intrusive(BifType::Record::SMB2::GUID); + r->Assign(0, val_mgr->Count(${file_id.persistent})); + r->Assign(1, val_mgr->Count(${file_id._volatile})); + return r; + } + +IntrusivePtr smb2_file_attrs_to_bro(SMB2_file_attributes* val) + { + auto r = make_intrusive(BifType::Record::SMB2::FileAttrs); + r->Assign(0, val_mgr->Bool(${val.read_only})); + r->Assign(1, val_mgr->Bool(${val.hidden})); + r->Assign(2, val_mgr->Bool(${val.system})); + r->Assign(3, val_mgr->Bool(${val.directory})); + r->Assign(4, val_mgr->Bool(${val.archive})); + r->Assign(5, val_mgr->Bool(${val.normal})); + r->Assign(6, val_mgr->Bool(${val.temporary})); + r->Assign(7, val_mgr->Bool(${val.sparse_file})); + r->Assign(8, val_mgr->Bool(${val.reparse_point})); + r->Assign(9, val_mgr->Bool(${val.compressed})); + r->Assign(10, val_mgr->Bool(${val.offline})); + r->Assign(11, val_mgr->Bool(${val.not_content_indexed})); + r->Assign(12, val_mgr->Bool(${val.encrypted})); + r->Assign(13, val_mgr->Bool(${val.integrity_stream})); + r->Assign(14, val_mgr->Bool(${val.no_scrub_data})); + return r; + } + +IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) + { + auto r = make_intrusive(BifType::Record::SMB2::NegotiateContextValue); + + r->Assign(0, val_mgr->Count(${ncv.context_type})); + r->Assign(1, val_mgr->Count(${ncv.data_length})); + + switch ( ${ncv.context_type} ) { + case SMB2_PREAUTH_INTEGRITY_CAPABILITIES: + { + auto rpreauth = make_intrusive(BifType::Record::SMB2::PreAuthIntegrityCapabilities); + rpreauth->Assign(0, val_mgr->Count(${ncv.preauth_integrity_capabilities.hash_alg_count})); + rpreauth->Assign(1, val_mgr->Count(${ncv.preauth_integrity_capabilities.salt_length})); + + auto ha = make_intrusive(internal_type("index_vec")->AsVectorType()); + + for ( int i = 0; i < ${ncv.preauth_integrity_capabilities.hash_alg_count}; ++i ) + { + const auto& vec = *${ncv.preauth_integrity_capabilities.hash_alg}; + ha->Assign(i, val_mgr->Count(vec[i])); + } + + rpreauth->Assign(2, std::move(ha)); + rpreauth->Assign(3, to_stringval(${ncv.preauth_integrity_capabilities.salt})); + r->Assign(2, std::move(rpreauth)); + } + break; + + case SMB2_ENCRYPTION_CAPABILITIES: + { + auto rencr = make_intrusive(BifType::Record::SMB2::EncryptionCapabilities); + rencr->Assign(0, val_mgr->Count(${ncv.encryption_capabilities.cipher_count})); + + auto c = make_intrusive(internal_type("index_vec")->AsVectorType()); + + for ( int i = 0; i < ${ncv.encryption_capabilities.cipher_count}; ++i ) + { + const auto& vec = *${ncv.encryption_capabilities.ciphers}; + c->Assign(i, val_mgr->Count(vec[i])); + } + + rencr->Assign(1, std::move(c)); + r->Assign(3, std::move(rencr)); + } + break; + + case SMB2_COMPRESSION_CAPABILITIES: + { + auto rcomp = make_intrusive(BifType::Record::SMB2::CompressionCapabilities); + rcomp->Assign(0, val_mgr->Count(${ncv.compression_capabilities.alg_count})); + + auto c = make_intrusive(internal_type("index_vec")->AsVectorType()); + + for ( int i = 0; i < ${ncv.compression_capabilities.alg_count}; ++i ) + { + const auto& vec = *${ncv.compression_capabilities.algs}; + c->Assign(i, val_mgr->Count(vec[i])); + } + + rcomp->Assign(1, std::move(c)); + r->Assign(4, std::move(rcomp)); + } + break; + + case SMB2_NETNAME_NEGOTIATE_CONTEXT_ID: + { + r->Assign(5, to_stringval(${ncv.netname_negotiate_context_id.net_name})); + } + break; + + default: + break; + } + + return r; + } +%} + enum smb2_commands { SMB2_NEGOTIATE_PROTOCOL = 0, SMB2_SESSION_SETUP = 1, @@ -100,102 +231,6 @@ refine connection SMB_Conn += { std::map smb2_request_tree_id; %} - function BuildSMB2ContextVal(ncv: SMB3_negotiate_context_value): BroVal - %{ - RecordVal* r = new RecordVal(BifType::Record::SMB2::NegotiateContextValue); - - r->Assign(0, val_mgr->Count(${ncv.context_type})); - r->Assign(1, val_mgr->Count(${ncv.data_length})); - - switch ( ${ncv.context_type} ) { - case SMB2_PREAUTH_INTEGRITY_CAPABILITIES: - { - RecordVal* rpreauth = new RecordVal(BifType::Record::SMB2::PreAuthIntegrityCapabilities); - rpreauth->Assign(0, val_mgr->Count(${ncv.preauth_integrity_capabilities.hash_alg_count})); - rpreauth->Assign(1, val_mgr->Count(${ncv.preauth_integrity_capabilities.salt_length})); - - VectorVal* ha = new VectorVal(internal_type("index_vec")->AsVectorType()); - - for ( int i = 0; i < (${ncv.preauth_integrity_capabilities.hash_alg_count}); ++i ) - ha->Assign(i, val_mgr->Count(${ncv.preauth_integrity_capabilities.hash_alg[i]})); - - rpreauth->Assign(2, ha); - rpreauth->Assign(3, to_stringval(${ncv.preauth_integrity_capabilities.salt})); - r->Assign(2, rpreauth); - } - break; - - case SMB2_ENCRYPTION_CAPABILITIES: - { - RecordVal* rencr = new RecordVal(BifType::Record::SMB2::EncryptionCapabilities); - rencr->Assign(0, val_mgr->Count(${ncv.encryption_capabilities.cipher_count})); - - VectorVal* c = new VectorVal(internal_type("index_vec")->AsVectorType()); - - for ( int i = 0; i < (${ncv.encryption_capabilities.cipher_count}); ++i ) - c->Assign(i, val_mgr->Count(${ncv.encryption_capabilities.ciphers[i]})); - - rencr->Assign(1, c); - r->Assign(3, rencr); - } - break; - - case SMB2_COMPRESSION_CAPABILITIES: - { - RecordVal* rcomp = new RecordVal(BifType::Record::SMB2::CompressionCapabilities); - rcomp->Assign(0, val_mgr->Count(${ncv.compression_capabilities.alg_count})); - - VectorVal* c = new VectorVal(internal_type("index_vec")->AsVectorType()); - - for ( int i = 0; i < (${ncv.compression_capabilities.alg_count}); ++i ) - c->Assign(i, val_mgr->Count(${ncv.compression_capabilities.algs[i]})); - - rcomp->Assign(1, c); - r->Assign(4, rcomp); - } - break; - - case SMB2_NETNAME_NEGOTIATE_CONTEXT_ID: - { - r->Assign(5, to_stringval(${ncv.netname_negotiate_context_id.net_name})); - } - break; - - default: - break; - } - - return r; - %} - - function BuildSMB2HeaderVal(hdr: SMB2_Header): BroVal - %{ - RecordVal* r = new RecordVal(BifType::Record::SMB2::Header); - - r->Assign(0, val_mgr->Count(${hdr.credit_charge})); - r->Assign(1, val_mgr->Count(${hdr.status})); - r->Assign(2, val_mgr->Count(${hdr.command})); - r->Assign(3, val_mgr->Count(${hdr.credits})); - r->Assign(4, val_mgr->Count(${hdr.flags})); - r->Assign(5, val_mgr->Count(${hdr.message_id})); - r->Assign(6, val_mgr->Count(${hdr.process_id})); - r->Assign(7, val_mgr->Count(${hdr.tree_id})); - r->Assign(8, val_mgr->Count(${hdr.session_id})); - r->Assign(9, to_stringval(${hdr.signature})); - - return r; - %} - - function BuildSMB2GUID(file_id: SMB2_guid): BroVal - %{ - RecordVal* r = new RecordVal(BifType::Record::SMB2::GUID); - - r->Assign(0, val_mgr->Count(${file_id.persistent})); - r->Assign(1, val_mgr->Count(${file_id._volatile})); - - return r; - %} - function proc_smb2_message(h: SMB2_Header, is_orig: bool): bool %{ if ( is_orig ) @@ -216,8 +251,7 @@ refine connection SMB_Conn += { if ( smb2_message ) { BifEvent::enqueue_smb2_message(bro_analyzer(), bro_analyzer()->Conn(), - {AdoptRef{}, BuildSMB2HeaderVal(h)}, - is_orig); + BuildSMB2HeaderVal(h), is_orig); } return true; %} @@ -234,29 +268,6 @@ refine connection SMB_Conn += { %} }; -function smb2_file_attrs_to_bro(val: SMB2_file_attributes): BroVal - %{ - RecordVal* r = new RecordVal(BifType::Record::SMB2::FileAttrs); - - r->Assign(0, val_mgr->Bool(${val.read_only})); - r->Assign(1, val_mgr->Bool(${val.hidden})); - r->Assign(2, val_mgr->Bool(${val.system})); - r->Assign(3, val_mgr->Bool(${val.directory})); - r->Assign(4, val_mgr->Bool(${val.archive})); - r->Assign(5, val_mgr->Bool(${val.normal})); - r->Assign(6, val_mgr->Bool(${val.temporary})); - r->Assign(7, val_mgr->Bool(${val.sparse_file})); - r->Assign(8, val_mgr->Bool(${val.reparse_point})); - r->Assign(9, val_mgr->Bool(${val.compressed})); - r->Assign(10, val_mgr->Bool(${val.offline})); - r->Assign(11, val_mgr->Bool(${val.not_content_indexed})); - r->Assign(12, val_mgr->Bool(${val.encrypted})); - r->Assign(13, val_mgr->Bool(${val.integrity_stream})); - r->Assign(14, val_mgr->Bool(${val.no_scrub_data})); - - return r; - %} - type SMB2_file_attributes = record { flags : uint32; } &let { diff --git a/src/binpac_bro-lib.pac b/src/binpac_bro-lib.pac index ed8efff361..5b5b7594b1 100644 --- a/src/binpac_bro-lib.pac +++ b/src/binpac_bro-lib.pac @@ -6,22 +6,18 @@ #include "ConvertUTF.h" %} -function network_time(): double - %{ - return ::network_time; - %} - -function utf16_bytestring_to_utf8_val(conn: Connection, utf16: bytestring): StringVal - %{ +%code{ +IntrusivePtr utf16_to_utf8_val(Connection* conn, const bytestring& utf16) + { std::string resultstring; size_t utf8size = (3 * utf16.length() + 1); if ( utf8size > resultstring.max_size() ) { - reporter->Info("utf16 too long in utf16_bytestring_to_utf8_val"); + reporter->Weird(conn, "utf16_conversion_failed", "utf16 too long in utf16_to_utf8_val"); // If the conversion didn't go well, return the original data. - return to_stringval(utf16).release(); + return to_stringval(utf16); } resultstring.resize(utf8size, '\0'); @@ -47,14 +43,25 @@ function utf16_bytestring_to_utf8_val(conn: Connection, utf16: bytestring): Stri lenientConversion); if ( res != conversionOK ) { - reporter->Weird(conn, "utf16_conversion_failed", "utf16 conversion failed in utf16_bytestring_to_utf8_val"); + reporter->Weird(conn, "utf16_conversion_failed", "utf16 conversion failed in utf16_to_utf8_val"); // If the conversion didn't go well, return the original data. - return to_stringval(utf16).release(); + return to_stringval(utf16); } *targetstart = 0; // We're relying on no nulls being in the string. //return new StringVal(resultstring.length(), (const char *) resultstring.data()); - return new StringVal(resultstring.c_str()); + return make_intrusive(resultstring.c_str()); + } + +StringVal* utf16_bytestring_to_utf8_val(Connection* conn, const bytestring& utf16) + { + return utf16_to_utf8_val(conn, utf16).release(); + } +%} + +function network_time(): double + %{ + return ::network_time; %} diff --git a/src/binpac_bro.h b/src/binpac_bro.h index 743bb7443d..1d84ad0810 100644 --- a/src/binpac_bro.h +++ b/src/binpac_bro.h @@ -40,4 +40,9 @@ inline IntrusivePtr to_stringval(const_bytestring const& str) return make_intrusive(str.length(), (const char*) str.begin()); } +IntrusivePtr utf16_to_utf8_val(Connection* conn, const bytestring& utf16); + +[[deprecated("Remove in v4.1. Use utf16_to_utf8_val() instead.")]] +StringVal* utf16_bytestring_to_utf8_val(Connection* conn, const bytestring& utf16); + } // namespace binpac diff --git a/src/bro.pac b/src/bro.pac index 5f976b448a..b622041c12 100644 --- a/src/bro.pac +++ b/src/bro.pac @@ -8,4 +8,3 @@ extern type BroPortVal; extern type BroStringVal; function network_time(): double; -function utf16_bytestring_to_utf8_val(conn: Connection, utf16: bytestring): StringVal; From b05e5c7686177b1a61e5204da0cd92a7b068f90d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 6 May 2020 15:01:14 -0700 Subject: [PATCH 013/151] Migrate IP.cc to use IntrusivePtr --- src/IP.cc | 63 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/IP.cc b/src/IP.cc index 820570a2d6..590f932a90 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -42,14 +42,14 @@ static inline RecordType* hdrType(RecordType*& type, const char* name) return type; } -static VectorVal* BuildOptionsVal(const u_char* data, int len) +static IntrusivePtr BuildOptionsVal(const u_char* data, int len) { - VectorVal* vv = new VectorVal(internal_type("ip6_options")->AsVectorType()); + auto vv = make_intrusive(internal_type("ip6_options")->AsVectorType()); while ( len > 0 ) { const struct ip6_opt* opt = (const struct ip6_opt*) data; - RecordVal* rv = new RecordVal(hdrType(ip6_option_type, "ip6_option")); + auto rv = make_intrusive(hdrType(ip6_option_type, "ip6_option")); rv->Assign(0, val_mgr->Count(opt->ip6o_type)); if ( opt->ip6o_type == 0 ) @@ -71,7 +71,7 @@ static VectorVal* BuildOptionsVal(const u_char* data, int len) len -= opt->ip6o_len + off; } - vv->Assign(vv->Size(), rv); + vv->Assign(vv->Size(), std::move(rv)); } return vv; @@ -188,7 +188,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const rv->Assign(3, val_mgr->Count(mob->ip6mob_rsv)); rv->Assign(4, val_mgr->Count(ntohs(mob->ip6mob_chksum))); - RecordVal* msg = new RecordVal(hdrType(ip6_mob_msg_type, "ip6_mobility_msg")); + auto msg = make_intrusive(hdrType(ip6_mob_msg_type, "ip6_mobility_msg")); msg->Assign(0, val_mgr->Count(mob->ip6mob_type)); uint16_t off = sizeof(ip6_mobility); @@ -197,63 +197,63 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const switch ( mob->ip6mob_type ) { case 0: { - RecordVal* m = new RecordVal(hdrType(ip6_mob_brr_type, "ip6_mobility_brr")); + auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_brr")); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); off += sizeof(uint16_t); m->Assign(1, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(1, m); + msg->Assign(1, std::move(m)); } break; case 1: { - RecordVal* m = new RecordVal(hdrType(ip6_mob_brr_type, "ip6_mobility_hoti")); + auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_hoti")); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); off += sizeof(uint16_t) + sizeof(uint64_t); m->Assign(2, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(2, m); + msg->Assign(2, std::move(m)); break; } case 2: { - RecordVal* m = new RecordVal(hdrType(ip6_mob_brr_type, "ip6_mobility_coti")); + auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_coti")); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); off += sizeof(uint16_t) + sizeof(uint64_t); m->Assign(2, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(3, m); + msg->Assign(3, std::move(m)); break; } case 3: { - RecordVal* m = new RecordVal(hdrType(ip6_mob_brr_type, "ip6_mobility_hot")); + auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_hot")); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(2, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t)))))); off += sizeof(uint16_t) + 2 * sizeof(uint64_t); m->Assign(3, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(4, m); + msg->Assign(4, std::move(m)); break; } case 4: { - RecordVal* m = new RecordVal(hdrType(ip6_mob_brr_type, "ip6_mobility_cot")); + auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_cot")); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(2, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t)))))); off += sizeof(uint16_t) + 2 * sizeof(uint64_t); m->Assign(3, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(5, m); + msg->Assign(5, std::move(m)); break; } case 5: { - RecordVal* m = new RecordVal(hdrType(ip6_mob_brr_type, "ip6_mobility_bu")); + auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_bu")); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Bool(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x8000)); m->Assign(2, val_mgr->Bool(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x4000)); @@ -262,32 +262,32 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const m->Assign(5, val_mgr->Count(ntohs(*((uint16_t*)(msg_data + 2*sizeof(uint16_t)))))); off += 3 * sizeof(uint16_t); m->Assign(6, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(6, m); + msg->Assign(6, std::move(m)); break; } case 6: { - RecordVal* m = new RecordVal(hdrType(ip6_mob_brr_type, "ip6_mobility_back")); + auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_back")); m->Assign(0, val_mgr->Count(*((uint8_t*)msg_data))); m->Assign(1, val_mgr->Bool(*((uint8_t*)(msg_data + sizeof(uint8_t))) & 0x80)); m->Assign(2, val_mgr->Count(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(3, val_mgr->Count(ntohs(*((uint16_t*)(msg_data + 2*sizeof(uint16_t)))))); off += 3 * sizeof(uint16_t); m->Assign(4, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(7, m); + msg->Assign(7, std::move(m)); break; } case 7: { - RecordVal* m = new RecordVal(hdrType(ip6_mob_brr_type, "ip6_mobility_be")); + auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_be")); m->Assign(0, val_mgr->Count(*((uint8_t*)msg_data))); const in6_addr* hoa = (const in6_addr*)(msg_data + sizeof(uint16_t)); m->Assign(1, make_intrusive(IPAddr(*hoa))); off += sizeof(uint16_t) + sizeof(in6_addr); m->Assign(2, BuildOptionsVal(data + off, Length() - off)); - msg->Assign(8, m); + msg->Assign(8, std::move(m)); break; } @@ -403,7 +403,7 @@ IntrusivePtr IP_Hdr::ToPktHdrVal(IntrusivePtr pkt_hdr, int case IPPROTO_TCP: { const struct tcphdr* tp = (const struct tcphdr*) data; - RecordVal* tcp_hdr = new RecordVal(tcp_hdr_type); + auto tcp_hdr = make_intrusive(tcp_hdr_type); int tcp_hdr_len = tp->th_off * 4; int data_len = PayloadLen() - tcp_hdr_len; @@ -418,42 +418,42 @@ IntrusivePtr IP_Hdr::ToPktHdrVal(IntrusivePtr pkt_hdr, int tcp_hdr->Assign(7, val_mgr->Count(tp->th_flags)); tcp_hdr->Assign(8, val_mgr->Count(ntohs(tp->th_win))); - pkt_hdr->Assign(sindex + 2, tcp_hdr); + pkt_hdr->Assign(sindex + 2, std::move(tcp_hdr)); break; } case IPPROTO_UDP: { const struct udphdr* up = (const struct udphdr*) data; - RecordVal* udp_hdr = new RecordVal(udp_hdr_type); + auto udp_hdr = make_intrusive(udp_hdr_type); udp_hdr->Assign(0, val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP)); udp_hdr->Assign(1, val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP)); udp_hdr->Assign(2, val_mgr->Count(ntohs(up->uh_ulen))); - pkt_hdr->Assign(sindex + 3, udp_hdr); + pkt_hdr->Assign(sindex + 3, std::move(udp_hdr)); break; } case IPPROTO_ICMP: { const struct icmp* icmpp = (const struct icmp *) data; - RecordVal* icmp_hdr = new RecordVal(icmp_hdr_type); + auto icmp_hdr = make_intrusive(icmp_hdr_type); icmp_hdr->Assign(0, val_mgr->Count(icmpp->icmp_type)); - pkt_hdr->Assign(sindex + 4, icmp_hdr); + pkt_hdr->Assign(sindex + 4, std::move(icmp_hdr)); break; } case IPPROTO_ICMPV6: { const struct icmp6_hdr* icmpp = (const struct icmp6_hdr*) data; - RecordVal* icmp_hdr = new RecordVal(icmp_hdr_type); + auto icmp_hdr = make_intrusive(icmp_hdr_type); icmp_hdr->Assign(0, val_mgr->Count(icmpp->icmp6_type)); - pkt_hdr->Assign(sindex + 4, icmp_hdr); + pkt_hdr->Assign(sindex + 4, std::move(icmp_hdr)); break; } @@ -713,7 +713,7 @@ IntrusivePtr IPv6_Hdr_Chain::ToVal() const for ( size_t i = 1; i < chain.size(); ++i ) { auto v = chain[i]->ToVal(); - RecordVal* ext_hdr = new RecordVal(ip6_ext_hdr_type); + auto ext_hdr = make_intrusive(ip6_ext_hdr_type); uint8_t type = chain[i]->Type(); ext_hdr->Assign(0, val_mgr->Count(type)); @@ -743,11 +743,10 @@ IntrusivePtr IPv6_Hdr_Chain::ToVal() const #endif default: reporter->InternalWarning("IPv6_Hdr_Chain bad header %d", type); - Unref(ext_hdr); continue; } - rval->Assign(rval->Size(), ext_hdr); + rval->Assign(rval->Size(), std::move(ext_hdr)); } return rval; From 89dd668affc63cca01271475f63833c0b7b7e1f9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 6 May 2020 15:53:52 -0700 Subject: [PATCH 014/151] Change BroType::ShallowClone() to return IntrusivePtr --- src/Type.cc | 30 +++++++++++++++--------------- src/Type.h | 22 ++++++++++++---------- src/Var.cc | 2 +- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/Type.cc b/src/Type.cc index 934d82d926..2b9a79887b 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -69,7 +69,7 @@ BroType::BroType(TypeTag t, bool arg_base_type) { } -BroType* BroType::ShallowClone() +IntrusivePtr BroType::ShallowClone() { switch ( tag ) { case TYPE_VOID: @@ -87,7 +87,7 @@ BroType* BroType::ShallowClone() case TYPE_ADDR: case TYPE_SUBNET: case TYPE_ANY: - return new BroType(tag, base_type); + return make_intrusive(tag, base_type); default: reporter->InternalError("cloning illegal base BroType"); @@ -346,9 +346,9 @@ TableType::TableType(IntrusivePtr ind, IntrusivePtr yield) } } -TableType* TableType::ShallowClone() +IntrusivePtr TableType::ShallowClone() { - return new TableType(indices, yield_type); + return make_intrusive(indices, yield_type); } bool TableType::IsUnspecifiedTable() const @@ -419,9 +419,9 @@ SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements } } -SetType* SetType::ShallowClone() +IntrusivePtr SetType::ShallowClone() { - return new SetType(indices, elements); + return make_intrusive(indices, elements); } SetType::~SetType() = default; @@ -457,9 +457,9 @@ FuncType::FuncType(IntrusivePtr arg_args, prototypes.emplace_back(Prototype{false, args, std::move(offsets)}); } -FuncType* FuncType::ShallowClone() +IntrusivePtr FuncType::ShallowClone() { - auto f = new FuncType(); + auto f = make_intrusive(); f->args = {NewRef{}, args->AsRecordType()}; f->arg_types = {NewRef{}, arg_types->AsTypeList()}; f->yield = yield; @@ -672,12 +672,12 @@ RecordType::RecordType(type_decl_list* arg_types) : BroType(TYPE_RECORD) // in this case the clone is actually not so shallow, since // it gets modified by everyone. -RecordType* RecordType::ShallowClone() +IntrusivePtr RecordType::ShallowClone() { auto pass = new type_decl_list(); for ( const auto& type : *types ) pass->push_back(new TypeDecl(*type)); - return new RecordType(pass); + return make_intrusive(pass); } RecordType::~RecordType() @@ -1128,12 +1128,12 @@ EnumType::EnumType(const EnumType* e) SetName(e->GetName()); } -EnumType* EnumType::ShallowClone() +IntrusivePtr EnumType::ShallowClone() { if ( counter == 0 ) - return new EnumType(GetName()); + return make_intrusive(GetName()); - return new EnumType(this); + return make_intrusive(this); } EnumType::~EnumType() = default; @@ -1356,9 +1356,9 @@ VectorType::VectorType(IntrusivePtr element_type) { } -VectorType* VectorType::ShallowClone() +IntrusivePtr VectorType::ShallowClone() { - return new VectorType(yield_type); + return make_intrusive(yield_type); } VectorType::~VectorType() = default; diff --git a/src/Type.h b/src/Type.h index daa6a7fb13..7c509fae7c 100644 --- a/src/Type.h +++ b/src/Type.h @@ -151,7 +151,7 @@ public: // Clone operations will mostly be implemented in the derived classes; // in addition cloning will be limited to classes that can be reached by // the script-level. - virtual BroType* ShallowClone(); + virtual IntrusivePtr ShallowClone(); TypeTag Tag() const { return tag; } InternalTypeTag InternalType() const { return internal_tag; } @@ -415,7 +415,7 @@ class TableType : public IndexType { public: TableType(IntrusivePtr ind, IntrusivePtr yield); - TableType* ShallowClone() override; + IntrusivePtr ShallowClone() override; // Returns true if this table type is "unspecified", which is // what one gets using an empty "set()" or "table()" constructor. @@ -430,7 +430,7 @@ public: SetType(IntrusivePtr ind, IntrusivePtr arg_elements); ~SetType() override; - SetType* ShallowClone() override; + IntrusivePtr ShallowClone() override; ListExpr* SetElements() const { return elements.get(); } @@ -453,7 +453,7 @@ public: FuncType(IntrusivePtr args, IntrusivePtr yield, function_flavor f); - FuncType* ShallowClone() override; + IntrusivePtr ShallowClone() override; ~FuncType() override; @@ -493,6 +493,8 @@ public: { return prototypes; } protected: + friend IntrusivePtr make_intrusive(); + FuncType() : BroType(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; } IntrusivePtr args; IntrusivePtr arg_types; @@ -504,7 +506,7 @@ protected: class TypeType final : public BroType { public: explicit TypeType(IntrusivePtr t) : BroType(TYPE_TYPE), type(std::move(t)) {} - TypeType* ShallowClone() override { return new TypeType(type); } + IntrusivePtr ShallowClone() override { return make_intrusive(type); } BroType* Type() { return type.get(); } const BroType* Type() const { return type.get(); } @@ -534,7 +536,7 @@ typedef PList type_decl_list; class RecordType final : public BroType { public: explicit RecordType(type_decl_list* types); - RecordType* ShallowClone() override; + IntrusivePtr ShallowClone() override; ~RecordType() override; @@ -604,7 +606,7 @@ public: class FileType final : public BroType { public: explicit FileType(IntrusivePtr yield_type); - FileType* ShallowClone() override { return new FileType(yield); } + IntrusivePtr ShallowClone() override { return make_intrusive(yield); } ~FileType() override; BroType* YieldType() override; @@ -618,7 +620,7 @@ protected: class OpaqueType final : public BroType { public: explicit OpaqueType(const std::string& name); - OpaqueType* ShallowClone() override { return new OpaqueType(name); } + IntrusivePtr ShallowClone() override { return make_intrusive(name); } ~OpaqueType() override { }; const std::string& Name() const { return name; } @@ -638,7 +640,7 @@ public: explicit EnumType(const EnumType* e); explicit EnumType(const std::string& arg_name); - EnumType* ShallowClone() override; + IntrusivePtr ShallowClone() override; ~EnumType() override; // The value of this name is next internal counter value, starting @@ -688,7 +690,7 @@ protected: class VectorType final : public BroType { public: explicit VectorType(IntrusivePtr t); - VectorType* ShallowClone() override; + IntrusivePtr ShallowClone() override; ~VectorType() override; BroType* YieldType() override; const BroType* YieldType() const override; diff --git a/src/Var.cc b/src/Var.cc index 54837ae8c3..8fc1214755 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -363,7 +363,7 @@ void add_type(ID* id, IntrusivePtr t, attr_list* attr) tnew = std::move(t); else // Clone the type to preserve type name aliasing. - tnew = {AdoptRef{}, t->ShallowClone()}; + tnew = t->ShallowClone(); BroType::AddAlias(new_type_name, tnew.get()); From f512ae023e5af37f1868f7b97bc832ab2ee57290 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 6 May 2020 16:43:25 -0700 Subject: [PATCH 015/151] Remove two superfluous IntrusivePtr NewRefs in Type.cc --- src/Type.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Type.cc b/src/Type.cc index 2b9a79887b..85600e349d 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -460,8 +460,8 @@ FuncType::FuncType(IntrusivePtr arg_args, IntrusivePtr FuncType::ShallowClone() { auto f = make_intrusive(); - f->args = {NewRef{}, args->AsRecordType()}; - f->arg_types = {NewRef{}, arg_types->AsTypeList()}; + f->args = args; + f->arg_types = arg_types; f->yield = yield; f->flavor = flavor; f->prototypes = prototypes; From c6f2e35af02f80e071662dc42b64776723d5f501 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 6 May 2020 16:45:01 -0700 Subject: [PATCH 016/151] Give make_intrusive() access to protected EnumVal ctor --- src/Type.cc | 4 ++-- src/Val.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Type.cc b/src/Type.cc index 85600e349d..fd05c82c3e 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1209,7 +1209,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, AddNameInternal(module_name, name, val, is_export); if ( vals.find(val) == vals.end() ) - vals[val] = IntrusivePtr{AdoptRef{}, new EnumVal(this, val)}; + vals[val] = make_intrusive(this, val); set types = BroType::GetAliases(GetName()); set::const_iterator it; @@ -1265,7 +1265,7 @@ IntrusivePtr EnumType::GetVal(bro_int_t i) if ( it == vals.end() ) { - rval = IntrusivePtr{AdoptRef{}, new EnumVal(this, i)}; + rval = make_intrusive(this, i); vals[i] = rval; } else diff --git a/src/Val.h b/src/Val.h index 3aa128c5f6..95a687709c 100644 --- a/src/Val.h +++ b/src/Val.h @@ -998,6 +998,9 @@ protected: friend class Val; friend class EnumType; + template + friend IntrusivePtr make_intrusive(Ts&&... args); + EnumVal(EnumType* t, int i) : Val(bro_int_t(i), t) { } From 6a1e4d61d124ab9955d65a667bc8b6d710aef1f6 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 6 May 2020 17:37:23 -0700 Subject: [PATCH 017/151] Add cast_intrusive() and make use of it in two spots --- src/Expr.cc | 3 +-- src/IntrusivePtr.h | 12 ++++++++++++ src/Type.cc | 9 +++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index bad6240e7d..a7903ad6cc 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2393,8 +2393,7 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) if ( aggr->Type()->Tag() != TYPE_TABLE ) Internal("bad aggregate in AssignExpr::InitVal"); - // TODO: implement safer IntrusivePtr casts - IntrusivePtr tv{NewRef{}, aggr->AsTableVal()}; + auto tv = cast_intrusive(std::move(aggr)); const TableType* tt = tv->Type()->AsTableType(); const BroType* yt = tv->Type()->YieldType(); diff --git a/src/IntrusivePtr.h b/src/IntrusivePtr.h index b6c273a3ff..6f09bd86cd 100644 --- a/src/IntrusivePtr.h +++ b/src/IntrusivePtr.h @@ -184,6 +184,18 @@ IntrusivePtr make_intrusive(Ts&&... args) return {AdoptRef{}, new T(std::forward(args)...)}; } +/** + * Casts an @c IntrusivePtr object to another by way of static_cast on + * the underlying pointer. + * @param p The pointer of type @c U to cast to another type, @c T. + * @return The pointer, as cast to type @c T. + */ +template +IntrusivePtr cast_intrusive(IntrusivePtr p) noexcept + { + return {AdoptRef{}, static_cast(p.release())}; + } + // -- comparison to nullptr ---------------------------------------------------- /** diff --git a/src/Type.cc b/src/Type.cc index fd05c82c3e..a0ed30aa0a 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1892,12 +1892,12 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) const FuncType* ft1 = (const FuncType*) t1; const FuncType* ft2 = (const FuncType*) t1; - auto args = merge_types(ft1->Args(), ft2->Args()); + auto args = cast_intrusive(merge_types(ft1->Args(), ft2->Args())); auto yield = t1->YieldType() ? merge_types(t1->YieldType(), t2->YieldType()) : nullptr; - return make_intrusive(IntrusivePtr{AdoptRef{}, args.release()->AsRecordType()}, - std::move(yield), ft1->Flavor()); + return make_intrusive(std::move(args), std::move(yield), + ft1->Flavor()); } case TYPE_RECORD: @@ -2125,7 +2125,8 @@ IntrusivePtr init_type(Expr* init) t = std::move(tl); } - return make_intrusive(IntrusivePtr{AdoptRef{}, t.release()->AsTypeList()}, nullptr); + return make_intrusive(cast_intrusive(std::move(t)), + nullptr); } bool is_atomic_type(const BroType* t) From 0f59b80d662e1d9ac05620dc49667a357d606885 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 6 May 2020 17:46:15 -0700 Subject: [PATCH 018/151] Remove unused TableType::ExpandRecordIndex() --- src/Type.cc | 14 -------------- src/Type.h | 3 --- 2 files changed, 17 deletions(-) diff --git a/src/Type.cc b/src/Type.cc index a0ed30aa0a..a9b93f0036 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -357,20 +357,6 @@ bool TableType::IsUnspecifiedTable() const return indices->Types()->length() == 0; } -TypeList* TableType::ExpandRecordIndex(RecordType* rt) const - { - TypeList* tl = new TypeList(); - - int n = rt->NumFields(); - for ( int i = 0; i < n; ++i ) - { - TypeDecl* td = rt->FieldDecl(i); - tl->Append(td->type); - } - - return tl; - } - SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements) : TableType(std::move(ind), nullptr), elements(std::move(arg_elements)) { diff --git a/src/Type.h b/src/Type.h index 7c509fae7c..24a3e181b0 100644 --- a/src/Type.h +++ b/src/Type.h @@ -420,9 +420,6 @@ public: // Returns true if this table type is "unspecified", which is // what one gets using an empty "set()" or "table()" constructor. bool IsUnspecifiedTable() const; - -protected: - TypeList* ExpandRecordIndex(RecordType* rt) const; }; class SetType final : public TableType { From 9ab71508839188499c1265fbb7c697c044affdbb Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 6 May 2020 17:56:23 -0700 Subject: [PATCH 019/151] Deprecate SetType::SetElements(), replace with SetType::Elements() --- src/Type.h | 4 ++++ src/Var.cc | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Type.h b/src/Type.h index 24a3e181b0..2b077146e4 100644 --- a/src/Type.h +++ b/src/Type.h @@ -429,8 +429,12 @@ public: IntrusivePtr ShallowClone() override; + [[deprecated("Remove in v4.1. Use Elements() isntead.")]] ListExpr* SetElements() const { return elements.get(); } + const IntrusivePtr& Elements() const + { return elements; } + protected: IntrusivePtr elements; }; diff --git a/src/Var.cc b/src/Var.cc index 8fc1214755..9ca437a5e2 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -162,7 +162,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, if ( t && t->IsSet() ) { // Check for set with explicit elements. SetType* st = t->AsTableType()->AsSetType(); - ListExpr* elements = st->SetElements(); + const auto& elements = st->Elements(); if ( elements ) { @@ -172,7 +172,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, return; } - init = {NewRef{}, elements}; + init = elements; } } From 011866a90856fabe4c679ae875fb58186b07ec82 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 6 May 2020 20:58:40 -0700 Subject: [PATCH 020/151] Deprecate TypeList::PureType(), replace with TypeList::GetPureType() --- src/Expr.cc | 4 ++-- src/Type.cc | 2 +- src/Type.h | 7 +++++++ src/Val.cc | 4 ++-- src/input/Manager.cc | 12 ++++++------ src/input/readers/config/Config.cc | 2 +- src/logging/Manager.cc | 2 +- src/threading/SerialTypes.cc | 2 +- 8 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index a7903ad6cc..527bcb394b 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4528,10 +4528,10 @@ IntrusivePtr ListExpr::InitType() const ti->AsTypeList(); if ( ! til->IsPure() || - ! til->AllMatch(til->PureType(), true) ) + ! til->AllMatch(til->GetPureType(), true) ) tl->Append({NewRef{}, til}); else - tl->Append({NewRef{}, til->PureType()}); + tl->Append(til->GetPureType()); } else tl->Append({NewRef{}, ti}); diff --git a/src/Type.cc b/src/Type.cc index a9b93f0036..14d922f256 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1664,7 +1664,7 @@ const BroType* flatten_type(const BroType* t) const TypeList* tl = t->AsTypeList(); if ( tl->IsPure() ) - return tl->PureType(); + return tl->GetPureType().get(); const type_list* types = tl->Types(); diff --git a/src/Type.h b/src/Type.h index 2b077146e4..eebb27dc12 100644 --- a/src/Type.h +++ b/src/Type.h @@ -362,13 +362,20 @@ public: // Returns the underlying pure type, or nil if the list // is not pure or is empty. + const IntrusivePtr& GetPureType() const + { return pure_type; } + + [[deprecated("Remove in v4.1. Use GetPureType() instead.")]] BroType* PureType() { return pure_type.get(); } + [[deprecated("Remove in v4.1. Use GetPureType() instead.")]] const BroType* PureType() const { return pure_type.get(); } // True if all of the types match t, false otherwise. If // is_init is true, then the matching is done in the context // of an initialization. bool AllMatch(const BroType* t, bool is_init) const; + bool AllMatch(const IntrusivePtr& t, bool is_init) const + { return AllMatch(t.get(), is_init); } void Append(IntrusivePtr t); void AppendEvenIfNotPure(IntrusivePtr t); diff --git a/src/Val.cc b/src/Val.cc index 925a1c4c76..226ea376f0 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1235,8 +1235,8 @@ IntrusivePtr ListVal::ToSetVal() const if ( tag == TYPE_ANY ) Internal("conversion of heterogeneous list to set"); - auto set_index = make_intrusive( - IntrusivePtr{NewRef{}, type->AsTypeList()->PureType()}); + const auto& pt = type->AsTypeList()->GetPureType(); + auto set_index = make_intrusive(pt); set_index->Append(base_type(tag)); auto s = make_intrusive(std::move(set_index), nullptr); auto t = make_intrusive(std::move(s)); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 250b790893..fedac9fcbe 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -812,7 +812,7 @@ bool Manager::IsCompatibleType(BroType* t, bool atomic_only) if ( ! t->IsSet() ) return false; - return IsCompatibleType(t->AsSetType()->Indices()->PureType(), true); + return IsCompatibleType(t->AsSetType()->Indices()->GetPureType().get(), true); } case TYPE_VECTOR: @@ -941,7 +941,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, bool optional = false; if ( ty == TYPE_TABLE ) - st = rec->FieldType(i)->AsSetType()->Indices()->PureType()->Tag(); + st = rec->FieldType(i)->AsSetType()->Indices()->GetPureType()->Tag(); else if ( ty == TYPE_VECTOR ) st = rec->FieldType(i)->AsVectorType()->YieldType()->Tag(); @@ -2334,14 +2334,14 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ case TYPE_TABLE: { // all entries have to have the same type... - BroType* type = request_type->AsTableType()->Indices()->PureType(); - auto set_index = make_intrusive(IntrusivePtr{NewRef{}, type}); - set_index->Append({NewRef{}, type}); + const auto& type = request_type->AsTableType()->Indices()->GetPureType(); + auto set_index = make_intrusive(type); + set_index->Append(type); auto s = make_intrusive(std::move(set_index), nullptr); TableVal* t = new TableVal(std::move(s)); for ( int j = 0; j < val->val.set_val.size; j++ ) { - Val* assignval = ValueToVal(i, val->val.set_val.vals[j], type, have_error); + Val* assignval = ValueToVal(i, val->val.set_val.vals[j], type.get(), have_error); t->Assign(assignval, nullptr); Unref(assignval); // index is not consumed by assign. diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index f31226a69b..22433453fe 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -45,7 +45,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) TypeTag primary = id->Type()->Tag(); TypeTag secondary = TYPE_VOID; if ( primary == TYPE_TABLE ) - secondary = id->Type()->AsSetType()->Indices()->PureType()->Tag(); + secondary = id->Type()->AsSetType()->Indices()->GetPureType()->Tag(); else if ( primary == TYPE_VECTOR ) secondary = id->Type()->AsVectorType()->YieldType()->Tag(); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index a09c0fa0d4..8bb3ab1ce7 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -517,7 +517,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, TypeTag st = TYPE_VOID; if ( t->Tag() == TYPE_TABLE ) - st = t->AsSetType()->Indices()->PureType()->Tag(); + st = t->AsSetType()->Indices()->GetPureType()->Tag(); else if ( t->Tag() == TYPE_VECTOR ) st = t->AsVectorType()->YieldType()->Tag(); diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index a115c37351..2d39fecf51 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -146,7 +146,7 @@ bool Value::IsCompatibleType(BroType* t, bool atomic_only) if ( ! t->IsSet() ) return false; - return IsCompatibleType(t->AsSetType()->Indices()->PureType(), true); + return IsCompatibleType(t->AsSetType()->Indices()->GetPureType().get(), true); } case TYPE_VECTOR: From 455fc29b1ab37fcd8a6d80b09644f05cb0f4e1f8 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 6 May 2020 23:12:47 -0700 Subject: [PATCH 021/151] Migrate TypeList to store IntrusivePtrs This changes return types of TypeList::Types() and IndexType::IndexTypes() to return std::vector instead of type_list* --- NEWS | 3 + src/Attr.cc | 31 +++---- src/CompHash.cc | 30 +++---- src/Expr.cc | 40 ++++----- src/Stmt.cc | 19 ++-- src/Type.cc | 189 +++++++++++++++++++++------------------ src/Type.h | 15 ++-- src/Val.cc | 23 +++-- src/broker/Data.cc | 52 +++++------ src/broker/Manager.cc | 16 ++-- src/broker/messaging.bif | 6 +- src/input/Manager.cc | 67 +++++++------- src/logging/Manager.cc | 6 +- src/option.bif | 22 ++--- 14 files changed, 271 insertions(+), 248 deletions(-) diff --git a/NEWS b/NEWS index ee26a55cba..6d4804b629 100644 --- a/NEWS +++ b/NEWS @@ -86,6 +86,9 @@ Changed Functionality - The DCE/RPC operation string of "NetrLogonSamLogonWithFlags" has been corrected from "NetrLogonSameLogonWithFlags". +- ``TypeList::Types()`` and ``IndexType::IndexTypes()`` now return an + ``std::vector`` instead of ``type_list*`` + Removed Functionality --------------------- diff --git a/src/Attr.cc b/src/Attr.cc index 49cbecfcba..6480f19ce6 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -464,20 +464,21 @@ void Attributes::CheckAttr(Attr* a) if (the_table->IsUnspecifiedTable()) break; - const type_list* func_index_types = e_ft->ArgTypes()->Types(); + const auto& func_index_types = e_ft->ArgTypes()->Types(); // Keep backwards compatibility with idx: any idiom. - if ( func_index_types->length() == 2 ) + if ( func_index_types.size() == 2 ) { - if ((*func_index_types)[1]->Tag() == TYPE_ANY) + if (func_index_types[1]->Tag() == TYPE_ANY) break; } - const type_list* table_index_types = the_table->IndexTypes(); + const auto& table_index_types = the_table->IndexTypes(); - type_list expected_args; + type_list expected_args(1 + static_cast(table_index_types.size())); expected_args.push_back(type->AsTableType()); - for (const auto& t : *table_index_types) - expected_args.push_back(t); + + for ( const auto& t : table_index_types ) + expected_args.push_back(t.get()); if ( ! e_ft->CheckArgs(&expected_args) ) Error("&expire_func argument type clash"); @@ -510,30 +511,30 @@ void Attributes::CheckAttr(Attr* a) if ( the_table->IsUnspecifiedTable() ) break; - const type_list* args = c_ft->ArgTypes()->Types(); - const type_list* t_indexes = the_table->IndexTypes(); - if ( args->length() != ( type->IsSet() ? 2 : 3 ) + t_indexes->length() ) + const auto& args = c_ft->ArgTypes()->Types(); + const auto& t_indexes = the_table->IndexTypes(); + if ( args.size() != ( type->IsSet() ? 2 : 3 ) + t_indexes.size() ) { Error("&on_change function has incorrect number of arguments"); break; } - if ( ! same_type((*args)[0], the_table->AsTableType()) ) + if ( ! same_type(args[0].get(), the_table->AsTableType()) ) { Error("&on_change: first argument must be of same type as table"); break; } // can't check exact type here yet - the data structures don't exist yet. - if ( (*args)[1]->Tag() != TYPE_ENUM ) + if ( args[1]->Tag() != TYPE_ENUM ) { Error("&on_change: second argument must be a TableChange enum"); break; } - for ( int i = 0; i < t_indexes->length(); i++ ) + for ( size_t i = 0; i < t_indexes.size(); i++ ) { - if ( ! same_type((*args)[2+i], (*t_indexes)[i]) ) + if ( ! same_type(args[2+i].get(), t_indexes[i].get()) ) { Error("&on_change: index types do not match table"); break; @@ -541,7 +542,7 @@ void Attributes::CheckAttr(Attr* a) } if ( ! type->IsSet() ) - if ( ! same_type((*args)[2+t_indexes->length()], the_table->YieldType()) ) + if ( ! same_type(args[2+t_indexes.size()].get(), the_table->YieldType()) ) { Error("&on_change: value type does not match table"); break; diff --git a/src/CompHash.cc b/src/CompHash.cc index 749dda19ab..01decb854d 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -21,9 +21,9 @@ CompositeHash::CompositeHash(IntrusivePtr composite_type) // If the only element is a record, don't treat it as a // singleton, since it needs to be evaluated specially. - if ( type->Types()->length() == 1 ) + if ( type->Types().size() == 1 ) { - if ( (*type->Types())[0]->Tag() == TYPE_RECORD ) + if ( type->Types()[0]->Tag() == TYPE_RECORD ) { is_complex_type = true; is_singleton = false; @@ -45,7 +45,7 @@ CompositeHash::CompositeHash(IntrusivePtr composite_type) { // Don't do any further key computations - we'll do them // via the singleton later. - singleton_tag = (*type->Types())[0]->InternalType(); + singleton_tag = type->Types()[0]->InternalType(); size = 0; key = nullptr; } @@ -366,20 +366,20 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const type_check = false; // no need to type-check again. } - const type_list* tl = type->Types(); + const auto& tl = type->Types(); if ( type_check && v->Type()->Tag() != TYPE_LIST ) return nullptr; auto lv = v->AsListVal(); - if ( type_check && lv->Length() != tl->length() ) + if ( type_check && lv->Length() != static_cast(tl.size()) ) return nullptr; char* kp = k; - loop_over_list(*tl, i) + for ( auto i = 0u; i < tl.size(); ++i ) { - kp = SingleValHash(type_check, kp, (*tl)[i], lv->Idx(i).get(), false); + kp = SingleValHash(type_check, kp, tl[i].get(), lv->Idx(i).get(), false); if ( ! kp ) return nullptr; } @@ -624,7 +624,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_static_size) const { - const type_list* tl = type->Types(); + const auto& tl = type->Types(); if ( v ) { @@ -633,14 +633,14 @@ int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_stati auto lv = v->AsListVal(); - if ( type_check && lv->Length() != tl->length() ) + if ( type_check && lv->Length() != static_cast(tl.size()) ) return 0; } int sz = 0; - loop_over_list(*tl, i) + for ( auto i = 0u; i < tl.size(); ++i ) { - sz = SingleTypeKeySize((*tl)[i], v ? v->AsListVal()->Idx(i).get() : nullptr, + sz = SingleTypeKeySize(tl[i].get(), v ? v->AsListVal()->Idx(i).get() : nullptr, type_check, sz, false, calc_static_size); if ( ! sz ) return 0; @@ -711,14 +711,14 @@ int CompositeHash::SizeAlign(int offset, unsigned int size) const IntrusivePtr CompositeHash::RecoverVals(const HashKey* k) const { auto l = make_intrusive(TYPE_ANY); - const type_list* tl = type->Types(); + const auto& tl = type->Types(); const char* kp = (const char*) k->Key(); const char* const k_end = kp + k->Size(); - for ( const auto& type : *tl ) + for ( const auto& type : tl ) { IntrusivePtr v; - kp = RecoverOneVal(k, kp, k_end, type, &v, false); + kp = RecoverOneVal(k, kp, k_end, type.get(), &v, false); ASSERT(v); l->Append(std::move(v)); } @@ -1008,7 +1008,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, for ( int i = 0; i < n; ++i ) { IntrusivePtr v; - BroType* it = (*tl->Types())[i]; + BroType* it = tl->Types()[i].get(); kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false); lv->Append(std::move(v)); } diff --git a/src/Expr.cc b/src/Expr.cc index 527bcb394b..bad027f368 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3103,7 +3103,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; - type_list* indices = type->AsTableType()->Indices()->Types(); + const auto& indices = type->AsTableType()->Indices()->Types(); const expr_list& cle = op->AsListExpr()->Exprs(); // check and promote all index expressions in ctor list @@ -3119,14 +3119,14 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li expr_list& idx_exprs = idx_expr->AsListExpr()->Exprs(); - if ( idx_exprs.length() != indices->length() ) + if ( idx_exprs.length() != static_cast(indices.size()) ) continue; loop_over_list(idx_exprs, j) { Expr* idx = idx_exprs[j]; - auto promoted_idx = check_and_promote_expr(idx, (*indices)[j]); + auto promoted_idx = check_and_promote_expr(idx, indices[j].get()); if ( promoted_idx ) { @@ -3221,17 +3221,17 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; - type_list* indices = type->AsTableType()->Indices()->Types(); + const auto& indices = type->AsTableType()->Indices()->Types(); expr_list& cle = op->AsListExpr()->Exprs(); - if ( indices->length() == 1 ) + if ( indices.size() == 1 ) { if ( ! check_and_promote_exprs_to_type(op->AsListExpr(), - (*indices)[0]) ) + indices[0].get()) ) ExprError("inconsistent type in set constructor"); } - else if ( indices->length() > 1 ) + else if ( indices.size() > 1 ) { // Check/promote each expression in composite index. loop_over_list(cle, i) @@ -4555,9 +4555,9 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co if ( ! aggr && type->AsTypeList()->AllMatch(t, true) ) { auto v = make_intrusive(TYPE_ANY); - const type_list* tl = type->AsTypeList()->Types(); + const auto& tl = type->AsTypeList()->Types(); - if ( exprs.length() != tl->length() ) + if ( exprs.length() != static_cast(tl.size()) ) { Error("index mismatch", t); return nullptr; @@ -4565,7 +4565,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co loop_over_list(exprs, i) { - auto vi = exprs[i]->InitVal((*tl)[i], nullptr); + auto vi = exprs[i]->InitVal(tl[i].get(), nullptr); if ( ! vi ) return nullptr; @@ -4583,9 +4583,9 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co return nullptr; } - const type_list* tl = t->AsTypeList()->Types(); + const auto& tl = t->AsTypeList()->Types(); - if ( exprs.length() != tl->length() ) + if ( exprs.length() != static_cast(tl.size()) ) { Error("index mismatch", t); return nullptr; @@ -4595,7 +4595,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co loop_over_list(exprs, i) { - auto vi = exprs[i]->InitVal((*tl)[i], nullptr); + auto vi = exprs[i]->InitVal(tl[i].get(), nullptr); if ( ! vi ) return nullptr; @@ -4703,7 +4703,7 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) else if ( expr->Type()->Tag() == TYPE_LIST ) element = expr->InitVal(it, nullptr); else - element = expr->InitVal((*it->Types())[0], nullptr); + element = expr->InitVal(it->Types()[0].get(), nullptr); if ( ! element ) return nullptr; @@ -4725,7 +4725,7 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) if ( expr->Type()->Tag() == TYPE_LIST ) element = check_and_promote(std::move(element), it, true); else - element = check_and_promote(std::move(element), (*it->Types())[0], true); + element = check_and_promote(std::move(element), it->Types()[0].get(), true); if ( ! element ) return nullptr; @@ -5013,12 +5013,12 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) bool check_and_promote_exprs(ListExpr* const elements, TypeList* types) { expr_list& el = elements->Exprs(); - const type_list* tl = types->Types(); + const auto& tl = types->Types(); - if ( tl->length() == 1 && (*tl)[0]->Tag() == TYPE_ANY ) + if ( tl.size() == 1 && tl[0]->Tag() == TYPE_ANY ) return true; - if ( el.length() != tl->length() ) + if ( el.length() != static_cast(tl.size()) ) { types->Error("indexing mismatch", elements); return false; @@ -5027,11 +5027,11 @@ bool check_and_promote_exprs(ListExpr* const elements, TypeList* types) loop_over_list(el, i) { Expr* e = el[i]; - auto promoted_e = check_and_promote_expr(e, (*tl)[i]); + auto promoted_e = check_and_promote_expr(e, tl[i].get()); if ( ! promoted_e ) { - e->Error("type mismatch", (*tl)[i]); + e->Error("type mismatch", tl[i].get()); return false; } diff --git a/src/Stmt.cc b/src/Stmt.cc index fdb4b96c4b..b778e93ab1 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1069,28 +1069,29 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) if ( e->Type()->Tag() == TYPE_TABLE ) { - const type_list* indices = e->Type()->AsTableType()->IndexTypes(); - if ( indices->length() != loop_vars->length() ) + const auto& indices = e->Type()->AsTableType()->IndexTypes(); + + if ( static_cast(indices.size()) != loop_vars->length() ) { e->Error("wrong index size"); return; } - for ( int i = 0; i < indices->length(); i++ ) + for ( auto i = 0u; i < indices.size(); i++ ) { - BroType* ind_type = (*indices)[i]->Ref(); + const auto& ind_type = indices[i]; if ( (*loop_vars)[i]->Type() ) { - if ( ! same_type((*loop_vars)[i]->Type(), ind_type) ) - (*loop_vars)[i]->Type()->Error("type clash in iteration", ind_type); + if ( ! same_type((*loop_vars)[i]->Type(), ind_type.get()) ) + (*loop_vars)[i]->Type()->Error("type clash in iteration", + ind_type.get()); } else { - add_local({NewRef{}, (*loop_vars)[i]}, - {NewRef{}, ind_type}, INIT_NONE, - nullptr, nullptr, VAR_REGULAR); + add_local({NewRef{}, (*loop_vars)[i]}, ind_type, INIT_NONE, + nullptr, nullptr, VAR_REGULAR); } } } diff --git a/src/Type.cc b/src/Type.cc index 14d922f256..be28490d91 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -153,16 +153,10 @@ unsigned int BroType::MemoryAllocation() const return padded_sizeof(*this); } -TypeList::~TypeList() - { - for ( const auto& type : types ) - Unref(type); - } - bool TypeList::AllMatch(const BroType* t, bool is_init) const { for ( const auto& type : types ) - if ( ! same_type(type, t, is_init) ) + if ( ! same_type(type.get(), t, is_init) ) return false; return true; } @@ -172,7 +166,7 @@ void TypeList::Append(IntrusivePtr t) if ( pure_type && ! same_type(t.get(), pure_type.get()) ) reporter->InternalError("pure type-list violation"); - types.push_back(t.release()); + types.emplace_back(std::move(t)); } void TypeList::AppendEvenIfNotPure(IntrusivePtr t) @@ -180,7 +174,7 @@ void TypeList::AppendEvenIfNotPure(IntrusivePtr t) if ( pure_type && ! same_type(t.get(), pure_type.get()) ) pure_type = nullptr; - types.push_back(t.release()); + types.emplace_back(std::move(t)); } void TypeList::Describe(ODesc* d) const @@ -193,14 +187,14 @@ void TypeList::Describe(ODesc* d) const d->Add(IsPure()); if ( IsPure() ) pure_type->Describe(d); - d->Add(types.length()); + d->Add(static_cast(types.size())); } if ( IsPure() ) pure_type->Describe(d); else { - loop_over_list(types, i) + for ( size_t i = 0; i < types.size(); ++i ) { if ( i > 0 && ! d->IsBinary() ) d->Add(","); @@ -212,9 +206,16 @@ void TypeList::Describe(ODesc* d) const unsigned int TypeList::MemoryAllocation() const { + unsigned int size = 0; + + for ( const auto& t : types ) + size += t->MemoryAllocation(); + + size += pad_size(types.capacity() * sizeof(decltype(types)::value_type)); + return BroType::MemoryAllocation() + padded_sizeof(*this) - padded_sizeof(BroType) - + types.MemoryAllocation() - padded_sizeof(types); + + size; } IndexType::~IndexType() = default; @@ -222,10 +223,10 @@ IndexType::~IndexType() = default; int IndexType::MatchesIndex(ListExpr* const index) const { // If we have a type indexed by subnets, addresses are ok. - const type_list* types = indices->Types(); + const auto& types = indices->Types(); const expr_list& exprs = index->Exprs(); - if ( types->length() == 1 && (*types)[0]->Tag() == TYPE_SUBNET && + if ( types.size() == 1 && types[0]->Tag() == TYPE_SUBNET && exprs.length() == 1 && exprs[0]->Type()->Tag() == TYPE_ADDR ) return MATCHES_INDEX_SCALAR; @@ -248,11 +249,14 @@ void IndexType::Describe(ODesc* d) const BroType::Describe(d); if ( ! d->IsBinary() ) d->Add("["); - loop_over_list(*IndexTypes(), i) + + const auto& its = IndexTypes(); + + for ( auto i = 0u; i < its.size(); ++i ) { if ( ! d->IsBinary() && i > 0 ) d->Add(","); - (*IndexTypes())[i]->Describe(d); + its[i]->Describe(d); } if ( ! d->IsBinary() ) d->Add("]"); @@ -277,12 +281,14 @@ void IndexType::DescribeReST(ODesc* d, bool roles_only) const d->Add("` "); d->Add("["); - loop_over_list(*IndexTypes(), i) + const auto& its = IndexTypes(); + + for ( auto i = 0u; i < its.size(); ++i ) { if ( i > 0 ) d->Add(", "); - const BroType* t = (*IndexTypes())[i]; + const auto& t = its[i]; if ( ! t->GetName().empty() ) { @@ -313,8 +319,8 @@ void IndexType::DescribeReST(ODesc* d, bool roles_only) const bool IndexType::IsSubNetIndex() const { - const type_list* types = indices->Types(); - if ( types->length() == 1 && (*types)[0]->Tag() == TYPE_SUBNET ) + const auto& types = indices->Types(); + if ( types.size() == 1 && types[0]->Tag() == TYPE_SUBNET ) return true; return false; } @@ -325,9 +331,9 @@ TableType::TableType(IntrusivePtr ind, IntrusivePtr yield) if ( ! indices ) return; - type_list* tl = indices->Types(); + const auto& tl = indices->Types(); - for ( const auto& tli : *tl ) + for ( const auto& tli : tl ) { InternalTypeTag t = tli->InternalType(); @@ -354,7 +360,7 @@ IntrusivePtr TableType::ShallowClone() bool TableType::IsUnspecifiedTable() const { // Unspecified types have an empty list of indices. - return indices->Types()->length() == 0; + return indices->Types().empty(); } SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements) @@ -370,27 +376,27 @@ SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements else { TypeList* tl_type = elements->Type()->AsTypeList(); - type_list* tl = tl_type->Types(); + const auto& tl = tl_type->Types(); - if ( tl->length() < 1 ) + if ( tl.size() < 1 ) { Error("no type given for set"); SetError(); } - else if ( tl->length() == 1 ) + else if ( tl.size() == 1 ) { - IntrusivePtr ft{NewRef{}, flatten_type((*tl)[0])}; + IntrusivePtr ft{NewRef{}, flatten_type(tl[0].get())}; indices = make_intrusive(ft); indices->Append(std::move(ft)); } else { - auto t = merge_types((*tl)[0], (*tl)[1]); + auto t = merge_types(tl[0].get(), tl[1].get()); - for ( int i = 2; t && i < tl->length(); ++i ) - t = merge_types(t.get(), (*tl)[i]); + for ( size_t i = 2; t && i < tl.size(); ++i ) + t = merge_types(t.get(), tl[i].get()); if ( ! t ) { @@ -493,22 +499,34 @@ int FuncType::MatchesIndex(ListExpr* const index) const bool FuncType::CheckArgs(const type_list* args, bool is_init) const { - const type_list* my_args = arg_types->Types(); + std::vector> as; + as.reserve(args->length()); - if ( my_args->length() != args->length() ) + for ( auto a : *args ) + as.emplace_back(NewRef{}, a); + + return CheckArgs(as, is_init); + } + +bool FuncType::CheckArgs(const std::vector>& args, + bool is_init) const + { + const auto& my_args = arg_types->Types(); + + if ( my_args.size() != args.size() ) { - Warn(fmt("Wrong number of arguments for function. Expected %d, got %d.", - args->length(), my_args->length())); + Warn(fmt("Wrong number of arguments for function. Expected %zu, got %zu.", + args.size(), my_args.size())); return false; } bool success = true; - for ( int i = 0; i < my_args->length(); ++i ) - if ( ! same_type((*args)[i], (*my_args)[i], is_init) ) + for ( size_t i = 0; i < my_args.size(); ++i ) + if ( ! same_type(args[i].get(), my_args[i].get(), is_init) ) { - Warn(fmt("Type mismatch in function argument #%d. Expected %s, got %s.", - i, type_name((*args)[i]->Tag()), type_name((*my_args)[i]->Tag()))); + Warn(fmt("Type mismatch in function argument #%zu. Expected %s, got %s.", + i, type_name(args[i]->Tag()), type_name(my_args[i]->Tag()))); success = false; } @@ -785,12 +803,14 @@ static string container_type_name(const BroType* ft) s = "set["; else s = "table["; - const type_list* tl = ((const IndexType*) ft)->IndexTypes(); - loop_over_list(*tl, i) + + const auto& tl = ((const IndexType*) ft)->IndexTypes(); + + for ( auto i = 0u; i < tl.size(); ++i ) { if ( i > 0 ) s += ","; - s += container_type_name((*tl)[i]); + s += container_type_name(tl[i].get()); } s += "]"; if ( ft->YieldType() ) @@ -1576,14 +1596,14 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re case TYPE_LIST: { - const type_list* tl1 = t1->AsTypeList()->Types(); - const type_list* tl2 = t2->AsTypeList()->Types(); + const auto& tl1 = t1->AsTypeList()->Types(); + const auto& tl2 = t2->AsTypeList()->Types(); - if ( tl1->length() != tl2->length() ) + if ( tl1.size() != tl2.size() ) return false; - loop_over_list(*tl1, i) - if ( ! same_type((*tl1)[i], (*tl2)[i], is_init, match_record_field_names) ) + for ( auto i = 0u; i < tl1.size(); ++i ) + if ( ! same_type(tl1[i].get(), tl2[i].get(), is_init, match_record_field_names) ) return false; return true; @@ -1666,14 +1686,15 @@ const BroType* flatten_type(const BroType* t) if ( tl->IsPure() ) return tl->GetPureType().get(); - const type_list* types = tl->Types(); + const auto& types = tl->Types(); - if ( types->length() == 0 ) + if ( types.size() == 0 ) reporter->InternalError("empty type list in flatten_type"); - const BroType* ft = (*types)[0]; - if ( types->length() == 1 || tl->AllMatch(ft, false) ) - return ft; + const auto& ft = types[0]; + + if ( types.size() == 1 || tl->AllMatch(ft, false) ) + return ft.get(); return t; } @@ -1821,28 +1842,25 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) const IndexType* it1 = (const IndexType*) t1; const IndexType* it2 = (const IndexType*) t2; - const type_list* tl1 = it1->IndexTypes(); - const type_list* tl2 = it2->IndexTypes(); + const auto& tl1 = it1->IndexTypes(); + const auto& tl2 = it2->IndexTypes(); IntrusivePtr tl3; - if ( tl1 || tl2 ) + if ( tl1.size() != tl2.size() ) { - if ( ! tl1 || ! tl2 || tl1->length() != tl2->length() ) - { - t1->Error("incompatible types", t2); + t1->Error("incompatible types", t2); + return nullptr; + } + + tl3 = make_intrusive(); + + for ( auto i = 0u; i < tl1.size(); ++i ) + { + auto tl3_i = merge_types(tl1[i].get(), tl2[i].get()); + if ( ! tl3_i ) return nullptr; - } - tl3 = make_intrusive(); - - loop_over_list(*tl1, i) - { - auto tl3_i = merge_types((*tl1)[i], (*tl2)[i]); - if ( ! tl3_i ) - return nullptr; - - tl3->Append(std::move(tl3_i)); - } + tl3->Append(std::move(tl3_i)); } const BroType* y1 = t1->YieldType(); @@ -1926,12 +1944,12 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) return nullptr; } - const type_list* l1 = tl1->Types(); - const type_list* l2 = tl2->Types(); + const auto& l1 = tl1->Types(); + const auto& l2 = tl2->Types(); - if ( l1->length() == 0 || l2->length() == 0 ) + if ( l1.size() == 0 || l2.size() == 0 ) { - if ( l1->length() == 0 ) + if ( l1.size() == 0 ) tl1->Error("empty list"); else tl2->Error("empty list"); @@ -1944,20 +1962,21 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) // the initialization expression into a set of values. // So the merge type of the list is the type of one // of the elements, providing they're consistent. - return merge_types((*l1)[0], (*l2)[0]); + return merge_types(l1[0].get(), l2[0].get()); } // Impure lists - must have the same size and match element // by element. - if ( l1->length() != l2->length() ) + if ( l1.size() != l2.size() ) { tl1->Error("different number of indices", tl2); return nullptr; } auto tl3 = make_intrusive(); - loop_over_list(*l1, i) - tl3->Append(merge_types((*l1)[i], (*l2)[i])); + + for ( auto i = 0u; i < l1.size(); ++i ) + tl3->Append(merge_types(l1[i].get(), l2[i].get())); return tl3; } @@ -1993,21 +2012,21 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) IntrusivePtr merge_type_list(ListExpr* elements) { TypeList* tl_type = elements->Type()->AsTypeList(); - type_list* tl = tl_type->Types(); + const auto& tl = tl_type->Types(); - if ( tl->length() < 1 ) + if ( tl.size() < 1 ) { reporter->Error("no type can be inferred for empty list"); return nullptr; } - IntrusivePtr t{NewRef{}, (*tl)[0]}; + auto t = tl[0]; - if ( tl->length() == 1 ) + if ( tl.size() == 1 ) return t; - for ( int i = 1; t && i < tl->length(); ++i ) - t = merge_types(t.get(), (*tl)[i]); + for ( size_t i = 1; t && i < tl.size(); ++i ) + t = merge_types(t.get(), tl[i].get()); if ( ! t ) reporter->Error("inconsistent types in list"); @@ -2024,8 +2043,8 @@ static BroType* reduce_type(BroType* t) else if ( t->IsSet() ) { TypeList* tl = t->AsTableType()->Indices(); - if ( tl->Types()->length() == 1 ) - return (*tl->Types())[0]; + if ( tl->Types().size() == 1 ) + return tl->Types()[0].get(); else return tl; } @@ -2044,7 +2063,7 @@ IntrusivePtr init_type(Expr* init) return nullptr; if ( t->Tag() == TYPE_LIST && - t->AsTypeList()->Types()->length() != 1 ) + t->AsTypeList()->Types().size() != 1 ) { init->Error("list used in scalar initialization"); return nullptr; diff --git a/src/Type.h b/src/Type.h index eebb27dc12..90a02dedd5 100644 --- a/src/Type.h +++ b/src/Type.h @@ -353,10 +353,8 @@ public: { } - ~TypeList() override; - - const type_list* Types() const { return &types; } - type_list* Types() { return &types; } + const std::vector>& Types() const + { return types; } bool IsPure() const { return pure_type != nullptr; } @@ -386,7 +384,7 @@ public: protected: IntrusivePtr pure_type; - type_list types; + std::vector> types; }; class IndexType : public BroType { @@ -394,7 +392,10 @@ public: int MatchesIndex(ListExpr* index) const override; TypeList* Indices() const { return indices.get(); } - const type_list* IndexTypes() const { return indices->Types(); } + + const std::vector>& IndexTypes() const + { return indices->Types(); } + BroType* YieldType() override; const BroType* YieldType() const override; @@ -478,6 +479,8 @@ public: int MatchesIndex(ListExpr* index) const override; bool CheckArgs(const type_list* args, bool is_init = false) const; + bool CheckArgs(const std::vector>& args, + bool is_init = false) const; TypeList* ArgTypes() const { return arg_types.get(); } diff --git a/src/Val.cc b/src/Val.cc index 226ea376f0..c7a5ccd58a 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -266,7 +266,7 @@ IntrusivePtr Val::SizeVal() const case TYPE_INTERNAL_OTHER: if ( type->Tag() == TYPE_FUNC ) - return val_mgr->Count(val.func_val->FType()->ArgTypes()->Types()->length()); + return val_mgr->Count(val.func_val->FType()->ArgTypes()->Types().size()); if ( type->Tag() == TYPE_FILE ) return make_intrusive(val.file_val->Size(), TYPE_DOUBLE); @@ -1353,8 +1353,8 @@ static void find_nested_record_types(BroType* t, std::set* found) return; case TYPE_LIST: { - for ( auto& type : *t->AsTypeList()->Types() ) - find_nested_record_types(type, found); + for ( const auto& type : t->AsTypeList()->Types() ) + find_nested_record_types(type.get(), found); } return; case TYPE_FUNC: @@ -1380,12 +1380,12 @@ TableVal::TableVal(IntrusivePtr t, IntrusivePtr a) : Val( if ( ! is_parsing ) return; - for ( const auto& t : *table_type->IndexTypes() ) + for ( const auto& t : table_type->IndexTypes() ) { std::set found; // TODO: this likely doesn't have to be repeated for each new TableVal, // can remember the resulting dependencies per TableType - find_nested_record_types(t, &found); + find_nested_record_types(t.get(), &found); for ( auto rt : found ) parse_time_table_record_dependencies[rt].emplace_back(NewRef{}, this); @@ -1766,7 +1766,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) ListVal* iv = index->AsListVal(); if ( iv->BaseTag() != TYPE_ANY ) { - if ( table_type->Indices()->Types()->length() != 1 ) + if ( table_type->Indices()->Types().size() != 1 ) reporter->InternalError("bad singleton list index"); for ( int i = 0; i < iv->Length(); ++i ) @@ -2146,14 +2146,14 @@ ListVal* TableVal::ConvertToList(TypeTag t) const IntrusivePtr TableVal::ToPureListVal() const { - type_list* tl = table_type->Indices()->Types(); - if ( tl->length() != 1 ) + const auto& tl = table_type->Indices()->Types(); + if ( tl.size() != 1 ) { InternalWarning("bad index type in TableVal::ToPureListVal"); return nullptr; } - return ToListVal((*tl)[0]->Tag()); + return ToListVal(tl[0]->Tag()); } ListVal* TableVal::ConvertToPureList() const @@ -2481,10 +2481,9 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) const Func* f = vf->AsFunc(); zeek::Args vl; - const auto func_args = f->FType()->ArgTypes()->Types(); - + const auto& func_args = f->FType()->ArgTypes()->Types(); // backwards compatibility with idx: any idiom - bool any_idiom = func_args->length() == 2 && func_args->back()->Tag() == TYPE_ANY; + bool any_idiom = func_args.size() == 2 && func_args.back()->Tag() == TYPE_ANY; if ( ! any_idiom ) { diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 6324c0339b..ba2105264c 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -212,17 +212,17 @@ struct val_converter { for ( auto& item : a ) { - auto expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->Indices()->Types(); broker::vector composite_key; auto indices = caf::get_if(&item); if ( indices ) { - if ( expected_index_types->length() == 1 ) + if ( expected_index_types.size() == 1 ) { auto index_is_vector_or_record = - (*expected_index_types)[0]->Tag() == TYPE_RECORD || - (*expected_index_types)[0]->Tag() == TYPE_VECTOR; + expected_index_types[0]->Tag() == TYPE_RECORD || + expected_index_types[0]->Tag() == TYPE_VECTOR; if ( index_is_vector_or_record ) { @@ -238,8 +238,7 @@ struct val_converter { indices = &composite_key; } - if ( static_cast(expected_index_types->length()) != - indices->size() ) + if ( expected_index_types.size() != indices->size() ) return nullptr; auto list_val = make_intrusive(TYPE_ANY); @@ -247,7 +246,7 @@ struct val_converter { for ( auto i = 0u; i < indices->size(); ++i ) { auto index_val = bro_broker::data_to_val(move((*indices)[i]), - (*expected_index_types)[i]); + expected_index_types[i].get()); if ( ! index_val ) return nullptr; @@ -272,17 +271,17 @@ struct val_converter { for ( auto& item : a ) { - auto expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->Indices()->Types(); broker::vector composite_key; auto indices = caf::get_if(&item.first); if ( indices ) { - if ( expected_index_types->length() == 1 ) + if ( expected_index_types.size() == 1 ) { auto index_is_vector_or_record = - (*expected_index_types)[0]->Tag() == TYPE_RECORD || - (*expected_index_types)[0]->Tag() == TYPE_VECTOR; + expected_index_types[0]->Tag() == TYPE_RECORD || + expected_index_types[0]->Tag() == TYPE_VECTOR; if ( index_is_vector_or_record ) { @@ -298,8 +297,7 @@ struct val_converter { indices = &composite_key; } - if ( static_cast(expected_index_types->length()) != - indices->size() ) + if ( expected_index_types.size() != indices->size() ) return nullptr; auto list_val = make_intrusive(TYPE_ANY); @@ -307,7 +305,7 @@ struct val_converter { for ( auto i = 0u; i < indices->size(); ++i ) { auto index_val = bro_broker::data_to_val(move((*indices)[i]), - (*expected_index_types)[i]); + expected_index_types[i].get()); if ( ! index_val ) return nullptr; @@ -561,17 +559,17 @@ struct type_checker { for ( const auto& item : a ) { - auto expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->Indices()->Types(); auto indices = caf::get_if(&item); vector indices_to_check; if ( indices ) { - if ( expected_index_types->length() == 1 ) + if ( expected_index_types.size() == 1 ) { auto index_is_vector_or_record = - (*expected_index_types)[0]->Tag() == TYPE_RECORD || - (*expected_index_types)[0]->Tag() == TYPE_VECTOR; + expected_index_types[0]->Tag() == TYPE_RECORD || + expected_index_types[0]->Tag() == TYPE_VECTOR; if ( index_is_vector_or_record ) // Disambiguate from composite key w/ multiple vals. @@ -595,13 +593,12 @@ struct type_checker { else indices_to_check.emplace_back(&item); - if ( static_cast(expected_index_types->length()) != - indices_to_check.size() ) + if ( expected_index_types.size() != indices_to_check.size() ) return false; for ( auto i = 0u; i < indices_to_check.size(); ++i ) { - auto expect = (*expected_index_types)[i]; + auto expect = expected_index_types[i].get(); auto& index_to_check = *(indices_to_check)[i]; if ( ! data_type_check(index_to_check, expect) ) @@ -621,17 +618,17 @@ struct type_checker { for ( auto& item : a ) { - auto expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->Indices()->Types(); auto indices = caf::get_if(&item.first); vector indices_to_check; if ( indices ) { - if ( expected_index_types->length() == 1 ) + if ( expected_index_types.size() == 1 ) { auto index_is_vector_or_record = - (*expected_index_types)[0]->Tag() == TYPE_RECORD || - (*expected_index_types)[0]->Tag() == TYPE_VECTOR; + expected_index_types[0]->Tag() == TYPE_RECORD || + expected_index_types[0]->Tag() == TYPE_VECTOR; if ( index_is_vector_or_record ) // Disambiguate from composite key w/ multiple vals. @@ -656,15 +653,14 @@ struct type_checker { indices_to_check.emplace_back(&item.first); - if ( static_cast(expected_index_types->length()) != - indices_to_check.size() ) + if ( expected_index_types.size() != indices_to_check.size() ) { return false; } for ( auto i = 0u; i < indices_to_check.size(); ++i ) { - auto expect = (*expected_index_types)[i]; + auto expect = expected_index_types[i].get(); auto& index_to_check = *(indices_to_check)[i]; if ( ! data_type_check(index_to_check, expect) ) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index d54b061580..2929e5e168 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -742,9 +742,9 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) } auto got_type = (*args)[i]->Type(); - auto expected_type = (*func->FType()->ArgTypes()->Types())[i - 1]; + const auto& expected_type = func->FType()->ArgTypes()->Types()[i - 1]; - if ( ! same_type(got_type, expected_type) ) + if ( ! same_type(got_type, expected_type.get()) ) { rval->Assign(0, nullptr); Error("event parameter #%d type mismatch, got %s, expect %s", i, @@ -978,13 +978,13 @@ void Manager::ProcessEvent(const broker::topic& topic, broker::zeek::Event ev) return; } - auto arg_types = handler->FType(false)->ArgTypes()->Types(); + const auto& arg_types = handler->FType(false)->ArgTypes()->Types(); - if ( static_cast(arg_types->length()) != args.size() ) + if ( arg_types.size() != args.size() ) { reporter->Warning("got event message '%s' with invalid # of args," - " got %zd, expected %d", name.data(), args.size(), - arg_types->length()); + " got %zd, expected %zu", name.data(), args.size(), + arg_types.size()); return; } @@ -994,8 +994,8 @@ void Manager::ProcessEvent(const broker::topic& topic, broker::zeek::Event ev) for ( auto i = 0u; i < args.size(); ++i ) { auto got_type = args[i].get_type_name(); - auto expected_type = (*arg_types)[i]; - auto val = data_to_val(std::move(args[i]), expected_type); + const auto& expected_type = arg_types[i]; + auto val = data_to_val(std::move(args[i]), expected_type.get()); if ( val ) vl.emplace_back(std::move(val)); diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index fdc0fa848b..c809b013ee 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -12,12 +12,12 @@ static bool is_string_set(const BroType* type) if ( ! type->IsSet() ) return false; - auto index_types = type->AsSetType()->IndexTypes(); + const auto& index_types = type->AsSetType()->IndexTypes(); - if ( index_types->length() != 1 ) + if ( index_types.size() != 1 ) return false; - return (*index_types)[0]->Tag() == TYPE_STRING; + return index_types[0]->Tag() == TYPE_STRING; } std::set val_to_topic_set(Val* val) diff --git a/src/input/Manager.cc b/src/input/Manager.cc index fedac9fcbe..72d53ee14b 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -336,21 +336,21 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - const type_list* args = etype->ArgTypes()->Types(); + const auto& args = etype->ArgTypes()->Types(); - if ( args->length() < 2 ) + if ( args.size() < 2 ) { reporter->Error("Input stream %s: Event does not take enough arguments", stream_name.c_str()); return false; } - if ( ! same_type((*args)[1], BifType::Enum::Input::Event, false) ) + if ( ! same_type(args[1].get(), BifType::Enum::Input::Event, false) ) { reporter->Error("Input stream %s: Event's second attribute must be of type Input::Event", stream_name.c_str()); return false; } - if ( ! same_type((*args)[0], BifType::Record::Input::EventDescription, false) ) + if ( ! same_type(args[0].get(), BifType::Record::Input::EventDescription, false) ) { reporter->Error("Input stream %s: Event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; @@ -358,7 +358,7 @@ bool Manager::CreateEventStream(RecordVal* fval) if ( want_record->InternalInt() == 0 ) { - if ( args->length() != fields->NumFields() + 2 ) + if ( static_cast(args.size()) != fields->NumFields() + 2 ) { reporter->Error("Input stream %s: Event has wrong number of arguments", stream_name.c_str()); return false; @@ -366,17 +366,17 @@ bool Manager::CreateEventStream(RecordVal* fval) for ( int i = 0; i < fields->NumFields(); i++ ) { - if ( ! same_type((*args)[i + 2], fields->FieldType(i) ) ) + if ( ! same_type(args[i + 2].get(), fields->FieldType(i) ) ) { ODesc desc1; ODesc desc2; - (*args)[i + 2]->Describe(&desc1); + args[i + 2]->Describe(&desc1); fields->FieldType(i)->Describe(&desc2); reporter->Error("Input stream %s: Incompatible type for event in field %d. Need type '%s':%s, got '%s':%s", stream_name.c_str(), i + 3, type_name(fields->FieldType(i)->Tag()), desc2.Description(), - type_name((*args)[i + 2]->Tag()), desc1.Description()); + type_name(args[i + 2]->Tag()), desc1.Description()); return false; } @@ -386,21 +386,21 @@ bool Manager::CreateEventStream(RecordVal* fval) else if ( want_record->InternalInt() == 1 ) { - if ( args->length() != 3 ) + if ( args.size() != 3 ) { reporter->Error("Input stream %s: Event has wrong number of arguments", stream_name.c_str()); return false; } - if ( ! same_type((*args)[2], fields ) ) + if ( ! same_type(args[2].get(), fields ) ) { ODesc desc1; ODesc desc2; - (*args)[2]->Describe(&desc1); + args[2]->Describe(&desc1); fields->Describe(&desc2); reporter->Error("Input stream %s: Incompatible type '%s':%s for event, which needs type '%s':%s\n", stream_name.c_str(), - type_name((*args)[2]->Tag()), desc1.Description(), + type_name(args[2]->Tag()), desc1.Description(), type_name(fields->Tag()), desc2.Description()); return false; } @@ -486,9 +486,10 @@ bool Manager::CreateTableStream(RecordVal* fval) // check if index fields match table description int num = idx->NumFields(); - const type_list* tl = dst->Type()->AsTableType()->IndexTypes(); + const auto& tl = dst->Type()->AsTableType()->IndexTypes(); + int j; - loop_over_list(*tl, j) + for ( j = 0; j < static_cast(tl.size()); ++j ) { if ( j >= num ) { @@ -496,16 +497,16 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( ! same_type(idx->FieldType(j), (*tl)[j]) ) + if ( ! same_type(idx->FieldType(j), tl[j].get()) ) { ODesc desc1; ODesc desc2; idx->FieldType(j)->Describe(&desc1); - (*tl)[j]->Describe(&desc2); + tl[j]->Describe(&desc2); reporter->Error("Input stream %s: Table type does not match index type. Need type '%s':%s, got '%s':%s", stream_name.c_str(), type_name(idx->FieldType(j)->Tag()), desc1.Description(), - type_name((*tl)[j]->Tag()), desc2.Description()); + type_name(tl[j]->Tag()), desc2.Description()); return false; } @@ -563,54 +564,54 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - const type_list* args = etype->ArgTypes()->Types(); + const auto& args = etype->ArgTypes()->Types(); - if ( args->length() != 4 ) + if ( args.size() != 4 ) { reporter->Error("Input stream %s: Table event must take 4 arguments", stream_name.c_str()); return false; } - if ( ! same_type((*args)[0], BifType::Record::Input::TableDescription, false) ) + if ( ! same_type(args[0].get(), BifType::Record::Input::TableDescription, false) ) { reporter->Error("Input stream %s: Table event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! same_type((*args)[1], BifType::Enum::Input::Event, false) ) + if ( ! same_type(args[1].get(), BifType::Enum::Input::Event, false) ) { reporter->Error("Input stream %s: Table event's second attribute must be of type Input::Event", stream_name.c_str()); return false; } - if ( ! same_type((*args)[2], idx) ) + if ( ! same_type(args[2].get(), idx) ) { ODesc desc1; ODesc desc2; idx->Describe(&desc1); - (*args)[2]->Describe(&desc2); + args[2]->Describe(&desc2); reporter->Error("Input stream %s: Table event's index attributes do not match. Need '%s', got '%s'", stream_name.c_str(), desc1.Description(), desc2.Description()); return false; } - if ( want_record->InternalInt() == 1 && val && ! same_type((*args)[3], val.get()) ) + if ( want_record->InternalInt() == 1 && val && ! same_type(args[3].get(), val.get()) ) { ODesc desc1; ODesc desc2; val->Describe(&desc1); - (*args)[3]->Describe(&desc2); + args[3]->Describe(&desc2); reporter->Error("Input stream %s: Table event's value attributes do not match. Need '%s', got '%s'", stream_name.c_str(), desc1.Description(), desc2.Description()); return false; } else if ( want_record->InternalInt() == 0 - && val && !same_type((*args)[3], val->FieldType(0) ) ) + && val && !same_type(args[3].get(), val->FieldType(0) ) ) { ODesc desc1; ODesc desc2; val->FieldType(0)->Describe(&desc1); - (*args)[3]->Describe(&desc2); + args[3]->Describe(&desc2); reporter->Error("Input stream %s: Table event's value attribute does not match. Need '%s', got '%s'", stream_name.c_str(), desc1.Description(), desc2.Description()); return false; @@ -710,33 +711,33 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - const type_list* args = etype->ArgTypes()->Types(); + const auto& args = etype->ArgTypes()->Types(); - if ( args->length() != 3 ) + if ( args.size() != 3 ) { reporter->Error("Input stream %s: Error event must take 3 arguments", stream_name.c_str()); return false; } - if ( table && ! same_type((*args)[0], BifType::Record::Input::TableDescription, false) ) + if ( table && ! same_type(args[0].get(), BifType::Record::Input::TableDescription, false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! table && ! same_type((*args)[0], BifType::Record::Input::EventDescription, false) ) + if ( ! table && ! same_type(args[0].get(), BifType::Record::Input::EventDescription, false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; } - if ( (*args)[1]->Tag() != TYPE_STRING ) + if ( args[1]->Tag() != TYPE_STRING ) { reporter->Error("Input stream %s: Error event's second attribute must be of type string", stream_name.c_str()); return false; } - if ( ! same_type((*args)[2], BifType::Enum::Reporter::Level, false) ) + if ( ! same_type(args[2].get(), BifType::Enum::Reporter::Level, false) ) { reporter->Error("Input stream %s: Error event's third attribute must be of type Reporter::Level", stream_name.c_str()); return false; diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 8bb3ab1ce7..23a295238b 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -278,15 +278,15 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) return false; } - const type_list* args = etype->ArgTypes()->Types(); + const auto& args = etype->ArgTypes()->Types(); - if ( args->length() != 1 ) + if ( args.size() != 1 ) { reporter->Error("stream event must take a single argument"); return false; } - if ( ! same_type((*args)[0], columns) ) + if ( ! same_type(args[0].get(), columns) ) { reporter->Error("stream event's argument type does not match column record type"); return false; diff --git a/src/option.bif b/src/option.bif index 49d63bdca7..dd534811a8 100644 --- a/src/option.bif +++ b/src/option.bif @@ -15,7 +15,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, ID* i, { for ( auto handler_function : i->GetOptionHandlers() ) { - bool add_loc = handler_function->FType()->AsFuncType()->ArgTypes()->Types()->length() == 3; + bool add_loc = handler_function->FType()->AsFuncType()->ArgTypes()->Types().size() == 3; zeek::Args vl; vl.reserve(2 + add_loc); vl.emplace_back(NewRef{}, name); @@ -170,32 +170,32 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - const type_list* args = on_change->Type()->AsFuncType()->ArgTypes()->Types(); - if ( args->length() < 2 || args->length() > 3 ) + const auto& args = on_change->Type()->AsFuncType()->ArgTypes()->Types(); + if ( args.size() < 2 || args.size() > 3 ) { - builtin_error(fmt("Wrong number of arguments for passed function in Option::on_change for ID '%s'; expected 2 or 3, got %d", - ID->CheckString(), args->length())); + builtin_error(fmt("Wrong number of arguments for passed function in Option::on_change for ID '%s'; expected 2 or 3, got %zu", + ID->CheckString(), args.size())); return val_mgr->False(); } - if ( (*args)[0]->Tag() != TYPE_STRING ) + if ( args[0]->Tag() != TYPE_STRING ) { builtin_error(fmt("First argument of passed function has to be string in Option::on_change for ID '%s'; got '%s'", - ID->CheckString(), type_name((*args)[0]->Tag()))); + ID->CheckString(), type_name(args[0]->Tag()))); return val_mgr->False(); } - if ( ! same_type((*args)[1], i->Type()) ) + if ( ! same_type(args[1].get(), i->Type()) ) { builtin_error(fmt("Second argument of passed function has to be %s in Option::on_change for ID '%s'; got '%s'", - type_name(i->Type()->Tag()), ID->CheckString(), type_name((*args)[1]->Tag()))); + type_name(i->Type()->Tag()), ID->CheckString(), type_name(args[1]->Tag()))); return val_mgr->False(); } - if ( args->length() == 3 && (*args)[2]->Tag() != TYPE_STRING ) + if ( args.size() == 3 && args[2]->Tag() != TYPE_STRING ) { builtin_error(fmt("Third argument of passed function has to be string in Option::on_change for ID '%s'; got '%s'", - ID->CheckString(), type_name((*args)[2]->Tag()))); + ID->CheckString(), type_name(args[2]->Tag()))); return val_mgr->False(); } From 103fed9f013f0b17023b65f45183ea502e78a285 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 7 May 2020 15:05:43 -0700 Subject: [PATCH 022/151] Deprecate RecordType::FieldType(), replace with GetFieldType() --- NEWS | 2 + src/CompHash.cc | 6 +-- src/EventHandler.cc | 2 +- src/Expr.cc | 20 ++++----- src/ID.cc | 2 +- src/Type.cc | 29 +++++--------- src/Type.h | 28 ++++++++++++- src/Val.cc | 7 ++-- src/Var.cc | 2 +- src/broker/Data.cc | 4 +- src/input/Manager.cc | 78 ++++++++++++++++++------------------ src/logging/Manager.cc | 6 +-- src/supervisor/Supervisor.cc | 8 ++-- 13 files changed, 105 insertions(+), 89 deletions(-) diff --git a/NEWS b/NEWS index 6d4804b629..50d732d707 100644 --- a/NEWS +++ b/NEWS @@ -146,6 +146,8 @@ Deprecated Functionality - The ``utf16_bytestring_to_utf8_val()`` function is deprecated, use ``utf16_to_utf8_val()`` instead. +- ``RecordType::FieldType()`` is deprecated, use ``RecordType::GetFieldType()`` + Zeek 3.1.0 ========== diff --git a/src/CompHash.cc b/src/CompHash.cc index 01decb854d..416ae38208 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -189,7 +189,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, return nullptr; if ( ! (kp = SingleValHash(type_check, kp, - rt->FieldType(i), + rt->GetFieldType(i).get(), rv_i, optional)) ) return nullptr; } @@ -517,7 +517,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, Attributes* a = rt->FieldDecl(i)->attrs.get(); bool optional = (a && a->FindAttr(ATTR_OPTIONAL)); - sz = SingleTypeKeySize(rt->FieldType(i), + sz = SingleTypeKeySize(rt->GetFieldType(i).get(), rv ? rv->Lookup(i) : nullptr, type_check, sz, optional, calc_static_size); @@ -910,7 +910,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, bool optional = (a && a->FindAttr(ATTR_OPTIONAL)); kp = RecoverOneVal(k, kp, k_end, - rt->FieldType(i), &v, optional); + rt->GetFieldType(i).get(), &v, optional); // An earlier call to reporter->InternalError would have called abort() and broken the // call tree that clang-tidy is relying on to get the error described. diff --git a/src/EventHandler.cc b/src/EventHandler.cc index fa1d90bbd2..4b8f2d11aa 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -132,7 +132,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) for ( int i = 0; i < args->NumFields(); i++ ) { const char* fname = args->FieldName(i); - BroType* ftype = args->FieldType(i); + const auto& ftype = args->GetFieldType(i); auto fdefault = args->FieldDefault(i); auto rec = make_intrusive(call_argument); diff --git a/src/Expr.cc b/src/Expr.cc index bad027f368..0929de3888 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2373,7 +2373,7 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) RecordVal* aggr_r = aggr->AsRecordVal(); - auto v = op2->InitVal(rt->FieldType(td.id), nullptr); + auto v = op2->InitVal(rt->GetFieldType(td.id).get(), nullptr); if ( ! v ) return nullptr; @@ -2867,7 +2867,7 @@ FieldExpr::FieldExpr(IntrusivePtr arg_op, const char* arg_field_name) ExprError("no such field in record"); else { - SetType({NewRef{}, rt->FieldType(field)}); + SetType(rt->GetFieldType(field)); td = rt->FieldDecl(field); if ( rt->IsFieldDeprecated(field) ) @@ -3565,8 +3565,8 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, break; } - BroType* sub_t_i = sub_r->FieldType(i); - BroType* sup_t_i = t_r->FieldType(t_i); + BroType* sub_t_i = sub_r->GetFieldType(i).get(); + BroType* sup_t_i = t_r->GetFieldType(t_i).get(); if ( ! same_type(sup_t_i, sub_t_i) ) { @@ -3685,7 +3685,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const } BroType* rhs_type = rhs->Type(); - BroType* field_type = val_type->FieldType(i); + BroType* field_type = val_type->GetFieldType(i).get(); if ( rhs_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && @@ -3711,11 +3711,11 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const { auto def_val = def->AttrExpr()->Eval(nullptr); BroType* def_type = def_val->Type(); - BroType* field_type = Type()->AsRecordType()->FieldType(i); + const auto& field_type = Type()->AsRecordType()->GetFieldType(i); if ( def_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && - ! same_type(def_type, field_type) ) + ! same_type(def_type, field_type.get()) ) { auto tmp = def_val->AsRecordVal()->CoerceTo( field_type->AsRecordType()); @@ -3814,7 +3814,7 @@ FlattenExpr::FlattenExpr(IntrusivePtr arg_op) auto tl = make_intrusive(); for ( int i = 0; i < num_fields; ++i ) - tl->Append({NewRef{}, rt->FieldType(i)}); + tl->Append(rt->GetFieldType(i)); Unref(rt); SetType(std::move(tl)); @@ -4809,7 +4809,7 @@ RecordAssignExpr::RecordAssignExpr(const IntrusivePtr& record, int field = lhs->FieldOffset(field_name); if ( field >= 0 && - same_type(lhs->FieldType(field), t->FieldType(j)) ) + same_type(lhs->GetFieldType(field).get(), t->GetFieldType(j).get()) ) { auto fe_lhs = make_intrusive(record, field_name); auto fe_rhs = make_intrusive(IntrusivePtr{NewRef{}, init}, field_name); @@ -5081,7 +5081,7 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types) TypeList* tl = new TypeList(); for ( int i = 0; i < types->NumFields(); ++i ) - tl->Append({NewRef{}, types->FieldType(i)}); + tl->Append(types->GetFieldType(i)); int rval = check_and_promote_exprs(args, tl); Unref(tl); diff --git a/src/ID.cc b/src/ID.cc index 34289ef574..f77c693aaa 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -187,7 +187,7 @@ void ID::UpdateValAttrs() TypeDecl* fd = rt->FieldDecl(i); if ( ! fd->attrs ) - fd->attrs = make_intrusive(new attr_list, IntrusivePtr{NewRef{}, rt->FieldType(i)}, true, IsGlobal()); + fd->attrs = make_intrusive(new attr_list, rt->GetFieldType(i), true, IsGlobal()); fd->attrs->AddAttr(make_intrusive(ATTR_LOG)); } diff --git a/src/Type.cc b/src/Type.cc index be28490d91..131346ceb1 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -442,7 +442,7 @@ FuncType::FuncType(IntrusivePtr arg_args, args->Error(err_str); } - arg_types->Append({NewRef{}, args->FieldType(i)}); + arg_types->Append(args->GetFieldType(i)); offsets[i] = i; } @@ -609,10 +609,10 @@ std::optional FuncType::FindPrototype(const RecordType& arg for ( auto i = 0; i < args.NumFields(); ++i ) { - auto ptype = p.args->FieldType(i); - auto desired_type = args.FieldType(i); + const auto& ptype = p.args->GetFieldType(i); + const auto& desired_type = args.GetFieldType(i); - if ( ! same_type(ptype, desired_type) || + if ( ! same_type(ptype.get(), desired_type.get()) || ! streq(args.FieldName(i), p.args->FieldName(i)) ) { matched = false; @@ -700,17 +700,6 @@ bool RecordType::HasField(const char* field) const return FieldOffset(field) >= 0; } -BroType* RecordType::FieldType(const char* field) const - { - int offset = FieldOffset(field); - return offset >= 0 ? FieldType(offset) : nullptr; - } - -BroType* RecordType::FieldType(int field) const - { - return (*types)[field]->type.get(); - } - IntrusivePtr RecordType::FieldDefault(int field) const { const TypeDecl* td = FieldDecl(field); @@ -830,7 +819,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const for ( int i = 0; i < NumFields(); ++i ) { - const BroType* ft = FieldType(i); + const auto& ft = GetFieldType(i); const TypeDecl* fd = FieldDecl(i); Val* fv = nullptr; @@ -844,7 +833,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const auto nr = make_intrusive(internal_type("record_field")->AsRecordType()); - string s = container_type_name(ft); + string s = container_type_name(ft.get()); nr->Assign(0, make_intrusive(s)); nr->Assign(1, val_mgr->Bool(logged)); nr->Assign(2, fv); @@ -1656,10 +1645,10 @@ bool record_promotion_compatible(const RecordType* super_rec, // Orphaned field. continue; - BroType* sub_field_type = sub_rec->FieldType(i); - BroType* super_field_type = super_rec->FieldType(o); + const auto& sub_field_type = sub_rec->GetFieldType(i); + const auto& super_field_type = super_rec->GetFieldType(o); - if ( same_type(sub_field_type, super_field_type) ) + if ( same_type(sub_field_type.get(), super_field_type.get()) ) continue; if ( sub_field_type->Tag() != TYPE_RECORD ) diff --git a/src/Type.h b/src/Type.h index 90a02dedd5..a67164ac6f 100644 --- a/src/Type.h +++ b/src/Type.h @@ -552,8 +552,32 @@ public: ~RecordType() override; bool HasField(const char* field) const override; - BroType* FieldType(const char* field) const override; - BroType* FieldType(int field) const; + + [[deprecated("Remove in v4.1. Use GetFieldType() instead (note it doesn't check for invalid names).")]] + BroType* FieldType(const char* field) const override + { + auto offset = FieldOffset(field); + return offset >= 0 ? GetFieldType(offset).get() : nullptr; + } + + [[deprecated("Remove in v4.1. Use GetFieldType() instead.")]] + BroType* FieldType(int field) const + { return GetFieldType(field).get(); } + + /** + * Looks up a field by name and returns its type. No check for invalid + * field name is performed. + */ + const IntrusivePtr& GetFieldType(const char* field_name) const + { return GetFieldType(FieldOffset(field_name)); } + + /** + * Looks up a field by its index and returns its type. No check for + * invalid field offset is performed. + */ + const IntrusivePtr& GetFieldType(int field_index) const + { return (*types)[field_index]->type; } + IntrusivePtr FieldDefault(int field) const; // A field's offset is its position in the type_decl_list, diff --git a/src/Val.cc b/src/Val.cc index c7a5ccd58a..622510d203 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2817,12 +2817,13 @@ IntrusivePtr RecordVal::CoerceTo(const RecordType* t, Val* aggr, bool // Check for allowable optional fields is outside the loop, below. continue; - if ( ar_t->FieldType(t_i)->Tag() == TYPE_RECORD && - ! same_type(ar_t->FieldType(t_i), v->Type()) ) + const auto& ft = ar_t->GetFieldType(t_i); + + if ( ft->Tag() == TYPE_RECORD && ! same_type(ft.get(), v->Type()) ) { auto rhs = make_intrusive(IntrusivePtr{NewRef{}, v}); auto e = make_intrusive(std::move(rhs), - IntrusivePtr{NewRef{}, ar_t->FieldType(t_i)->AsRecordType()}); + cast_intrusive(ft)); ar->Assign(t_i, e->Eval(nullptr)); continue; } diff --git a/src/Var.cc b/src/Var.cc index 9ca437a5e2..33cbc7916e 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -448,7 +448,7 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl return false; for ( auto i = 0; i < canon_args->NumFields(); ++i ) - if ( ! same_type(canon_args->FieldType(i), impl_args->FieldType(i)) ) + if ( ! same_type(canon_args->GetFieldType(i).get(), impl_args->GetFieldType(i).get()) ) return false; return true; diff --git a/src/broker/Data.cc b/src/broker/Data.cc index ba2105264c..2e405e1f1e 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -403,7 +403,7 @@ struct val_converter { } auto item_val = bro_broker::data_to_val(move(a[idx]), - rt->FieldType(i)); + rt->GetFieldType(i).get()); if ( ! item_val ) return nullptr; @@ -730,7 +730,7 @@ struct type_checker { continue; } - if ( ! data_type_check(a[idx], rt->FieldType(i)) ) + if ( ! data_type_check(a[idx], rt->GetFieldType(i).get()) ) return false; ++idx; diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 72d53ee14b..766a0c559a 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -366,16 +366,16 @@ bool Manager::CreateEventStream(RecordVal* fval) for ( int i = 0; i < fields->NumFields(); i++ ) { - if ( ! same_type(args[i + 2].get(), fields->FieldType(i) ) ) + if ( ! same_type(args[i + 2].get(), fields->GetFieldType(i).get() ) ) { ODesc desc1; ODesc desc2; args[i + 2]->Describe(&desc1); - fields->FieldType(i)->Describe(&desc2); + fields->GetFieldType(i)->Describe(&desc2); reporter->Error("Input stream %s: Incompatible type for event in field %d. Need type '%s':%s, got '%s':%s", stream_name.c_str(), i + 3, - type_name(fields->FieldType(i)->Tag()), desc2.Description(), + type_name(fields->GetFieldType(i)->Tag()), desc2.Description(), type_name(args[i + 2]->Tag()), desc1.Description()); return false; @@ -497,15 +497,15 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( ! same_type(idx->FieldType(j), tl[j].get()) ) + if ( ! same_type(idx->GetFieldType(j).get(), tl[j].get()) ) { ODesc desc1; ODesc desc2; - idx->FieldType(j)->Describe(&desc1); + idx->GetFieldType(j)->Describe(&desc1); tl[j]->Describe(&desc2); reporter->Error("Input stream %s: Table type does not match index type. Need type '%s':%s, got '%s':%s", stream_name.c_str(), - type_name(idx->FieldType(j)->Tag()), desc1.Description(), + type_name(idx->GetFieldType(j)->Tag()), desc1.Description(), type_name(tl[j]->Tag()), desc2.Description()); return false; @@ -526,7 +526,7 @@ bool Manager::CreateTableStream(RecordVal* fval) const BroType* compare_type = val.get(); if ( want_record->InternalInt() == 0 ) - compare_type = val->FieldType(0); + compare_type = val->GetFieldType(0).get(); if ( ! same_type(table_yield, compare_type) ) { @@ -606,11 +606,11 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } else if ( want_record->InternalInt() == 0 - && val && !same_type(args[3].get(), val->FieldType(0) ) ) + && val && !same_type(args[3].get(), val->GetFieldType(0).get() ) ) { ODesc desc1; ODesc desc2; - val->FieldType(0)->Describe(&desc1); + val->GetFieldType(0)->Describe(&desc1); args[3]->Describe(&desc2); reporter->Error("Input stream %s: Table event's value attribute does not match. Need '%s', got '%s'", stream_name.c_str(), desc1.Description(), desc2.Description()); @@ -892,7 +892,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, for ( int i = 0; i < rec->NumFields(); i++ ) { - if ( ! IsCompatibleType(rec->FieldType(i)) ) + if ( ! IsCompatibleType(rec->GetFieldType(i).get()) ) { string name = nameprepend + rec->FieldName(i); // If the field is a file, function, or opaque @@ -901,21 +901,21 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, // stuff that we actually cannot read :) if ( allow_file_func ) { - if ( ( rec->FieldType(i)->Tag() == TYPE_FILE || - rec->FieldType(i)->Tag() == TYPE_FUNC || - rec->FieldType(i)->Tag() == TYPE_OPAQUE ) && + if ( ( rec->GetFieldType(i)->Tag() == TYPE_FILE || + rec->GetFieldType(i)->Tag() == TYPE_FUNC || + rec->GetFieldType(i)->Tag() == TYPE_OPAQUE ) && rec->FieldDecl(i)->FindAttr(ATTR_OPTIONAL) ) { - reporter->Info("Encountered incompatible type \"%s\" in type definition for field \"%s\" in ReaderFrontend. Ignoring optional field.", type_name(rec->FieldType(i)->Tag()), name.c_str()); + reporter->Info("Encountered incompatible type \"%s\" in type definition for field \"%s\" in ReaderFrontend. Ignoring optional field.", type_name(rec->GetFieldType(i)->Tag()), name.c_str()); continue; } } - reporter->Error("Incompatible type \"%s\" in type definition for for field \"%s\" in ReaderFrontend", type_name(rec->FieldType(i)->Tag()), name.c_str()); + reporter->Error("Incompatible type \"%s\" in type definition for for field \"%s\" in ReaderFrontend", type_name(rec->GetFieldType(i)->Tag()), name.c_str()); return false; } - if ( rec->FieldType(i)->Tag() == TYPE_RECORD ) + if ( rec->GetFieldType(i)->Tag() == TYPE_RECORD ) { string prep = nameprepend + rec->FieldName(i) + "."; @@ -925,7 +925,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, return false; } - if ( !UnrollRecordType(fields, rec->FieldType(i)->AsRecordType(), prep, allow_file_func) ) + if ( !UnrollRecordType(fields, rec->GetFieldType(i)->AsRecordType(), prep, allow_file_func) ) { return false; } @@ -937,15 +937,15 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, string name = nameprepend + rec->FieldName(i); const char* secondary = nullptr; IntrusivePtr c; - TypeTag ty = rec->FieldType(i)->Tag(); + TypeTag ty = rec->GetFieldType(i)->Tag(); TypeTag st = TYPE_VOID; bool optional = false; if ( ty == TYPE_TABLE ) - st = rec->FieldType(i)->AsSetType()->Indices()->GetPureType()->Tag(); + st = rec->GetFieldType(i)->AsSetType()->Indices()->GetPureType()->Tag(); else if ( ty == TYPE_VECTOR ) - st = rec->FieldType(i)->AsVectorType()->YieldType()->Tag(); + st = rec->GetFieldType(i)->AsVectorType()->YieldType()->Tag(); else if ( ty == TYPE_PORT && rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN) ) @@ -1027,9 +1027,9 @@ Val* Manager::ValueToIndexVal(const Stream* i, int num_fields, const RecordType int position = 0; - if ( num_fields == 1 && type->FieldType(0)->Tag() != TYPE_RECORD ) + if ( num_fields == 1 && type->GetFieldType(0)->Tag() != TYPE_RECORD ) { - idxval = ValueToVal(i, vals[0], type->FieldType(0), have_error); + idxval = ValueToVal(i, vals[0], type->GetFieldType(0).get(), have_error); position = 1; } else @@ -1037,12 +1037,12 @@ Val* Manager::ValueToIndexVal(const Stream* i, int num_fields, const RecordType ListVal *l = new ListVal(TYPE_ANY); for ( int j = 0 ; j < type->NumFields(); j++ ) { - if ( type->FieldType(j)->Tag() == TYPE_RECORD ) + if ( type->GetFieldType(j)->Tag() == TYPE_RECORD ) l->Append({AdoptRef{}, ValueToRecordVal(i, vals, - type->FieldType(j)->AsRecordType(), &position, have_error)}); + type->GetFieldType(j)->AsRecordType(), &position, have_error)}); else { - l->Append({AdoptRef{}, ValueToVal(i, vals[position], type->FieldType(j), have_error)}); + l->Append({AdoptRef{}, ValueToVal(i, vals[position], type->GetFieldType(j).get(), have_error)}); position++; } } @@ -1158,7 +1158,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) valval = nullptr; else if ( stream->num_val_fields == 1 && !stream->want_record ) - valval = ValueToVal(i, vals[position], stream->rtype->FieldType(0), convert_error); + valval = ValueToVal(i, vals[position], stream->rtype->GetFieldType(0).get(), convert_error); else valval = ValueToRecordVal(i, vals, stream->rtype, &position, convert_error); @@ -1502,14 +1502,14 @@ int Manager::SendEventStreamEvent(Stream* i, EnumVal* type, const Value* const * { Val* val = nullptr; - if ( stream->fields->FieldType(j)->Tag() == TYPE_RECORD ) + if ( stream->fields->GetFieldType(j)->Tag() == TYPE_RECORD ) val = ValueToRecordVal(i, vals, - stream->fields->FieldType(j)->AsRecordType(), + stream->fields->GetFieldType(j)->AsRecordType(), &position, convert_error); else { - val = ValueToVal(i, vals[position], stream->fields->FieldType(j), convert_error); + val = ValueToVal(i, vals[position], stream->fields->GetFieldType(j).get(), convert_error); position++; } @@ -1547,7 +1547,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) valval = nullptr; else if ( stream->num_val_fields == 1 && stream->want_record == 0 ) - valval = ValueToVal(i, vals[position], stream->rtype->FieldType(0), convert_error); + valval = ValueToVal(i, vals[position], stream->rtype->GetFieldType(0).get(), convert_error); else valval = ValueToRecordVal(i, vals, stream->rtype, &position, convert_error); @@ -1845,10 +1845,10 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu Val* v = ValueToVal(i, vals[j], convert_error); vl.emplace_back(AdoptRef{}, v); - if ( v && ! convert_error && ! same_type(type->FieldType(j), v->Type()) ) + if ( v && ! convert_error && ! same_type(type->GetFieldType(j).get(), v->Type()) ) { convert_error = true; - type->FieldType(j)->Error("SendEvent types do not match", v->Type()); + type->GetFieldType(j)->Error("SendEvent types do not match", v->Type()); } } @@ -1916,8 +1916,8 @@ RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType *request_type, assert ( (*position) <= maxpos ); Val* fieldVal = nullptr; - if ( request_type->FieldType(i)->Tag() == TYPE_RECORD ) - fieldVal = ListValToRecordVal(list, request_type->FieldType(i)->AsRecordType(), position); + if ( request_type->GetFieldType(i)->Tag() == TYPE_RECORD ) + fieldVal = ListValToRecordVal(list, request_type->GetFieldType(i)->AsRecordType(), position); else { fieldVal = list->Idx(*position).get(); @@ -1940,10 +1940,10 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v for ( int i = 0; i < request_type->NumFields(); i++ ) { Val* fieldVal = nullptr; - if ( request_type->FieldType(i)->Tag() == TYPE_RECORD ) - fieldVal = ValueToRecordVal(stream, vals, request_type->FieldType(i)->AsRecordType(), position, have_error); - else if ( request_type->FieldType(i)->Tag() == TYPE_FILE || - request_type->FieldType(i)->Tag() == TYPE_FUNC ) + if ( request_type->GetFieldType(i)->Tag() == TYPE_RECORD ) + fieldVal = ValueToRecordVal(stream, vals, request_type->GetFieldType(i)->AsRecordType(), position, have_error); + else if ( request_type->GetFieldType(i)->Tag() == TYPE_FILE || + request_type->GetFieldType(i)->Tag() == TYPE_FUNC ) { // If those two unsupported types are encountered here, they have // been let through by the type checking. @@ -1956,7 +1956,7 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v } else { - fieldVal = ValueToVal(stream, vals[*position], request_type->FieldType(i), have_error); + fieldVal = ValueToVal(stream, vals[*position], request_type->GetFieldType(i).get(), have_error); (*position)++; } diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 23a295238b..44327ee43e 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -247,7 +247,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) if ( ! (columns->FieldDecl(i)->FindAttr(ATTR_LOG)) ) continue; - if ( ! threading::Value::IsCompatibleType(columns->FieldType(i)) ) + if ( ! threading::Value::IsCompatibleType(columns->GetFieldType(i).get()) ) { reporter->Error("type of field '%s' is not support for logging output", columns->FieldName(i)); @@ -409,7 +409,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, rtype = rt; } - BroType* t = rtype->FieldType(i); + const auto& t = rtype->GetFieldType(i); // Ignore if &log not specified. if ( ! rtype->FieldDecl(i)->FindAttr(ATTR_LOG) ) @@ -744,7 +744,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) path_arg = val_mgr->EmptyString(); IntrusivePtr rec_arg; - BroType* rt = filter->path_func->FType()->Args()->FieldType("rec"); + const auto& rt = filter->path_func->FType()->Args()->GetFieldType("rec"); if ( rt->Tag() == TYPE_RECORD ) rec_arg = columns->CoerceTo(rt->AsRecordType(), true); diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 75e08bdef1..6ae8038fcd 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1123,14 +1123,14 @@ IntrusivePtr Supervisor::NodeConfig::ToRecord() const if ( cpu_affinity ) rval->Assign(rt->FieldOffset("cpu_affinity"), val_mgr->Int(*cpu_affinity)); - auto st = BifType::Record::Supervisor::NodeConfig->FieldType("scripts"); + const auto& st = rt->GetFieldType("scripts"); auto scripts_val = new VectorVal(st->AsVectorType()); rval->Assign(rt->FieldOffset("scripts"), scripts_val); for ( const auto& s : scripts ) scripts_val->Assign(scripts_val->Size(), make_intrusive(s)); - auto tt = BifType::Record::Supervisor::NodeConfig->FieldType("cluster"); + const auto& tt = rt->GetFieldType("cluster"); auto cluster_val = new TableVal({NewRef{}, tt->AsTableType()}); rval->Assign(rt->FieldOffset("cluster"), cluster_val); @@ -1314,8 +1314,8 @@ void Supervisor::SupervisedNode::Init(zeek::Options* options) const IntrusivePtr Supervisor::Status(std::string_view node_name) { auto rval = make_intrusive(BifType::Record::Supervisor::Status); - auto tt = BifType::Record::Supervisor::Status->FieldType("nodes"); - auto node_table_val = new TableVal({NewRef{}, tt->AsTableType()}); + const auto& tt = BifType::Record::Supervisor::Status->GetFieldType("nodes"); + auto node_table_val = new TableVal(cast_intrusive(tt)); rval->Assign(0, node_table_val); if ( node_name.empty() ) From 2aa84eb86ee01562c6f3c4fd344ad7f5b6288638 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 7 May 2020 15:06:13 -0700 Subject: [PATCH 023/151] Deprecate BroType::GetField() and BroType::HasField() --- NEWS | 3 +++ src/Type.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/NEWS b/NEWS index 50d732d707..4f23388cea 100644 --- a/NEWS +++ b/NEWS @@ -148,6 +148,9 @@ Deprecated Functionality - ``RecordType::FieldType()`` is deprecated, use ``RecordType::GetFieldType()`` +- ``BroType::HasField()`` and ``BroType::FieldType()`` are deprecated, use + the methods of ``RecordType`` directly. + Zeek 3.1.0 ========== diff --git a/src/Type.h b/src/Type.h index a67164ac6f..29f7e8383f 100644 --- a/src/Type.h +++ b/src/Type.h @@ -177,9 +177,11 @@ public: // Returns true if this type is a record and contains the // given field, false otherwise. + [[deprecated("Remove in v4.1. Use RecordType::HasField() directly.")]] virtual bool HasField(const char* field) const; // Returns the type of the given field, or nil if no such field. + [[deprecated("Remove in v4.1. Use RecordType::GetFieldType() directly.")]] virtual BroType* FieldType(const char* field) const; #define CHECK_TYPE_TAG(tag_type, func_name) \ From bb25f5d568b5b8f5c7bc78dfd00a9aa2d73c8ce3 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 7 May 2020 16:16:18 -0700 Subject: [PATCH 024/151] Change base_type() to return const-ref, deprecate base_type_no_ref() --- src/OpaqueVal.cc | 2 +- src/Type.cc | 20 ++++++++------------ src/Type.h | 12 ++++++------ src/Val.cc | 3 +-- src/Val.h | 6 +++--- src/parse.y | 30 +++++++++++++++--------------- 6 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 3970e20ab5..2ae0b06455 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -141,7 +141,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data) if ( ! tag ) return nullptr; - return base_type(static_cast(*tag)).release(); + return base_type(static_cast(*tag))->Ref(); } IntrusivePtr OpaqueVal::DoClone(CloneState* state) diff --git a/src/Type.cc b/src/Type.cc index 131346ceb1..d4cbfd0f15 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1365,7 +1365,7 @@ BroType* VectorType::YieldType() // return any as that's what other code historically expects for type // comparisions. if ( IsUnspecifiedVector() ) - return base_type_no_ref(TYPE_ANY); + return ::base_type(TYPE_ANY).get(); return yield_type.get(); } @@ -1431,26 +1431,22 @@ void VectorType::DescribeReST(ODesc* d, bool roles_only) const d->Add(fmt(":zeek:type:`%s`", yield_type->GetName().c_str())); } -BroType* base_type_no_ref(TypeTag tag) +const IntrusivePtr& base_type(TypeTag tag) { - static BroType* base_types[NUM_TYPES]; + static IntrusivePtr base_types[NUM_TYPES]; - // We could check here that "tag" actually corresponds to a BRO - // basic type. - - int t = int(tag); - if ( ! base_types[t] ) + // We could check here that "tag" actually corresponds to a basic type. + if ( ! base_types[tag] ) { - base_types[t] = new BroType(tag, true); + base_types[tag] = make_intrusive(tag, true); // Give the base types a pseudo-location for easier identification. Location l(type_name(tag), 0, 0, 0, 0); - base_types[t]->SetLocationInfo(&l); + base_types[tag]->SetLocationInfo(&l); } - return base_types[t]; + return base_types[tag]; } - // Returns true if t1 is initialization-compatible with t2 (i.e., if an // initializer with type t1 can be used to initialize a value with type t2), // false otherwise. Assumes that t1's tag is different from t2's. Note diff --git a/src/Type.h b/src/Type.h index 29f7e8383f..d8c24e365a 100644 --- a/src/Type.h +++ b/src/Type.h @@ -757,16 +757,16 @@ extern OpaqueType* ocsp_resp_opaque_type; extern OpaqueType* paraglob_type; // Returns the basic (non-parameterized) type with the given type. -// The reference count of the type is not increased. -BroType* base_type_no_ref(TypeTag tag); +const IntrusivePtr& base_type(TypeTag tag); // Returns the basic (non-parameterized) type with the given type. -// The caller assumes responsibility for a reference to the type. -inline IntrusivePtr base_type(TypeTag tag) - { return {NewRef{}, base_type_no_ref(tag)}; } +// The reference count of the type is not increased. +[[deprecated("Remove in v4.1. Use ::base_type() instead")]] +inline BroType* base_type_no_ref(TypeTag tag) + { return base_type(tag).get(); } // Returns the basic error type. -inline IntrusivePtr error_type() { return base_type(TYPE_ERROR); } +inline const IntrusivePtr& error_type() { return base_type(TYPE_ERROR); } // True if the two types are equivalent. If is_init is true then the test is // done in the context of an initialization. If match_record_field_names is diff --git a/src/Val.cc b/src/Val.cc index 622510d203..8d1a1707e7 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1122,7 +1122,7 @@ IntrusivePtr StringVal::DoClone(CloneState* state) } PatternVal::PatternVal(RE_Matcher* re) - : Val(base_type_no_ref(TYPE_PATTERN)) + : Val(base_type(TYPE_PATTERN).get()) { val.re_val = re; } @@ -1130,7 +1130,6 @@ PatternVal::PatternVal(RE_Matcher* re) PatternVal::~PatternVal() { delete AsPattern(); - Unref(type); // base_type() ref'd it, so did our base constructor } bool PatternVal::AddTo(Val* v, bool /* is_first_init */) const diff --git a/src/Val.h b/src/Val.h index 95a687709c..455ae7b19c 100644 --- a/src/Val.h +++ b/src/Val.h @@ -126,7 +126,7 @@ union BroValUnion { class Val : public BroObj { public: Val(double d, TypeTag t) - : val(d), type(base_type(t).release()) + : val(d), type(base_type(t)->Ref()) { } @@ -143,7 +143,7 @@ public: } Val() - : val(bro_int_t(0)), type(base_type(TYPE_ERROR).release()) + : val(bro_int_t(0)), type(base_type(TYPE_ERROR)->Ref()) { } @@ -341,7 +341,7 @@ protected: template Val(V &&v, TypeTag t) noexcept - : val(std::forward(v)), type(base_type(t).release()) + : val(std::forward(v)), type(base_type(t)->Ref()) { } diff --git a/src/parse.y b/src/parse.y index 928340f20b..00f2e65874 100644 --- a/src/parse.y +++ b/src/parse.y @@ -843,72 +843,72 @@ enum_body_elem: type: TOK_BOOL { set_location(@1); - $$ = base_type(TYPE_BOOL).release(); + $$ = base_type(TYPE_BOOL)->Ref(); } | TOK_INT { set_location(@1); - $$ = base_type(TYPE_INT).release(); + $$ = base_type(TYPE_INT)->Ref(); } | TOK_COUNT { set_location(@1); - $$ = base_type(TYPE_COUNT).release(); + $$ = base_type(TYPE_COUNT)->Ref(); } | TOK_COUNTER { set_location(@1); - $$ = base_type(TYPE_COUNTER).release(); + $$ = base_type(TYPE_COUNTER)->Ref(); } | TOK_DOUBLE { set_location(@1); - $$ = base_type(TYPE_DOUBLE).release(); + $$ = base_type(TYPE_DOUBLE)->Ref(); } | TOK_TIME { set_location(@1); - $$ = base_type(TYPE_TIME).release(); + $$ = base_type(TYPE_TIME)->Ref(); } | TOK_INTERVAL { set_location(@1); - $$ = base_type(TYPE_INTERVAL).release(); + $$ = base_type(TYPE_INTERVAL)->Ref(); } | TOK_STRING { set_location(@1); - $$ = base_type(TYPE_STRING).release(); + $$ = base_type(TYPE_STRING)->Ref(); } | TOK_PATTERN { set_location(@1); - $$ = base_type(TYPE_PATTERN).release(); + $$ = base_type(TYPE_PATTERN)->Ref(); } | TOK_TIMER { set_location(@1); - $$ = base_type(TYPE_TIMER).release(); + $$ = base_type(TYPE_TIMER)->Ref(); } | TOK_PORT { set_location(@1); - $$ = base_type(TYPE_PORT).release(); + $$ = base_type(TYPE_PORT)->Ref(); } | TOK_ADDR { set_location(@1); - $$ = base_type(TYPE_ADDR).release(); + $$ = base_type(TYPE_ADDR)->Ref(); } | TOK_SUBNET { set_location(@1); - $$ = base_type(TYPE_SUBNET).release(); + $$ = base_type(TYPE_SUBNET)->Ref(); } | TOK_ANY { set_location(@1); - $$ = base_type(TYPE_ANY).release(); + $$ = base_type(TYPE_ANY)->Ref(); } | TOK_TABLE '[' type_list ']' TOK_OF type @@ -1012,7 +1012,7 @@ type: NullStmt here; if ( $1 ) $1->Error("not a Zeek type", &here); - $$ = error_type().release(); + $$ = error_type()->Ref(); } else { From f26904e03133fdede44fd8952008796444cf1f5e Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 7 May 2020 18:02:51 -0700 Subject: [PATCH 025/151] Deprecate BroType::YieldType(), replace with Yield() --- NEWS | 2 + src/Attr.cc | 12 ++-- src/CompHash.cc | 8 +-- src/Expr.cc | 90 ++++++++++++++--------------- src/Func.cc | 4 +- src/RuleCondition.cc | 2 +- src/Scope.cc | 2 +- src/Stmt.cc | 13 ++--- src/Type.cc | 91 ++++++++---------------------- src/Type.h | 30 ++++++---- src/Val.cc | 22 ++++---- src/Var.cc | 2 +- src/broker/Data.cc | 8 +-- src/input/Manager.cc | 24 ++++---- src/input/readers/config/Config.cc | 2 +- src/logging/Manager.cc | 14 ++--- src/option.bif | 4 +- src/threading/SerialTypes.cc | 2 +- src/zeek.bif | 14 ++--- 19 files changed, 156 insertions(+), 190 deletions(-) diff --git a/NEWS b/NEWS index 4f23388cea..ff7b02f657 100644 --- a/NEWS +++ b/NEWS @@ -151,6 +151,8 @@ Deprecated Functionality - ``BroType::HasField()`` and ``BroType::FieldType()`` are deprecated, use the methods of ``RecordType`` directly. +- ``BroType::YieldType()`` is deprecated, use ``BroType::Yield()``. + Zeek 3.1.0 ========== diff --git a/src/Attr.cc b/src/Attr.cc index 6480f19ce6..747994a396 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -273,7 +273,7 @@ void Attributes::CheckAttr(Attr* a) } FuncType* aft = at->AsFuncType(); - if ( ! same_type(aft->YieldType(), type.get()) ) + if ( ! same_type(aft->Yield().get(), type.get()) ) { a->AttrExpr()->Error( is_add ? @@ -328,7 +328,7 @@ void Attributes::CheckAttr(Attr* a) } TableType* tt = type->AsTableType(); - BroType* ytype = tt->YieldType(); + BroType* ytype = tt->Yield().get(); if ( ! in_record ) { @@ -340,7 +340,7 @@ void Attributes::CheckAttr(Attr* a) { FuncType* f = atype->AsFuncType(); if ( ! f->CheckArgs(tt->IndexTypes()) || - ! same_type(f->YieldType(), ytype) ) + ! same_type(f->Yield().get(), ytype) ) Error("&default function type clash"); // Ok. @@ -453,7 +453,7 @@ void Attributes::CheckAttr(Attr* a) const FuncType* e_ft = expire_func->Type()->AsFuncType(); - if ( e_ft->YieldType()->Tag() != TYPE_INTERVAL ) + if ( e_ft->Yield()->Tag() != TYPE_INTERVAL ) { Error("&expire_func must yield a value of type interval"); break; @@ -500,7 +500,7 @@ void Attributes::CheckAttr(Attr* a) const FuncType* c_ft = change_func->Type()->AsFuncType(); - if ( c_ft->YieldType()->Tag() != TYPE_VOID ) + if ( c_ft->Yield()->Tag() != TYPE_VOID ) { Error("&on_change must not return a value"); break; @@ -542,7 +542,7 @@ void Attributes::CheckAttr(Attr* a) } if ( ! type->IsSet() ) - if ( ! same_type(args[2+t_indexes.size()].get(), the_table->YieldType()) ) + if ( ! same_type(args[2+t_indexes.size()].get(), the_table->Yield().get()) ) { Error("&on_change: value type does not match table"); break; diff --git a/src/CompHash.cc b/src/CompHash.cc index 416ae38208..ea98690e69 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -277,7 +277,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, if ( val ) { if ( ! (kp1 = SingleValHash(type_check, kp1, - vt->YieldType(), val, false)) ) + vt->Yield().get(), val, false)) ) return nullptr; } } @@ -570,7 +570,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, sz = SizeAlign(sz, sizeof(unsigned int)); sz = SizeAlign(sz, sizeof(unsigned int)); if ( val ) - sz = SingleTypeKeySize(bt->AsVectorType()->YieldType(), + sz = SingleTypeKeySize(bt->AsVectorType()->Yield().get(), val, type_check, sz, false, calc_static_size); if ( ! sz ) return 0; @@ -956,7 +956,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, else { IntrusivePtr value; - kp1 = RecoverOneVal(k, kp1, k_end, tt->YieldType(), &value, + kp1 = RecoverOneVal(k, kp1, k_end, tt->Yield().get(), &value, false); tv->Assign(key.get(), std::move(value)); } @@ -986,7 +986,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, IntrusivePtr value; if ( have_val ) - kp1 = RecoverOneVal(k, kp1, k_end, vt->YieldType(), &value, + kp1 = RecoverOneVal(k, kp1, k_end, vt->Yield().get(), &value, false); vv->Assign(index, std::move(value)); diff --git a/src/Expr.cc b/src/Expr.cc index 0929de3888..cff9cd0d08 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -676,7 +676,7 @@ IntrusivePtr BinaryExpr::Fold(Val* v1, Val* v2) const BroType* ret_type = Type(); if ( IsVector(ret_type->Tag()) ) - ret_type = ret_type->YieldType(); + ret_type = ret_type->Yield().get(); if ( ret_type->Tag() == TYPE_INTERVAL ) return make_intrusive(d3, 1.0); @@ -863,9 +863,9 @@ void BinaryExpr::PromoteOps(TypeTag t) bool is_vec2 = IsVector(bt2); if ( is_vec1 ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); if ( is_vec2 ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( (is_vec1 || is_vec2) && ! (is_vec1 && is_vec2) ) reporter->Warning("mixing vector and scalar operands is deprecated"); @@ -922,7 +922,7 @@ IncrExpr::IncrExpr(BroExprTag arg_tag, IntrusivePtr arg_op) if ( IsVector(t->Tag()) ) { - if ( ! IsIntegral(t->AsVectorType()->YieldType()->Tag()) ) + if ( ! IsIntegral(t->AsVectorType()->Yield()->Tag()) ) ExprError("vector elements must be integral for increment operator"); else { @@ -956,7 +956,7 @@ IntrusivePtr IncrExpr::DoSingleEval(Frame* f, Val* v) const BroType* ret_type = Type(); if ( IsVector(ret_type->Tag()) ) - ret_type = Type()->YieldType(); + ret_type = Type()->Yield().get(); if ( ret_type->Tag() == TYPE_INT ) return val_mgr->Int(k); @@ -1050,7 +1050,7 @@ PosExpr::PosExpr(IntrusivePtr arg_op) BroType* t = op->Type(); if ( IsVector(t->Tag()) ) - t = t->AsVectorType()->YieldType(); + t = t->AsVectorType()->Yield().get(); TypeTag bt = t->Tag(); IntrusivePtr base_result_type; @@ -1088,7 +1088,7 @@ NegExpr::NegExpr(IntrusivePtr arg_op) BroType* t = op->Type(); if ( IsVector(t->Tag()) ) - t = t->AsVectorType()->YieldType(); + t = t->AsVectorType()->Yield().get(); TypeTag bt = t->Tag(); IntrusivePtr base_result_type; @@ -1153,12 +1153,12 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); IntrusivePtr base_result_type; @@ -1209,7 +1209,7 @@ AddToExpr::AddToExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) else if ( IsVector(bt1) ) { - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); if ( IsArithmetic(bt1) ) { @@ -1279,11 +1279,11 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) - bt1 = t1->AsVectorType()->YieldType()->Tag(); + bt1 = t1->AsVectorType()->Yield()->Tag(); TypeTag bt2 = t2->Tag(); if ( IsVector(bt2) ) - bt2 = t2->AsVectorType()->YieldType()->Tag(); + bt2 = t2->AsVectorType()->Yield()->Tag(); IntrusivePtr base_result_type; @@ -1366,12 +1366,12 @@ TimesExpr::TimesExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) { @@ -1403,12 +1403,12 @@ DivideExpr::DivideExpr(IntrusivePtr arg_op1, TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) { @@ -1470,12 +1470,12 @@ ModExpr::ModExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( BothIntegral(bt1, bt2) ) PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); @@ -1493,12 +1493,12 @@ BoolExpr::BoolExpr(BroExprTag arg_tag, TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt2 = op2->Type()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); if ( BothBool(bt1, bt2) ) { @@ -1643,12 +1643,12 @@ BitExpr::BitExpr(BroExprTag arg_tag, TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) - bt1 = t1->AsVectorType()->YieldType()->Tag(); + bt1 = t1->AsVectorType()->Yield()->Tag(); TypeTag bt2 = t2->Tag(); if ( IsVector(bt2) ) - bt2 = t2->AsVectorType()->YieldType()->Tag(); + bt2 = t2->AsVectorType()->Yield()->Tag(); if ( (bt1 == TYPE_COUNT || bt1 == TYPE_COUNTER) && (bt2 == TYPE_COUNT || bt2 == TYPE_COUNTER) ) @@ -1697,11 +1697,11 @@ EqExpr::EqExpr(BroExprTag arg_tag, TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) - bt1 = t1->AsVectorType()->YieldType()->Tag(); + bt1 = t1->AsVectorType()->Yield()->Tag(); TypeTag bt2 = t2->Tag(); if ( IsVector(bt2) ) - bt2 = t2->AsVectorType()->YieldType()->Tag(); + bt2 = t2->AsVectorType()->Yield()->Tag(); if ( is_vector(op1.get()) || is_vector(op2.get()) ) SetType(make_intrusive(base_type(TYPE_BOOL))); @@ -1799,11 +1799,11 @@ RelExpr::RelExpr(BroExprTag arg_tag, TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) - bt1 = t1->AsVectorType()->YieldType()->Tag(); + bt1 = t1->AsVectorType()->Yield()->Tag(); TypeTag bt2 = t2->Tag(); if ( IsVector(bt2) ) - bt2 = t2->AsVectorType()->YieldType()->Tag(); + bt2 = t2->AsVectorType()->Yield()->Tag(); if ( is_vector(op1.get()) || is_vector(op2.get()) ) SetType(make_intrusive(base_type(TYPE_BOOL))); @@ -1851,7 +1851,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, TypeTag bt1 = op1->Type()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->YieldType()->Tag(); + bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); if ( op1->IsError() || op2->IsError() || op3->IsError() ) SetError(); @@ -1864,12 +1864,12 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, TypeTag bt2 = op2->Type()->Tag(); if ( is_vector(op2.get()) ) - bt2 = op2->Type()->AsVectorType()->YieldType()->Tag(); + bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); TypeTag bt3 = op3->Type()->Tag(); if ( IsVector(bt3) ) - bt3 = op3->Type()->AsVectorType()->YieldType()->Tag(); + bt3 = op3->Type()->AsVectorType()->Yield()->Tag(); if ( is_vector(op1.get()) && ! (is_vector(op2.get()) && is_vector(op3.get())) ) { @@ -2329,7 +2329,7 @@ void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const TableVal* tv = aggr->AsTableVal(); auto index = op1->Eval(f); - auto v = check_and_promote(op2->Eval(f), t->YieldType(), true); + auto v = check_and_promote(op2->Eval(f), t->Yield().get(), true); if ( ! index || ! v ) return; @@ -2395,10 +2395,10 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) auto tv = cast_intrusive(std::move(aggr)); const TableType* tt = tv->Type()->AsTableType(); - const BroType* yt = tv->Type()->YieldType(); + const auto& yt = tv->Type()->Yield(); auto index = op1->InitVal(tt->Indices(), nullptr); - auto v = op2->InitVal(yt, nullptr); + auto v = op2->InitVal(yt.get(), nullptr); if ( ! index || ! v ) return nullptr; @@ -2491,7 +2491,7 @@ IndexExpr::IndexExpr(IntrusivePtr arg_op1, SetError(error_msg.data()); } - else if ( ! op1->Type()->YieldType() ) + else if ( ! op1->Type()->Yield() ) { if ( IsString(op1->Type()->Tag()) && match_type == MATCHES_INDEX_SCALAR ) SetType(base_type(TYPE_STRING)); @@ -2504,10 +2504,10 @@ IndexExpr::IndexExpr(IntrusivePtr arg_op1, } else if ( match_type == MATCHES_INDEX_SCALAR ) - SetType({NewRef{}, op1->Type()->YieldType()}); + SetType(op1->Type()->Yield()); else if ( match_type == MATCHES_INDEX_VECTOR ) - SetType(make_intrusive(IntrusivePtr{NewRef{}, op1->Type()->YieldType()})); + SetType(make_intrusive(op1->Type()->Yield())); else ExprError("Unknown MatchesIndex() return value"); @@ -2595,7 +2595,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const auto v_result = make_intrusive(Type()->AsVectorType()); // Booleans select each element (or not). - if ( IsBool(v_v2->Type()->YieldType()->Tag()) ) + if ( IsBool(v_v2->Type()->Yield()->Tag()) ) { if ( v_v1->Size() != v_v2->Size() ) { @@ -3343,7 +3343,7 @@ VectorConstructorExpr::VectorConstructorExpr(IntrusivePtr constructor_ } if ( ! check_and_promote_exprs_to_type(op->AsListExpr(), - type->AsVectorType()->YieldType()) ) + type->AsVectorType()->Yield().get()) ) ExprError("inconsistent types in vector constructor"); } @@ -3383,7 +3383,7 @@ IntrusivePtr VectorConstructorExpr::InitVal(const BroType* t, IntrusivePtr< loop_over_list(exprs, i) { Expr* e = exprs[i]; - auto v = check_and_promote(e->Eval(nullptr), t->YieldType(), true); + auto v = check_and_promote(e->Eval(nullptr), t->Yield().get(), true); if ( ! v || ! vec->Assign(i, std::move(v)) ) { @@ -3461,7 +3461,7 @@ ArithCoerceExpr::ArithCoerceExpr(IntrusivePtr arg_op, TypeTag t) if ( IsVector(bt) ) { SetType(make_intrusive(base_type(t))); - vbt = op->Type()->AsVectorType()->YieldType()->Tag(); + vbt = op->Type()->AsVectorType()->Yield()->Tag(); } else SetType(base_type(t)); @@ -3506,12 +3506,12 @@ IntrusivePtr ArithCoerceExpr::Fold(Val* v) const // invocation is being done per-element rather than on // the whole vector. Correct the type tag if necessary. if ( type->Tag() == TYPE_VECTOR ) - t = Type()->AsVectorType()->YieldType()->InternalType(); + t = Type()->AsVectorType()->Yield()->InternalType(); return FoldSingleVal(v, t); } - t = Type()->AsVectorType()->YieldType()->InternalType(); + t = Type()->AsVectorType()->Yield()->InternalType(); VectorVal* vv = v->AsVectorVal(); auto result = make_intrusive(Type()->AsVectorType()); @@ -4082,7 +4082,7 @@ CallExpr::CallExpr(IntrusivePtr arg_func, SetError("argument type mismatch in function call"); else { - BroType* yield = func_type->YieldType(); + const auto& yield = func_type->Yield(); if ( ! yield ) { @@ -4110,7 +4110,7 @@ CallExpr::CallExpr(IntrusivePtr arg_func, } } else - SetType({NewRef{}, yield}); + SetType(yield); // Check for call to built-ins that can be statically analyzed. IntrusivePtr func_val; @@ -4385,7 +4385,7 @@ EventExpr::EventExpr(const char* arg_name, IntrusivePtr arg_args) SetError("argument type mismatch in event invocation"); else { - if ( func_type->YieldType() ) + if ( func_type->Yield() ) { Error("function invoked as an event"); SetError(); @@ -4633,7 +4633,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co loop_over_list(exprs, i) { Expr* e = exprs[i]; - auto promoted_e = check_and_promote_expr(e, vec->Type()->AsVectorType()->YieldType()); + auto promoted_e = check_and_promote_expr(e, vec->Type()->AsVectorType()->Yield().get()); if ( promoted_e ) e = promoted_e.get(); diff --git a/src/Func.cc b/src/Func.cc index cc8e0b92f3..984e7991ce 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -245,7 +245,7 @@ std::pair Func::HandlePluginResult(std::pair plugin_resu case FUNC_FLAVOR_FUNCTION: { - BroType* yt = FType()->YieldType(); + const auto& yt = FType()->Yield(); if ( (! yt) || yt->Tag() == TYPE_VOID ) { @@ -423,7 +423,7 @@ IntrusivePtr BroFunc::Call(const zeek::Args& args, Frame* parent) const // Warn if the function returns something, but we returned from // the function without an explicit return, or without a value. - else if ( FType()->YieldType() && FType()->YieldType()->Tag() != TYPE_VOID && + else if ( FType()->Yield() && FType()->Yield()->Tag() != TYPE_VOID && (flow != FLOW_RETURN /* we fell off the end */ || ! result /* explicit return with no result */) && ! f->HasDelayed() ) diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index e561d28e0f..00b673253a 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -141,7 +141,7 @@ RuleConditionEval::RuleConditionEval(const char* func) // Validate argument quantity and type. FuncType* f = id->Type()->AsFuncType(); - if ( f->YieldType()->Tag() != TYPE_BOOL ) + if ( f->Yield()->Tag() != TYPE_BOOL ) rules_error("eval function type must yield a 'bool'", func); TypeList tl; diff --git a/src/Scope.cc b/src/Scope.cc index f8a6f6d8bf..be702afedd 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -34,7 +34,7 @@ Scope::Scope(IntrusivePtr id, attr_list* al) reporter->InternalError("bad scope id"); FuncType* ft = id->Type()->AsFuncType(); - return_type = {NewRef{}, ft->YieldType()}; + return_type = ft->Yield(); } } diff --git a/src/Stmt.cc b/src/Stmt.cc index b778e93ab1..420e27fe3e 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1148,18 +1148,17 @@ ForStmt::ForStmt(id_list* arg_loop_vars, if ( e->Type()->IsTable() ) { - BroType* yield_type = e->Type()->AsTableType()->YieldType(); + const auto& yield_type = e->Type()->AsTableType()->Yield(); // Verify value_vars type if its already been defined if ( value_var->Type() ) { - if ( ! same_type(value_var->Type(), yield_type) ) - value_var->Type()->Error("type clash in iteration", yield_type); + if ( ! same_type(value_var->Type(), yield_type.get()) ) + value_var->Type()->Error("type clash in iteration", yield_type.get()); } else { - add_local(value_var, {NewRef{}, yield_type}, INIT_NONE, - nullptr, nullptr, VAR_REGULAR); + add_local(value_var, yield_type, INIT_NONE, nullptr, nullptr, VAR_REGULAR); } } else @@ -1424,7 +1423,7 @@ ReturnStmt::ReturnStmt(IntrusivePtr arg_e) } FuncType* ft = s->ScopeID()->Type()->AsFuncType(); - BroType* yt = ft->YieldType(); + const auto& yt = ft->Yield(); if ( s->ScopeID()->DoInferReturnType() ) { @@ -1449,7 +1448,7 @@ ReturnStmt::ReturnStmt(IntrusivePtr arg_e) else { - auto promoted_e = check_and_promote_expr(e.get(), yt); + auto promoted_e = check_and_promote_expr(e.get(), yt.get()); if ( promoted_e ) e = std::move(promoted_e); diff --git a/src/Type.cc b/src/Type.cc index d4cbfd0f15..0fcbd5bf58 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -109,9 +109,10 @@ int BroType::MatchesIndex(ListExpr* const index) const return DOES_NOT_MATCH_INDEX; } -BroType* BroType::YieldType() +const IntrusivePtr& BroType::Yield() const { - return nullptr; + static IntrusivePtr nil; + return nil; } bool BroType::HasField(const char* /* field */) const @@ -234,16 +235,6 @@ int IndexType::MatchesIndex(ListExpr* const index) const MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX; } -BroType* IndexType::YieldType() - { - return yield_type.get(); - } - -const BroType* IndexType::YieldType() const - { - return yield_type.get(); - } - void IndexType::Describe(ODesc* d) const { BroType::Describe(d); @@ -481,16 +472,6 @@ string FuncType::FlavorString() const FuncType::~FuncType() = default; -BroType* FuncType::YieldType() - { - return yield.get(); - } - -const BroType* FuncType::YieldType() const - { - return yield.get(); - } - int FuncType::MatchesIndex(ListExpr* const index) const { return check_and_promote_args(index, args.get()) ? @@ -785,7 +766,7 @@ static string container_type_name(const BroType* ft) if ( ft->Tag() == TYPE_RECORD ) s = "record " + ft->GetName(); else if ( ft->Tag() == TYPE_VECTOR ) - s = "vector of " + container_type_name(ft->YieldType()); + s = "vector of " + container_type_name(ft->Yield().get()); else if ( ft->Tag() == TYPE_TABLE ) { if ( ft->IsSet() ) @@ -802,10 +783,10 @@ static string container_type_name(const BroType* ft) s += container_type_name(tl[i].get()); } s += "]"; - if ( ft->YieldType() ) + if ( ft->Yield() ) { s += " of "; - s += container_type_name(ft->YieldType()); + s += container_type_name(ft->Yield().get()); } } else @@ -1070,11 +1051,6 @@ FileType::FileType(IntrusivePtr yield_type) FileType::~FileType() = default; -BroType* FileType::YieldType() - { - return yield.get(); - } - void FileType::Describe(ODesc* d) const { if ( d->IsReadable() ) @@ -1358,33 +1334,16 @@ IntrusivePtr VectorType::ShallowClone() VectorType::~VectorType() = default; -BroType* VectorType::YieldType() +const IntrusivePtr& VectorType::Yield() const { // Work around the fact that we use void internally to mark a vector // as being unspecified. When looking at its yield type, we need to // return any as that's what other code historically expects for type // comparisions. if ( IsUnspecifiedVector() ) - return ::base_type(TYPE_ANY).get(); + return ::base_type(TYPE_ANY); - return yield_type.get(); - } - -const BroType* VectorType::YieldType() const - { - // Work around the fact that we use void internally to mark a vector - // as being unspecified. When looking at its yield type, we need to - // return any as that's what other code historically expects for type - // comparisions. - if ( IsUnspecifiedVector() ) - { - auto ret = ::base_type(TYPE_ANY); - assert(ret); - // release, because this won't be held by anyone. - return ret.release(); - } - - return yield_type.get(); + return yield_type; } int VectorType::MatchesIndex(ListExpr* const index) const @@ -1397,8 +1356,8 @@ int VectorType::MatchesIndex(ListExpr* const index) const if ( el.length() == 2 ) return MATCHES_INDEX_VECTOR; else if ( el[0]->Type()->Tag() == TYPE_VECTOR ) - return (IsIntegral(el[0]->Type()->YieldType()->Tag()) || - IsBool(el[0]->Type()->YieldType()->Tag())) ? + return (IsIntegral(el[0]->Type()->Yield()->Tag()) || + IsBool(el[0]->Type()->Yield()->Tag())) ? MATCHES_INDEX_VECTOR : DOES_NOT_MATCH_INDEX; else return (IsIntegral(el[0]->Type()->Tag()) || @@ -1528,8 +1487,8 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re return false; } - const BroType* y1 = t1->YieldType(); - const BroType* y2 = t2->YieldType(); + const BroType* y1 = t1->Yield().get(); + const BroType* y2 = t2->Yield().get(); if ( y1 || y2 ) { @@ -1548,10 +1507,10 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re if ( ft1->Flavor() != ft2->Flavor() ) return false; - if ( t1->YieldType() || t2->YieldType() ) + if ( t1->Yield() || t2->Yield() ) { - if ( ! t1->YieldType() || ! t2->YieldType() || - ! same_type(t1->YieldType(), t2->YieldType(), is_init, match_record_field_names) ) + if ( ! t1->Yield() || ! t2->Yield() || + ! same_type(t1->Yield().get(), t2->Yield().get(), is_init, match_record_field_names) ) return false; } @@ -1596,7 +1555,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re case TYPE_VECTOR: case TYPE_FILE: - return same_type(t1->YieldType(), t2->YieldType(), is_init, match_record_field_names); + return same_type(t1->Yield().get(), t2->Yield().get(), is_init, match_record_field_names); case TYPE_OPAQUE: { @@ -1848,8 +1807,8 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) tl3->Append(std::move(tl3_i)); } - const BroType* y1 = t1->YieldType(); - const BroType* y2 = t2->YieldType(); + const BroType* y1 = t1->Yield().get(); + const BroType* y2 = t2->Yield().get(); IntrusivePtr y3; if ( y1 || y2 ) @@ -1882,8 +1841,8 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) const FuncType* ft1 = (const FuncType*) t1; const FuncType* ft2 = (const FuncType*) t1; auto args = cast_intrusive(merge_types(ft1->Args(), ft2->Args())); - auto yield = t1->YieldType() ? - merge_types(t1->YieldType(), t2->YieldType()) : nullptr; + auto yield = t1->Yield() ? + merge_types(t1->Yield().get(), t2->Yield().get()) : nullptr; return make_intrusive(std::move(args), std::move(yield), ft1->Flavor()); @@ -1967,22 +1926,22 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) } case TYPE_VECTOR: - if ( ! same_type(t1->YieldType(), t2->YieldType()) ) + if ( ! same_type(t1->Yield().get(), t2->Yield().get()) ) { t1->Error("incompatible types", t2); return nullptr; } - return make_intrusive(merge_types(t1->YieldType(), t2->YieldType())); + return make_intrusive(merge_types(t1->Yield().get(), t2->Yield().get())); case TYPE_FILE: - if ( ! same_type(t1->YieldType(), t2->YieldType()) ) + if ( ! same_type(t1->Yield().get(), t2->Yield().get()) ) { t1->Error("incompatible types", t2); return nullptr; } - return make_intrusive(merge_types(t1->YieldType(), t2->YieldType())); + return make_intrusive(merge_types(t1->Yield().get(), t2->Yield().get())); case TYPE_UNION: reporter->InternalError("union type in merge_types()"); diff --git a/src/Type.h b/src/Type.h index d8c24e365a..c215603c82 100644 --- a/src/Type.h +++ b/src/Type.h @@ -171,9 +171,14 @@ public: // Returns the type yielded by this type. For example, if // this type is a table[string] of port, then returns the "port" // type. Returns nil if this is not an index type. - virtual BroType* YieldType(); + virtual const IntrusivePtr& Yield() const; + + [[deprecated("Remove in v4.1. Use Yield() instead.")]] + virtual BroType* YieldType() + { return Yield().get(); } + [[deprecated("Remove in v4.1. Use Yield() instead.")]] virtual const BroType* YieldType() const - { return ((BroType*) this)->YieldType(); } + { return Yield().get(); } // Returns true if this type is a record and contains the // given field, false otherwise. @@ -307,12 +312,12 @@ public: bool IsSet() const { - return tag == TYPE_TABLE && (YieldType() == nullptr); + return tag == TYPE_TABLE && ! Yield(); } bool IsTable() const { - return tag == TYPE_TABLE && (YieldType() != nullptr); + return tag == TYPE_TABLE && Yield(); } BroType* Ref() { ::Ref(this); return this; } @@ -398,8 +403,8 @@ public: const std::vector>& IndexTypes() const { return indices->Types(); } - BroType* YieldType() override; - const BroType* YieldType() const override; + const IntrusivePtr& Yield() const override + { return yield_type; } void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool roles_only = false) const override; @@ -469,8 +474,10 @@ public: ~FuncType() override; RecordType* Args() const { return args.get(); } - BroType* YieldType() override; - const BroType* YieldType() const override; + + const IntrusivePtr& Yield() const override + { return yield; } + void SetYieldType(IntrusivePtr arg_yield) { yield = std::move(arg_yield); } function_flavor Flavor() const { return flavor; } std::string FlavorString() const; @@ -646,7 +653,8 @@ public: IntrusivePtr ShallowClone() override { return make_intrusive(yield); } ~FileType() override; - BroType* YieldType() override; + const IntrusivePtr& Yield() const override + { return yield; } void Describe(ODesc* d) const override; @@ -729,8 +737,8 @@ public: explicit VectorType(IntrusivePtr t); IntrusivePtr ShallowClone() override; ~VectorType() override; - BroType* YieldType() override; - const BroType* YieldType() const override; + + const IntrusivePtr& Yield() const override; int MatchesIndex(ListExpr* index) const override; diff --git a/src/Val.cc b/src/Val.cc index 8d1a1707e7..cf76a1771f 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1348,7 +1348,7 @@ static void find_nested_record_types(BroType* t, std::set* found) return; case TYPE_TABLE: find_nested_record_types(t->AsTableType()->Indices(), found); - find_nested_record_types(t->AsTableType()->YieldType(), found); + find_nested_record_types(t->AsTableType()->Yield().get(), found); return; case TYPE_LIST: { @@ -1358,10 +1358,10 @@ static void find_nested_record_types(BroType* t, std::set* found) return; case TYPE_FUNC: find_nested_record_types(t->AsFuncType()->Args(), found); - find_nested_record_types(t->AsFuncType()->YieldType(), found); + find_nested_record_types(t->AsFuncType()->Yield().get(), found); return; case TYPE_VECTOR: - find_nested_record_types(t->AsVectorType()->YieldType(), found); + find_nested_record_types(t->AsVectorType()->Yield().get(), found); return; case TYPE_TYPE: find_nested_record_types(t->AsTypeType()->Type(), found); @@ -1439,7 +1439,7 @@ int TableVal::RecursiveSize() const int n = AsTable()->Length(); if ( Type()->IsSet() || - const_cast(Type()->AsTableType())->YieldType()->Tag() + const_cast(Type()->AsTableType())->Yield()->Tag() != TYPE_TABLE ) return n; @@ -1809,11 +1809,11 @@ IntrusivePtr TableVal::Default(Val* index) if ( ! def_val ) { - BroType* ytype = Type()->YieldType(); + const auto& ytype = Type()->Yield(); BroType* dtype = def_attr->AttrExpr()->Type(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype, ytype) && + ! same_type(dtype, ytype.get()) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) { @@ -1834,7 +1834,7 @@ IntrusivePtr TableVal::Default(Val* index) } if ( def_val->Type()->Tag() != TYPE_FUNC || - same_type(def_val->Type(), Type()->YieldType()) ) + same_type(def_val->Type(), Type()->Yield().get()) ) { if ( def_attr->AttrExpr()->IsConst() ) return def_val; @@ -2305,11 +2305,11 @@ void TableVal::InitDefaultFunc(Frame* f) if ( ! def_attr ) return; - BroType* ytype = Type()->YieldType(); + const auto& ytype = Type()->Yield(); BroType* dtype = def_attr->AttrExpr()->Type(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype, ytype) && + ! same_type(dtype, ytype.get()) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) return; // TableVal::Default will handle this. @@ -3001,7 +3001,7 @@ IntrusivePtr VectorVal::SizeVal() const bool VectorVal::Assign(unsigned int index, IntrusivePtr element) { if ( element && - ! same_type(element->Type(), vector_type->YieldType(), false) ) + ! same_type(element->Type(), vector_type->Yield().get(), false) ) return false; Val* val_at_index = nullptr; @@ -3042,7 +3042,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, bool VectorVal::Insert(unsigned int index, Val* element) { if ( element && - ! same_type(element->Type(), vector_type->YieldType(), false) ) + ! same_type(element->Type(), vector_type->Yield().get(), false) ) { Unref(element); return false; diff --git a/src/Var.cc b/src/Var.cc index 33cbc7916e..a9881b6c3b 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -459,7 +459,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, { if ( flavor == FUNC_FLAVOR_EVENT ) { - const BroType* yt = t->YieldType(); + const auto& yt = t->Yield(); if ( yt && yt->Tag() != TYPE_VOID ) id->Error("event cannot yield a value", t.get()); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 2e405e1f1e..cbed055db3 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -314,7 +314,7 @@ struct val_converter { } auto value_val = bro_broker::data_to_val(move(item.second), - tt->YieldType()); + tt->Yield().get()); if ( ! value_val ) return nullptr; @@ -334,7 +334,7 @@ struct val_converter { for ( auto& item : a ) { - auto item_val = bro_broker::data_to_val(move(item), vt->YieldType()); + auto item_val = bro_broker::data_to_val(move(item), vt->Yield().get()); if ( ! item_val ) return nullptr; @@ -667,7 +667,7 @@ struct type_checker { return false; } - if ( ! data_type_check(item.second, tt->YieldType()) ) + if ( ! data_type_check(item.second, tt->Yield().get()) ) return false; } @@ -682,7 +682,7 @@ struct type_checker { for ( auto& item : a ) { - if ( ! data_type_check(item, vt->YieldType()) ) + if ( ! data_type_check(item, vt->Yield().get()) ) return false; } diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 766a0c559a..a72f7a5894 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -522,13 +522,13 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( val ) { - const BroType* table_yield = dst->Type()->AsTableType()->YieldType(); + const auto& table_yield = dst->Type()->AsTableType()->Yield(); const BroType* compare_type = val.get(); if ( want_record->InternalInt() == 0 ) compare_type = val->GetFieldType(0).get(); - if ( ! same_type(table_yield, compare_type) ) + if ( ! same_type(table_yield.get(), compare_type) ) { ODesc desc1; ODesc desc2; @@ -821,7 +821,7 @@ bool Manager::IsCompatibleType(BroType* t, bool atomic_only) if ( atomic_only ) return false; - return IsCompatibleType(t->AsVectorType()->YieldType(), true); + return IsCompatibleType(t->AsVectorType()->Yield().get(), true); } default: @@ -945,7 +945,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, st = rec->GetFieldType(i)->AsSetType()->Indices()->GetPureType()->Tag(); else if ( ty == TYPE_VECTOR ) - st = rec->GetFieldType(i)->AsVectorType()->YieldType()->Tag(); + st = rec->GetFieldType(i)->AsVectorType()->Yield()->Tag(); else if ( ty == TYPE_PORT && rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN) ) @@ -2354,16 +2354,14 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ case TYPE_VECTOR: { // all entries have to have the same type... - BroType* type = request_type->AsVectorType()->YieldType(); - VectorType* vt = new VectorType({NewRef{}, type}); - VectorVal* v = new VectorVal(vt); - for ( int j = 0; j < val->val.vector_val.size; j++ ) - { - v->Assign(j, ValueToVal(i, val->val.vector_val.vals[j], type, have_error)); - } + const auto& type = request_type->AsVectorType()->Yield(); + auto vt = make_intrusive(type); + auto v = make_intrusive(vt.get()); - Unref(vt); - return v; + for ( int j = 0; j < val->val.vector_val.size; j++ ) + v->Assign(j, ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error)); + + return v.release(); } case TYPE_ENUM: { diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 22433453fe..cc2866f63d 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -47,7 +47,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) if ( primary == TYPE_TABLE ) secondary = id->Type()->AsSetType()->Indices()->GetPureType()->Tag(); else if ( primary == TYPE_VECTOR ) - secondary = id->Type()->AsVectorType()->YieldType()->Tag(); + secondary = id->Type()->AsVectorType()->Yield()->Tag(); option_types[id->Name()] = std::make_tuple(primary, secondary); } diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 44327ee43e..2a190ba53a 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -401,7 +401,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, if ( j < num_ext_fields ) { i = j; - rtype = filter->ext_func->FType()->YieldType()->AsRecordType(); + rtype = filter->ext_func->FType()->Yield()->AsRecordType(); } else { @@ -520,7 +520,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, st = t->AsSetType()->Indices()->GetPureType()->Tag(); else if ( t->Tag() == TYPE_VECTOR ) - st = t->AsVectorType()->YieldType()->Tag(); + st = t->AsVectorType()->Yield()->Tag(); bool optional = rtype->FieldDecl(i)->FindAttr(ATTR_OPTIONAL); @@ -587,18 +587,18 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) filter->num_ext_fields = 0; if ( filter->ext_func ) { - if ( filter->ext_func->FType()->YieldType()->Tag() == TYPE_RECORD ) + if ( filter->ext_func->FType()->Yield()->Tag() == TYPE_RECORD ) { - filter->num_ext_fields = filter->ext_func->FType()->YieldType()->AsRecordType()->NumFields(); + filter->num_ext_fields = filter->ext_func->FType()->Yield()->AsRecordType()->NumFields(); } - else if ( filter->ext_func->FType()->YieldType()->Tag() == TYPE_VOID ) + else if ( filter->ext_func->FType()->Yield()->Tag() == TYPE_VOID ) { // This is a special marker for the default no-implementation // of the ext_func and we'll allow it to slide. } else { - reporter->Error("Return value of log_ext is not a record (got %s)", type_name(filter->ext_func->FType()->YieldType()->Tag())); + reporter->Error("Return value of log_ext is not a record (got %s)", type_name(filter->ext_func->FType()->Yield()->Tag())); delete filter; return false; } @@ -1038,7 +1038,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) { lval->val.vector_val.vals[i] = ValToLogVal(vec->Lookup(i), - vec->Type()->YieldType()); + vec->Type()->Yield().get()); } break; diff --git a/src/option.bif b/src/option.bif index dd534811a8..2105054cfc 100644 --- a/src/option.bif +++ b/src/option.bif @@ -199,10 +199,10 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( ! same_type(on_change->Type()->AsFuncType()->YieldType(), i->Type()) ) + if ( ! same_type(on_change->Type()->AsFuncType()->Yield().get(), i->Type()) ) { builtin_error(fmt("Passed function needs to return type '%s' for ID '%s'; got '%s'", - type_name(i->Type()->Tag()), ID->CheckString(), type_name(on_change->Type()->AsFuncType()->YieldType()->Tag()))); + type_name(i->Type()->Tag()), ID->CheckString(), type_name(on_change->Type()->AsFuncType()->Yield()->Tag()))); return val_mgr->False(); } diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index 2d39fecf51..189b40798a 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -154,7 +154,7 @@ bool Value::IsCompatibleType(BroType* t, bool atomic_only) if ( atomic_only ) return false; - return IsCompatibleType(t->AsVectorType()->YieldType(), true); + return IsCompatibleType(t->AsVectorType()->Yield().get(), true); } default: diff --git a/src/zeek.bif b/src/zeek.bif index bea7c94761..fc14bbb892 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -804,7 +804,7 @@ function sha256_hash_finish%(handle: opaque of sha256%): string function paraglob_init%(v: any%) : opaque of paraglob %{ if ( v->Type()->Tag() != TYPE_VECTOR || - v->Type()->YieldType()->Tag() != TYPE_STRING ) + v->Type()->Yield()->Tag() != TYPE_STRING ) { // reporter->Error will throw an exception. reporter->Error("paraglob requires a vector of strings for initialization."); @@ -1281,7 +1281,7 @@ function resize%(aggr: any, newsize: count%) : count function any_set%(v: any%) : bool %{ if ( v->Type()->Tag() != TYPE_VECTOR || - v->Type()->YieldType()->Tag() != TYPE_BOOL ) + v->Type()->Yield()->Tag() != TYPE_BOOL ) { builtin_error("any_set() requires vector of bool"); return val_mgr->False(); @@ -1310,7 +1310,7 @@ function any_set%(v: any%) : bool function all_set%(v: any%) : bool %{ if ( v->Type()->Tag() != TYPE_VECTOR || - v->Type()->YieldType()->Tag() != TYPE_BOOL ) + v->Type()->Yield()->Tag() != TYPE_BOOL ) { builtin_error("all_set() requires vector of bool"); return val_mgr->False(); @@ -1408,7 +1408,7 @@ function sort%(v: any, ...%) : any return rval; } - BroType* elt_type = v->Type()->YieldType(); + const auto& elt_type = v->Type()->Yield(); Func* comp = 0; if ( @ARG@.size() > 2 ) @@ -1434,7 +1434,7 @@ function sort%(v: any, ...%) : any if ( comp ) { FuncType* comp_type = comp->FType()->AsFuncType(); - if ( comp_type->YieldType()->Tag() != TYPE_INT || + if ( comp_type->Yield()->Tag() != TYPE_INT || ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) { builtin_error("invalid comparison function in call to sort()"); @@ -1478,7 +1478,7 @@ function order%(v: any, ...%) : index_vec return result_v; } - BroType* elt_type = v->Type()->YieldType(); + const auto& elt_type = v->Type()->Yield(); Func* comp = 0; if ( @ARG@.size() > 2 ) @@ -1516,7 +1516,7 @@ function order%(v: any, ...%) : index_vec if ( comp ) { FuncType* comp_type = comp->FType()->AsFuncType(); - if ( comp_type->YieldType()->Tag() != TYPE_INT || + if ( comp_type->Yield()->Tag() != TYPE_INT || ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) { builtin_error("invalid comparison function in call to order()"); From 6e647416d577211f7f6b8419dba8f1e60bac5563 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 7 May 2020 20:07:46 -0700 Subject: [PATCH 026/151] Deprecate ID::AsType(), add ID::IsType() and ID::GetType() --- NEWS | 2 ++ src/Expr.cc | 10 +++++----- src/ID.h | 12 +++++++++++- src/OpaqueVal.cc | 5 ++--- src/Type.cc | 4 ++-- src/parse.y | 9 ++++----- src/supervisor/Supervisor.cc | 4 ++-- src/zeek.bif | 4 ++-- src/zeekygen/Manager.cc | 2 +- src/zeekygen/ScriptInfo.cc | 2 +- 10 files changed, 32 insertions(+), 22 deletions(-) diff --git a/NEWS b/NEWS index ff7b02f657..f3fd5eb603 100644 --- a/NEWS +++ b/NEWS @@ -153,6 +153,8 @@ Deprecated Functionality - ``BroType::YieldType()`` is deprecated, use ``BroType::Yield()``. +- ``ID::AsType()`` is deprecated, use ``ID::IsType()`` and ``ID::GetType()``. + Zeek 3.1.0 ========== diff --git a/src/Expr.cc b/src/Expr.cc index cff9cd0d08..fbd033d3da 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -218,8 +218,8 @@ NameExpr::NameExpr(IntrusivePtr arg_id, bool const_init) { in_const_init = const_init; - if ( id->AsType() ) - SetType(make_intrusive(IntrusivePtr{NewRef{}, id->AsType()})); + if ( id->IsType() ) + SetType(make_intrusive(IntrusivePtr{NewRef{}, id->Type()})); else SetType({NewRef{}, id->Type()}); @@ -232,8 +232,8 @@ IntrusivePtr NameExpr::Eval(Frame* f) const { IntrusivePtr v; - if ( id->AsType() ) - return make_intrusive(id->AsType(), true); + if ( id->IsType() ) + return make_intrusive(id->Type(), true); if ( id->IsGlobal() ) v = {NewRef{}, id->ID_Val()}; @@ -256,7 +256,7 @@ IntrusivePtr NameExpr::Eval(Frame* f) const IntrusivePtr NameExpr::MakeLvalue() { - if ( id->AsType() ) + if ( id->IsType() ) ExprError("Type name is not an lvalue"); if ( id->IsConst() && ! in_const_init ) diff --git a/src/ID.h b/src/ID.h index 3735e7a843..94b876dbd4 100644 --- a/src/ID.h +++ b/src/ID.h @@ -37,13 +37,23 @@ public: std::string ModuleName() const; void SetType(IntrusivePtr t); + BroType* Type() { return type.get(); } const BroType* Type() const { return type.get(); } - void MakeType() { is_type = true; } + const IntrusivePtr& GetType() const + { return type; } + + [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] BroType* AsType() { return is_type ? Type() : nullptr; } + [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] const BroType* AsType() const { return is_type ? Type() : nullptr; } + bool IsType() const + { return is_type; } + + void MakeType() { is_type = true; } + // If weak_ref is false, the Val is assumed to be already ref'ed // and will be deref'ed when the ID is deleted. // diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 2ae0b06455..392b3ed9c1 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -130,11 +130,10 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data) if ( ! id ) return nullptr; - BroType* t = id->AsType(); - if ( ! t ) + if ( ! id->IsType() ) return nullptr; - return t->Ref(); + return id->Type()->Ref(); } auto tag = caf::get_if(&(*v)[1]); diff --git a/src/Type.cc b/src/Type.cc index 0fcbd5bf58..877fa24340 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1766,12 +1766,12 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) // (potentially) avoiding a pitfall mentioned earlier about clones. auto id = global_scope()->Lookup(t1->GetName()); - if ( id && id->AsType() && id->AsType()->Tag() == TYPE_ENUM ) + if ( id && id->IsType() && id->Type()->Tag() == TYPE_ENUM ) // It should make most sense to return the real type here rather // than a copy since it may be redef'd later in parsing. If we // return a copy, then whoever is using this return value won't // actually see those changes from the redef. - return {NewRef{}, id->AsType()}; + return {NewRef{}, id->Type()}; std::string msg = fmt("incompatible enum types: '%s' and '%s'" " ('%s' enum type ID is invalid)", diff --git a/src/parse.y b/src/parse.y index 00f2e65874..fc556041ca 100644 --- a/src/parse.y +++ b/src/parse.y @@ -606,11 +606,10 @@ expr: { set_location(@1, @6); - BroType* ctor_type = 0; - - if ( $1->Tag() == EXPR_NAME && - (ctor_type = $1->AsNameExpr()->Id()->AsType()) ) + if ( $1->Tag() == EXPR_NAME && $1->AsNameExpr()->Id()->IsType() ) { + auto ctor_type = $1->AsNameExpr()->Id()->Type(); + switch ( ctor_type->Tag() ) { case TYPE_RECORD: { @@ -1007,7 +1006,7 @@ type: | resolve_id { - if ( ! $1 || ! ($$ = $1->AsType()) ) + if ( ! $1 || ! ($$ = $1->IsType() ? $1->Type() : nullptr) ) { NullStmt here; if ( $1 ) diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 6ae8038fcd..269b6576ea 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1171,7 +1171,7 @@ IntrusivePtr Supervisor::Node::ToRecord() const static IntrusivePtr supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role) { - static auto node_type = global_scope()->Lookup("Cluster::NodeType")->AsType()->AsEnumType(); + static auto node_type = global_scope()->Lookup("Cluster::NodeType")->Type()->AsEnumType(); switch ( role ) { case BifEnum::Supervisor::LOGGER: @@ -1192,7 +1192,7 @@ bool Supervisor::SupervisedNode::InitCluster() const if ( config.cluster.empty() ) return false; - auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->AsType()->AsRecordType(); + auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->Type()->AsRecordType(); auto cluster_nodes_id = global_scope()->Lookup("Cluster::nodes"); auto cluster_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger"); auto cluster_nodes = cluster_nodes_id->ID_Val()->AsTableVal(); diff --git a/src/zeek.bif b/src/zeek.bif index fc14bbb892..6ab3f39820 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -2003,14 +2003,14 @@ function record_fields%(rec: any%): record_field_table { auto id = global_scope()->Lookup(rec->AsStringVal()->ToStdString()); - if ( ! id || ! id->AsType() || id->AsType()->Tag() != TYPE_RECORD ) + if ( ! id || ! id->IsType() || id->Type()->Tag() != TYPE_RECORD ) { reporter->Error("record_fields string argument does not name a record type"); IntrusivePtr tt{NewRef{}, internal_type("record_field_table")->AsTableType()}; return make_intrusive(std::move(tt)); } - return id->AsType()->AsRecordType()->GetRecordFieldsVal(); + return id->Type()->AsRecordType()->GetRecordFieldsVal(); } return rec->GetRecordFields(); diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index 6636447516..47192cfd27 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -274,7 +274,7 @@ void Manager::StartType(IntrusivePtr id) static bool IsEnumType(ID* id) { - return id->AsType() ? id->AsType()->Tag() == TYPE_ENUM : false; + return id->IsType() ? id->Type()->Tag() == TYPE_ENUM : false; } void Manager::Identifier(IntrusivePtr id) diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index 532a6667ff..5b75415613 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -183,7 +183,7 @@ void ScriptInfo::DoInitPostScript() if ( ! zeekygen::is_public_api(id) ) continue; - if ( id->AsType() ) + if ( id->IsType() ) { types.push_back(info); DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a type", From 3f07c575239fd6c732f6a62fe6bed965af1fb201 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 7 May 2020 20:47:33 -0700 Subject: [PATCH 027/151] Deprecate ID::Type(), replace with GetType() --- NEWS | 2 ++ src/Debug.cc | 2 +- src/DebugCmds.cc | 2 +- src/EventHandler.cc | 4 +-- src/Expr.cc | 10 +++---- src/Func.cc | 4 +-- src/ID.cc | 10 +++---- src/ID.h | 6 ++-- src/OpaqueVal.cc | 2 +- src/RuleCondition.cc | 6 ++-- src/Scope.cc | 4 +-- src/Stmt.cc | 45 ++++++++++++++++-------------- src/Type.cc | 4 +-- src/Var.cc | 24 ++++++++-------- src/broker/Manager.cc | 4 +-- src/input/Manager.cc | 4 +-- src/input/readers/config/Config.cc | 12 ++++---- src/option.bif | 20 ++++++------- src/parse.y | 30 ++++++++++---------- src/supervisor/Supervisor.cc | 4 +-- src/zeek.bif | 6 ++-- src/zeekygen/IdentifierInfo.cc | 2 +- src/zeekygen/Manager.cc | 4 +-- src/zeekygen/ScriptInfo.cc | 6 ++-- 24 files changed, 111 insertions(+), 106 deletions(-) diff --git a/NEWS b/NEWS index f3fd5eb603..840e687988 100644 --- a/NEWS +++ b/NEWS @@ -155,6 +155,8 @@ Deprecated Functionality - ``ID::AsType()`` is deprecated, use ``ID::IsType()`` and ``ID::GetType()``. +- ``ID::Type()`` is deprecated, use ``ID::GetType()``. + Zeek 3.1.0 ========== diff --git a/src/Debug.cc b/src/Debug.cc index ef6a41f855..7136daf3cb 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -207,7 +207,7 @@ static void parse_function_name(vector& result, return; } - if ( ! id->Type()->AsFuncType() ) + if ( ! id->GetType()->AsFuncType() ) { debug_msg("Function %s not declared.\n", id->Name()); plr.type = plrUnknown; diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index e0d2cf843e..e36836e50a 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -65,7 +65,7 @@ void lookup_global_symbols_regex(const string& orig_regex, vector& matches, for ( const auto& sym : syms ) { ID* nextid = sym.second.get(); - if ( ! func_only || nextid->Type()->Tag() == TYPE_FUNC ) + if ( ! func_only || nextid->GetType()->Tag() == TYPE_FUNC ) if ( ! regexec (&re, nextid->Name(), 0, 0, 0) ) matches.push_back(nextid); } diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 4b8f2d11aa..4813e11f40 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -44,10 +44,10 @@ FuncType* EventHandler::FType(bool check_export) if ( ! id ) return nullptr; - if ( id->Type()->Tag() != TYPE_FUNC ) + if ( id->GetType()->Tag() != TYPE_FUNC ) return nullptr; - type = id->Type()->AsFuncType(); + type = id->GetType()->AsFuncType(); return type; } diff --git a/src/Expr.cc b/src/Expr.cc index fbd033d3da..223c27da2a 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -219,9 +219,9 @@ NameExpr::NameExpr(IntrusivePtr arg_id, bool const_init) in_const_init = const_init; if ( id->IsType() ) - SetType(make_intrusive(IntrusivePtr{NewRef{}, id->Type()})); + SetType(make_intrusive(id->GetType())); else - SetType({NewRef{}, id->Type()}); + SetType(id->GetType()); EventHandler* h = event_registry->Lookup(id->Name()); if ( h ) @@ -233,7 +233,7 @@ IntrusivePtr NameExpr::Eval(Frame* f) const IntrusivePtr v; if ( id->IsType() ) - return make_intrusive(id->Type(), true); + return make_intrusive(id->GetType().get(), true); if ( id->IsGlobal() ) v = {NewRef{}, id->ID_Val()}; @@ -4262,7 +4262,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, ingredients = std::move(arg_ing); outer_ids = std::move(arg_outer_ids); - SetType({NewRef{}, ingredients->id->Type()}); + SetType(ingredients->id->GetType()); // Install a dummy version of the function globally for use only // when broker provides a closure. @@ -4307,7 +4307,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, auto v = make_intrusive(dummy_func); Unref(dummy_func); id->SetVal(std::move(v)); - id->SetType({NewRef{}, ingredients->id->Type()}); + id->SetType(ingredients->id->GetType()); id->SetConst(); } diff --git a/src/Func.cc b/src/Func.cc index 984e7991ce..b3fe426b9a 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -271,7 +271,7 @@ BroFunc::BroFunc(ID* arg_id, IntrusivePtr arg_body, id_list* aggr_inits, : Func(BRO_FUNC) { name = arg_id->Name(); - type = {NewRef{}, arg_id->Type()}; + type = arg_id->GetType(); frame_size = arg_frame_size; if ( arg_body ) @@ -593,7 +593,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, if ( id->HasVal() ) reporter->InternalError("built-in function %s multiply defined", Name()); - type = {NewRef{}, id->Type()}; + type = id->GetType(); id->SetVal(make_intrusive(this)); } diff --git a/src/ID.cc b/src/ID.cc index f77c693aaa..0ddab99d92 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -167,7 +167,7 @@ void ID::UpdateValAttrs() if ( val && val->Type()->Tag() == TYPE_FILE ) val->AsFile()->SetAttrs(attrs.get()); - if ( Type()->Tag() == TYPE_FUNC ) + if ( GetType()->Tag() == TYPE_FUNC ) { Attr* attr = attrs->FindAttr(ATTR_ERROR_HANDLER); @@ -175,13 +175,13 @@ void ID::UpdateValAttrs() event_registry->SetErrorHandler(Name()); } - if ( Type()->Tag() == TYPE_RECORD ) + if ( GetType()->Tag() == TYPE_RECORD ) { Attr* attr = attrs->FindAttr(ATTR_LOG); if ( attr ) { // Apply &log to all record fields. - RecordType* rt = Type()->AsRecordType(); + RecordType* rt = GetType()->AsRecordType(); for ( int i = 0; i < rt->NumFields(); ++i ) { TypeDecl* fd = rt->FieldDecl(i); @@ -211,7 +211,7 @@ void ID::MakeDeprecated(IntrusivePtr deprecation) return; attr_list* attr = new attr_list{new Attr(ATTR_DEPRECATED, std::move(deprecation))}; - AddAttrs(make_intrusive(attr, IntrusivePtr{NewRef{}, Type()}, false, IsGlobal())); + AddAttrs(make_intrusive(attr, GetType(), false, IsGlobal())); } std::string ID::GetDeprecationWarning() const @@ -261,7 +261,7 @@ void ID::SetOption() if ( ! IsRedefinable() ) { attr_list* attr = new attr_list{new Attr(ATTR_REDEF)}; - AddAttrs(make_intrusive(attr, IntrusivePtr{NewRef{}, Type()}, false, IsGlobal())); + AddAttrs(make_intrusive(attr, GetType(), false, IsGlobal())); } } diff --git a/src/ID.h b/src/ID.h index 94b876dbd4..7324032c3c 100644 --- a/src/ID.h +++ b/src/ID.h @@ -38,16 +38,18 @@ public: void SetType(IntrusivePtr t); + [[deprecated("Remove in v4.1. Use GetType().")]] BroType* Type() { return type.get(); } + [[deprecated("Remove in v4.1. Use GetType().")]] const BroType* Type() const { return type.get(); } const IntrusivePtr& GetType() const { return type; } [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] - BroType* AsType() { return is_type ? Type() : nullptr; } + BroType* AsType() { return is_type ? GetType().get() : nullptr; } [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] - const BroType* AsType() const { return is_type ? Type() : nullptr; } + const BroType* AsType() const { return is_type ? GetType().get() : nullptr; } bool IsType() const { return is_type; } diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 392b3ed9c1..14867819e8 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -133,7 +133,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data) if ( ! id->IsType() ) return nullptr; - return id->Type()->Ref(); + return id->GetType()->Ref(); } auto tag = caf::get_if(&(*v)[1]); diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 00b673253a..ff43f0ecaf 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -136,10 +136,10 @@ RuleConditionEval::RuleConditionEval(const char* func) return; } - if ( id->Type()->Tag() == TYPE_FUNC ) + if ( id->GetType()->Tag() == TYPE_FUNC ) { // Validate argument quantity and type. - FuncType* f = id->Type()->AsFuncType(); + FuncType* f = id->GetType()->AsFuncType(); if ( f->Yield()->Tag() != TYPE_BOOL ) rules_error("eval function type must yield a 'bool'", func); @@ -163,7 +163,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, return false; } - if ( id->Type()->Tag() != TYPE_FUNC ) + if ( id->GetType()->Tag() != TYPE_FUNC ) return id->ID_Val()->AsBool(); // Call function with a signature_state value as argument. diff --git a/src/Scope.cc b/src/Scope.cc index be702afedd..79b7f46ced 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -26,14 +26,14 @@ Scope::Scope(IntrusivePtr id, attr_list* al) if ( id ) { - BroType* id_type = scope_id->Type(); + const auto& id_type = scope_id->GetType(); if ( id_type->Tag() == TYPE_ERROR ) return; else if ( id_type->Tag() != TYPE_FUNC ) reporter->InternalError("bad scope id"); - FuncType* ft = id->Type()->AsFuncType(); + FuncType* ft = id->GetType()->AsFuncType(); return_type = ft->Yield(); } } diff --git a/src/Stmt.cc b/src/Stmt.cc index 420e27fe3e..8879921fbf 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -190,7 +190,7 @@ static IntrusivePtr lookup_enum_val(const char* module_name, const char assert(id); assert(id->IsEnumConst()); - EnumType* et = id->Type()->AsEnumType(); + EnumType* et = id->GetType()->AsEnumType(); int index = et->Lookup(module_name, name); assert(index >= 0); @@ -530,7 +530,7 @@ void Case::Describe(ODesc* d) const d->SP(); d->Add("type"); d->SP(); - t[i]->Type()->Describe(d); + t[i]->GetType()->Describe(d); if ( t[i]->Name() ) { @@ -677,9 +677,9 @@ SwitchStmt::SwitchStmt(IntrusivePtr index, case_list* arg_cases) for ( const auto& t : *tl ) { - BroType* ct = t->Type(); + const auto& ct = t->GetType(); - if ( ! can_cast_value_to_type(e->Type(), ct) ) + if ( ! can_cast_value_to_type(e->Type(), ct.get()) ) { c->Error("cannot cast switch expression to case type"); continue; @@ -744,7 +744,7 @@ bool SwitchStmt::AddCaseLabelTypeMapping(ID* t, int idx) { for ( auto i : case_label_type_list ) { - if ( same_type(i.first->Type(), t->Type()) ) + if ( same_type(i.first->GetType().get(), t->GetType().get()) ) return false; } @@ -782,9 +782,9 @@ std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const for ( auto i : case_label_type_list ) { auto id = i.first; - auto type = id->Type(); + const auto& type = id->GetType(); - if ( can_cast_value_to_type(v, type) ) + if ( can_cast_value_to_type(v, type.get()) ) { label_idx = i.second; label_id = id; @@ -815,7 +815,7 @@ IntrusivePtr SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) con if ( matching_id ) { - auto cv = cast_value_to_type(v, matching_id->Type()); + auto cv = cast_value_to_type(v, matching_id->GetType().get()); f->SetElement(matching_id, cv.release()); } @@ -1080,17 +1080,18 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) for ( auto i = 0u; i < indices.size(); i++ ) { const auto& ind_type = indices[i]; + const auto& lv = (*loop_vars)[i]; + const auto& lvt = lv->GetType(); - if ( (*loop_vars)[i]->Type() ) + if ( lvt ) { - if ( ! same_type((*loop_vars)[i]->Type(), ind_type.get()) ) - (*loop_vars)[i]->Type()->Error("type clash in iteration", - ind_type.get()); + if ( ! same_type(lvt.get(), ind_type.get()) ) + lvt->Error("type clash in iteration", ind_type.get()); } else { - add_local({NewRef{}, (*loop_vars)[i]}, ind_type, INIT_NONE, + add_local({NewRef{}, lv}, ind_type, INIT_NONE, nullptr, nullptr, VAR_REGULAR); } } @@ -1104,7 +1105,8 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) return; } - BroType* t = (*loop_vars)[0]->Type(); + const auto& t = (*loop_vars)[0]->GetType(); + if ( ! t ) add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT), INIT_NONE, nullptr, nullptr, VAR_REGULAR); @@ -1124,7 +1126,8 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) return; } - BroType* t = (*loop_vars)[0]->Type(); + const auto& t = (*loop_vars)[0]->GetType(); + if ( ! t ) add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_STRING), @@ -1151,10 +1154,10 @@ ForStmt::ForStmt(id_list* arg_loop_vars, const auto& yield_type = e->Type()->AsTableType()->Yield(); // Verify value_vars type if its already been defined - if ( value_var->Type() ) + if ( value_var->GetType() ) { - if ( ! same_type(value_var->Type(), yield_type.get()) ) - value_var->Type()->Error("type clash in iteration", yield_type.get()); + if ( ! same_type(value_var->GetType().get(), yield_type.get()) ) + value_var->GetType()->Error("type clash in iteration", yield_type.get()); } else { @@ -1422,7 +1425,7 @@ ReturnStmt::ReturnStmt(IntrusivePtr arg_e) return; } - FuncType* ft = s->ScopeID()->Type()->AsFuncType(); + FuncType* ft = s->ScopeID()->GetType()->AsFuncType(); const auto& yt = ft->Yield(); if ( s->ScopeID()->DoInferReturnType() ) @@ -1653,7 +1656,7 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const for ( const auto& aggr : *inits ) { - BroType* t = aggr->Type(); + const auto& t = aggr->GetType(); Val* v = nullptr; @@ -1665,7 +1668,7 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const v = new VectorVal(t->AsVectorType()); break; case TYPE_TABLE: - v = new TableVal({NewRef{}, t->AsTableType()}, {NewRef{}, aggr->Attrs()}); + v = new TableVal(cast_intrusive(t), {NewRef{}, aggr->Attrs()}); break; default: break; diff --git a/src/Type.cc b/src/Type.cc index 877fa24340..1c8176ddcf 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1766,12 +1766,12 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) // (potentially) avoiding a pitfall mentioned earlier about clones. auto id = global_scope()->Lookup(t1->GetName()); - if ( id && id->IsType() && id->Type()->Tag() == TYPE_ENUM ) + if ( id && id->IsType() && id->GetType()->Tag() == TYPE_ENUM ) // It should make most sense to return the real type here rather // than a copy since it may be redef'd later in parsing. If we // return a copy, then whoever is using this return value won't // actually see those changes from the redef. - return {NewRef{}, id->Type()}; + return id->GetType(); std::string msg = fmt("incompatible enum types: '%s' and '%s'" " ('%s' enum type ID is invalid)", diff --git a/src/Var.cc b/src/Var.cc index a9881b6c3b..cf79a6ba4d 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -32,7 +32,7 @@ static IntrusivePtr init_val(Expr* init, const BroType* t, static bool add_prototype(ID* id, BroType* t, attr_list* attrs, const IntrusivePtr& init) { - if ( ! IsFunc(id->Type()->Tag()) ) + if ( ! IsFunc(id->GetType()->Tag()) ) return false; if ( ! IsFunc(t->Tag()) ) @@ -41,7 +41,7 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs, return false; } - auto canon_ft = id->Type()->AsFuncType(); + auto canon_ft = id->GetType()->AsFuncType(); auto alt_ft = t->AsFuncType(); if ( canon_ft->Flavor() != alt_ft->Flavor() ) @@ -110,9 +110,9 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, IntrusivePtr init, attr_list* attr, decl_type dt, bool do_init) { - if ( id->Type() ) + if ( id->GetType() ) { - if ( id->IsRedefinable() || (! init && attr && ! IsFunc(id->Type()->Tag())) ) + if ( id->IsRedefinable() || (! init && attr && ! IsFunc(id->GetType()->Tag())) ) { BroObj* redef_obj = init ? (BroObj*) init.get() : (BroObj*) t.get(); if ( dt != VAR_REDEF ) @@ -121,7 +121,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, else if ( dt != VAR_REDEF || init || ! attr ) { - if ( IsFunc(id->Type()->Tag()) ) + if ( IsFunc(id->GetType()->Tag()) ) add_prototype(id, t.get(), attr, init); else id->Error("already defined", init.get()); @@ -132,17 +132,17 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, if ( dt == VAR_REDEF ) { - if ( ! id->Type() ) + if ( ! id->GetType() ) { id->Error("\"redef\" used but not previously defined"); return; } if ( ! t ) - t = {NewRef{}, id->Type()}; + t = id->GetType(); } - if ( id->Type() && id->Type()->Tag() != TYPE_ERROR ) + if ( id->GetType() && id->GetType()->Tag() != TYPE_ERROR ) { if ( dt != VAR_REDEF && (! init || ! do_init || (! t && ! (t = init_type(init.get())))) ) @@ -152,7 +152,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, } // Allow redeclaration in order to initialize. - if ( ! same_type(t.get(), id->Type()) ) + if ( ! same_type(t.get(), id->GetType().get()) ) { id->Error("redefinition changes type", init.get()); return; @@ -469,9 +469,9 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, std::optional prototype; - if ( id->Type() ) + if ( id->GetType() ) { - auto decl = id->Type()->AsFuncType(); + auto decl = id->GetType()->AsFuncType(); prototype = func_type_check(decl, t.get()); if ( prototype ) @@ -766,7 +766,7 @@ BroType* internal_type(const char* name) if ( ! id ) reporter->InternalError("internal type %s missing", name); - return id->Type(); + return id->GetType().get(); } Func* internal_func(const char* name) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 2929e5e168..9155dad4cd 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -1196,12 +1196,12 @@ bool Manager::ProcessIdentifierUpdate(broker::zeek::IdentifierUpdate iu) return false; } - auto val = data_to_val(std::move(id_value), id->Type()); + auto val = data_to_val(std::move(id_value), id->GetType().get()); if ( ! val ) { reporter->Error("Failed to receive ID with unsupported type: %s (%s)", - id_name.c_str(), type_name(id->Type()->Tag())); + id_name.c_str(), type_name(id->GetType()->Tag())); return false; } diff --git a/src/input/Manager.cc b/src/input/Manager.cc index a72f7a5894..d59c428033 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -2509,7 +2509,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co return nullptr; } - index_type = {NewRef{}, enum_id->Type()->AsEnumType()}; + index_type = enum_id->GetType(); } else index_type = base_type(stag); @@ -2572,7 +2572,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co return nullptr; } - EnumType* t = id->Type()->AsEnumType(); + EnumType* t = id->GetType()->AsEnumType(); int intval = t->Lookup(id->ModuleName(), id->Name()); if ( intval < 0 ) { diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index cc2866f63d..60437eb825 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -35,19 +35,19 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) if ( ! id->IsOption() ) continue; - if ( id->Type()->Tag() == TYPE_RECORD || - ! input::Manager::IsCompatibleType(id->Type()) ) + if ( id->GetType()->Tag() == TYPE_RECORD || + ! input::Manager::IsCompatibleType(id->GetType().get()) ) { - option_types[id->Name()] = std::make_tuple(TYPE_ERROR, id->Type()->Tag()); + option_types[id->Name()] = std::make_tuple(TYPE_ERROR, id->GetType()->Tag()); continue; } - TypeTag primary = id->Type()->Tag(); + TypeTag primary = id->GetType()->Tag(); TypeTag secondary = TYPE_VOID; if ( primary == TYPE_TABLE ) - secondary = id->Type()->AsSetType()->Indices()->GetPureType()->Tag(); + secondary = id->GetType()->AsSetType()->Indices()->GetPureType()->Tag(); else if ( primary == TYPE_VECTOR ) - secondary = id->Type()->AsVectorType()->Yield()->Tag(); + secondary = id->GetType()->AsVectorType()->Yield()->Tag(); option_types[id->Name()] = std::make_tuple(primary, secondary); } diff --git a/src/option.bif b/src/option.bif index 2105054cfc..016bcd993e 100644 --- a/src/option.bif +++ b/src/option.bif @@ -82,12 +82,12 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool if ( same_type(val->Type(), bro_broker::DataVal::ScriptDataType()) ) { auto dv = static_cast(val->AsRecordVal()->Lookup(0)); - auto val_from_data = dv->castTo(i->Type()); + auto val_from_data = dv->castTo(i->GetType().get()); if ( ! val_from_data ) { builtin_error(fmt("Incompatible type for set of ID '%s': got broker data '%s', need '%s'", - ID->CheckString(), dv->data.get_type_name(), type_name(i->Type()->Tag()))); + ID->CheckString(), dv->data.get_type_name(), type_name(i->GetType()->Tag()))); return val_mgr->False(); } @@ -95,22 +95,22 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool return val_mgr->Bool(rval); } - if ( ! same_type(i->Type(), val->Type()) ) + if ( ! same_type(i->GetType().get(), val->Type()) ) { - if ( i->Type()->Tag() == TYPE_TABLE && + if ( i->GetType()->Tag() == TYPE_TABLE && val->Type()->Tag() == TYPE_TABLE && val->Type()->AsTableType()->IsUnspecifiedTable() ) { // Just coerce an empty/unspecified table to the right type. auto tv = make_intrusive( - IntrusivePtr{NewRef{}, i->Type()->AsTableType()}, + cast_intrusive(i->GetType()), IntrusivePtr{NewRef{}, i->ID_Val()->AsTableVal()->Attrs()}); auto rval = call_option_handlers_and_set_value(ID, i, std::move(tv), location); return val_mgr->Bool(rval); } builtin_error(fmt("Incompatible type for set of ID '%s': got '%s', need '%s'", - ID->CheckString(), type_name(val->Type()->Tag()), type_name(i->Type()->Tag()))); + ID->CheckString(), type_name(val->Type()->Tag()), type_name(i->GetType()->Tag()))); return val_mgr->False(); } @@ -185,10 +185,10 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( ! same_type(args[1].get(), i->Type()) ) + if ( ! same_type(args[1].get(), i->GetType().get()) ) { builtin_error(fmt("Second argument of passed function has to be %s in Option::on_change for ID '%s'; got '%s'", - type_name(i->Type()->Tag()), ID->CheckString(), type_name(args[1]->Tag()))); + type_name(i->GetType()->Tag()), ID->CheckString(), type_name(args[1]->Tag()))); return val_mgr->False(); } @@ -199,10 +199,10 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( ! same_type(on_change->Type()->AsFuncType()->Yield().get(), i->Type()) ) + if ( ! same_type(on_change->Type()->AsFuncType()->Yield().get(), i->GetType().get()) ) { builtin_error(fmt("Passed function needs to return type '%s' for ID '%s'; got '%s'", - type_name(i->Type()->Tag()), ID->CheckString(), type_name(on_change->Type()->AsFuncType()->Yield()->Tag()))); + type_name(i->GetType()->Tag()), ID->CheckString(), type_name(on_change->Type()->AsFuncType()->Yield()->Tag()))); return val_mgr->False(); } diff --git a/src/parse.y b/src/parse.y index fc556041ca..0025cb4eb1 100644 --- a/src/parse.y +++ b/src/parse.y @@ -155,14 +155,15 @@ static void parser_redef_enum (ID *id) /* Redef an enum. id points to the enum to be redefined. Let cur_enum_type point to it. */ assert(cur_enum_type == NULL); + // abort on errors; enums need to be accessible to continue parsing - if ( ! id->Type() ) + if ( ! id->GetType() ) reporter->FatalError("unknown enum identifier \"%s\"", id->Name()); else { - if ( ! id->Type() || id->Type()->Tag() != TYPE_ENUM ) + if ( ! id->GetType() || id->GetType()->Tag() != TYPE_ENUM ) reporter->FatalError("identifier \"%s\" is not an enum", id->Name()); - cur_enum_type = id->Type()->AsEnumType(); + cur_enum_type = id->GetType()->AsEnumType(); } } @@ -608,31 +609,28 @@ expr: if ( $1->Tag() == EXPR_NAME && $1->AsNameExpr()->Id()->IsType() ) { - auto ctor_type = $1->AsNameExpr()->Id()->Type(); + const auto& ctor_type = $1->AsNameExpr()->Id()->GetType(); switch ( ctor_type->Tag() ) { case TYPE_RECORD: { auto rce = make_intrusive( IntrusivePtr{AdoptRef{}, $4}); - IntrusivePtr rt{NewRef{}, ctor_type->AsRecordType()}; + auto rt = cast_intrusive(ctor_type); $$ = new RecordCoerceExpr(std::move(rce), std::move(rt)); } break; case TYPE_TABLE: if ( ctor_type->IsTable() ) - $$ = new TableConstructorExpr({AdoptRef{}, $4}, 0, - {NewRef{}, ctor_type}); + $$ = new TableConstructorExpr({AdoptRef{}, $4}, 0, ctor_type); else - $$ = new SetConstructorExpr({AdoptRef{}, $4}, 0, - {NewRef{}, ctor_type}); + $$ = new SetConstructorExpr({AdoptRef{}, $4}, 0, ctor_type); break; case TYPE_VECTOR: - $$ = new VectorConstructorExpr({AdoptRef{}, $4}, - {NewRef{}, ctor_type}); + $$ = new VectorConstructorExpr({AdoptRef{}, $4}, ctor_type); break; default: @@ -697,7 +695,7 @@ expr: if ( id->IsDeprecated() ) reporter->Warning("%s", id->GetDeprecationWarning().c_str()); - if ( ! id->Type() ) + if ( ! id->GetType() ) { id->Error("undeclared variable"); id->SetType(error_type()); @@ -706,7 +704,7 @@ expr: else if ( id->IsEnumConst() ) { - EnumType* t = id->Type()->AsEnumType(); + EnumType* t = id->GetType()->AsEnumType(); int intval = t->Lookup(id->ModuleName(), id->Name()); if ( intval < 0 ) @@ -1006,7 +1004,7 @@ type: | resolve_id { - if ( ! $1 || ! ($$ = $1->IsType() ? $1->Type() : nullptr) ) + if ( ! $1 || ! ($$ = $1->IsType() ? $1->GetType().get() : nullptr) ) { NullStmt here; if ( $1 ) @@ -1137,7 +1135,7 @@ decl: { cur_decl_type_id = 0; - if ( ! $3->Type() ) + if ( ! $3->GetType() ) $3->Error("unknown identifier"); else extend_record($3, $8, $11); @@ -1817,7 +1815,7 @@ global_or_event_id: if ( $$->IsDeprecated() ) { - BroType* t = $$->Type(); + const auto& t = $$->GetType(); if ( t->Tag() != TYPE_FUNC || t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 269b6576ea..4b04974245 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1171,7 +1171,7 @@ IntrusivePtr Supervisor::Node::ToRecord() const static IntrusivePtr supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role) { - static auto node_type = global_scope()->Lookup("Cluster::NodeType")->Type()->AsEnumType(); + static auto node_type = global_scope()->Lookup("Cluster::NodeType")->GetType()->AsEnumType(); switch ( role ) { case BifEnum::Supervisor::LOGGER: @@ -1192,7 +1192,7 @@ bool Supervisor::SupervisedNode::InitCluster() const if ( config.cluster.empty() ) return false; - auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->Type()->AsRecordType(); + auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->GetType()->AsRecordType(); auto cluster_nodes_id = global_scope()->Lookup("Cluster::nodes"); auto cluster_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger"); auto cluster_nodes = cluster_nodes_id->ID_Val()->AsTableVal(); diff --git a/src/zeek.bif b/src/zeek.bif index 6ab3f39820..93ffc5caed 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1951,7 +1951,7 @@ function global_ids%(%): id_table { ID* id = global.second.get(); auto rec = make_intrusive(script_id); - rec->Assign(0, make_intrusive(type_name(id->Type()->Tag()))); + rec->Assign(0, make_intrusive(type_name(id->GetType()->Tag()))); rec->Assign(1, val_mgr->Bool(id->IsExport())); rec->Assign(2, val_mgr->Bool(id->IsConst())); rec->Assign(3, val_mgr->Bool(id->IsEnumConst())); @@ -2003,14 +2003,14 @@ function record_fields%(rec: any%): record_field_table { auto id = global_scope()->Lookup(rec->AsStringVal()->ToStdString()); - if ( ! id || ! id->IsType() || id->Type()->Tag() != TYPE_RECORD ) + if ( ! id || ! id->IsType() || id->GetType()->Tag() != TYPE_RECORD ) { reporter->Error("record_fields string argument does not name a record type"); IntrusivePtr tt{NewRef{}, internal_type("record_field_table")->AsTableType()}; return make_intrusive(std::move(tt)); } - return id->Type()->AsRecordType()->GetRecordFieldsVal(); + return id->GetType()->AsRecordType()->GetRecordFieldsVal(); } return rec->GetRecordFields(); diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index e95de1ea9e..8372582f1c 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -116,7 +116,7 @@ string IdentifierInfo::DoReStructuredText(bool roles_only) const if ( i > 0 ) d.NL(); - if ( IsFunc(id->Type()->Tag()) ) + if ( IsFunc(id->GetType()->Tag()) ) { string s = comments[i]; diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index 47192cfd27..d773077c16 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -274,7 +274,7 @@ void Manager::StartType(IntrusivePtr id) static bool IsEnumType(ID* id) { - return id->IsType() ? id->Type()->Tag() == TYPE_ENUM : false; + return id->IsType() ? id->GetType()->Tag() == TYPE_ENUM : false; } void Manager::Identifier(IntrusivePtr id) @@ -300,7 +300,7 @@ void Manager::Identifier(IntrusivePtr id) if ( id_info ) { - if ( IsFunc(id_info->GetID()->Type()->Tag()) ) + if ( IsFunc(id_info->GetID()->GetType()->Tag()) ) { // Function may already been seen (declaration versus body). id_info->AddComments(comment_buffer); diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index 5b75415613..0861116902 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -191,9 +191,9 @@ void ScriptInfo::DoInitPostScript() continue; } - if ( IsFunc(id->Type()->Tag()) ) + if ( IsFunc(id->GetType()->Tag()) ) { - switch ( id->Type()->AsFuncType()->Flavor() ) { + switch ( id->GetType()->AsFuncType()->Flavor() ) { case FUNC_FLAVOR_HOOK: DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a hook", id->Name(), name.c_str()); @@ -243,7 +243,7 @@ void ScriptInfo::DoInitPostScript() continue; } - if ( id->Type()->Tag() == TYPE_ENUM ) + if ( id->GetType()->Tag() == TYPE_ENUM ) // Enums are always referenced/documented from the type's // documentation. continue; From 4af1a26b1f37d764fe3cdd9ce95bbe2b408fd218 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 7 May 2020 21:15:39 -0700 Subject: [PATCH 028/151] Add Val TypeType constructor taking an IntrusivePtr --- src/Expr.cc | 2 +- src/Val.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 223c27da2a..3ff94d3242 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -233,7 +233,7 @@ IntrusivePtr NameExpr::Eval(Frame* f) const IntrusivePtr v; if ( id->IsType() ) - return make_intrusive(id->GetType().get(), true); + return make_intrusive(id->GetType(), true); if ( id->IsGlobal() ) v = {NewRef{}, id->ID_Val()}; diff --git a/src/Val.h b/src/Val.h index 455ae7b19c..eb81241c3a 100644 --- a/src/Val.h +++ b/src/Val.h @@ -137,8 +137,12 @@ public: explicit Val(BroFile* f); // Extra arg to differentiate from protected version. - Val(BroType* t, bool type_type) - : type(new TypeType({NewRef{}, t})) + Val(IntrusivePtr t, bool type_type) + : type(new TypeType(std::move(t))) + { } + + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] + Val(BroType* t, bool type_type) : Val({NewRef{}, t}, type_type) { } From 16a8bf331847224457f799a8e19bd12999b1f5a9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 7 May 2020 21:30:57 -0700 Subject: [PATCH 029/151] Use std::move in some zeekygen::Manager methods --- src/zeekygen/Manager.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index d773077c16..868b27e39b 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -218,13 +218,14 @@ void Manager::ModuleUsage(const string& path, const string& module) IdentifierInfo* Manager::CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script) { - auto prev = identifiers.GetInfo(id->Name()); - IdentifierInfo* rval = prev ? prev : new IdentifierInfo(id, script); + const auto& id_name = id->Name(); + auto prev = identifiers.GetInfo(id_name); + IdentifierInfo* rval = prev ? prev : new IdentifierInfo(std::move(id), script); rval->AddComments(comment_buffer); comment_buffer.clear(); - comment_buffer_map_t::iterator it = comment_buffer_map.find(id->Name()); + comment_buffer_map_t::iterator it = comment_buffer_map.find(id_name); if ( it != comment_buffer_map.end() ) { @@ -235,7 +236,7 @@ IdentifierInfo* Manager::CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* s if ( ! prev ) { all_info.push_back(rval); - identifiers.map[id->Name()] = rval; + identifiers.map[id_name] = rval; } last_identifier_seen = rval; @@ -267,9 +268,9 @@ void Manager::StartType(IntrusivePtr id) return; } - incomplete_type = CreateIdentifierInfo(id, script_info); - DBG_LOG(DBG_ZEEKYGEN, "Made IdentifierInfo (incomplete) %s, in %s", + DBG_LOG(DBG_ZEEKYGEN, "Making IdentifierInfo (incomplete) %s, in %s", id->Name(), script.c_str()); + incomplete_type = CreateIdentifierInfo(std::move(id), script_info); } static bool IsEnumType(ID* id) @@ -331,9 +332,9 @@ void Manager::Identifier(IntrusivePtr id) return; } - CreateIdentifierInfo(id, script_info); - DBG_LOG(DBG_ZEEKYGEN, "Made IdentifierInfo %s, in script %s", + DBG_LOG(DBG_ZEEKYGEN, "Making IdentifierInfo %s, in script %s", id->Name(), script.c_str()); + CreateIdentifierInfo(std::move(id), script_info); } void Manager::RecordField(const ID* id, const TypeDecl* field, From 32b895f4ba662c48f46e5751b3e79caa8c1a22be Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 7 May 2020 22:11:10 -0700 Subject: [PATCH 030/151] Deprecate ID::ID_Val(), replace with ID::GetVal() --- NEWS | 2 ++ src/Debug.cc | 2 +- src/Expr.cc | 2 +- src/ID.cc | 29 ++++++++----------- src/ID.h | 13 +++++++-- src/RuleCondition.cc | 4 +-- src/RuleMatcher.cc | 2 +- src/Stats.cc | 4 +-- src/Trigger.cc | 3 +- src/Type.cc | 2 +- src/Var.cc | 14 ++++----- src/analyzer/Manager.cc | 4 +-- .../protocol/mqtt/commands/publish.pac | 2 +- src/broker/Data.cc | 4 +-- src/broker/Manager.cc | 8 ++--- src/broker/messaging.bif | 4 +-- src/logging/Manager.cc | 4 +-- src/option.bif | 2 +- src/supervisor/Supervisor.cc | 2 +- src/zeek-setup.cc | 6 ++-- src/zeek.bif | 16 ++++------ src/zeekygen/IdentifierInfo.cc | 4 +-- src/zeekygen/IdentifierInfo.h | 4 +-- 23 files changed, 69 insertions(+), 68 deletions(-) diff --git a/NEWS b/NEWS index 840e687988..055a1a48a6 100644 --- a/NEWS +++ b/NEWS @@ -157,6 +157,8 @@ Deprecated Functionality - ``ID::Type()`` is deprecated, use ``ID::GetType()``. +- ``ID::ID_Val()`` is deprecated, use ``ID::GetVal()``. + Zeek 3.1.0 ========== diff --git a/src/Debug.cc b/src/Debug.cc index 7136daf3cb..b28d03a7e2 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -221,7 +221,7 @@ static void parse_function_name(vector& result, return; } - const Func* func = id->ID_Val()->AsFunc(); + const Func* func = id->GetVal()->AsFunc(); const vector& bodies = func->GetBodies(); if ( bodies.size() == 0 ) diff --git a/src/Expr.cc b/src/Expr.cc index 3ff94d3242..4848a6db73 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -236,7 +236,7 @@ IntrusivePtr NameExpr::Eval(Frame* f) const return make_intrusive(id->GetType(), true); if ( id->IsGlobal() ) - v = {NewRef{}, id->ID_Val()}; + v = id->GetVal(); else if ( f ) v = {NewRef{}, f->GetElement(id.get())}; diff --git a/src/ID.cc b/src/ID.cc index 0ddab99d92..20d4e1df85 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -25,7 +25,6 @@ ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) scope = arg_scope; is_export = arg_is_export; is_option = false; - val = nullptr; is_const = false; is_enum_const = false; is_type = false; @@ -41,8 +40,8 @@ ID::~ID() { delete [] name; - if ( ! weak_ref ) - Unref(val); + if ( weak_ref ) + val.release(); } std::string ID::ModuleName() const @@ -57,18 +56,16 @@ void ID::SetType(IntrusivePtr t) void ID::ClearVal() { - if ( ! weak_ref ) - Unref(val); - - val = nullptr; + if ( weak_ref ) + val.release(); } void ID::SetVal(IntrusivePtr v, bool arg_weak_ref) { - if ( ! weak_ref ) - Unref(val); + if ( weak_ref ) + val.release(); - val = v.release(); + val = std::move(v); weak_ref = arg_weak_ref; Modified(); @@ -124,12 +121,12 @@ void ID::SetVal(IntrusivePtr v, init_class c) return; } else - v->AddTo(val, false); + v->AddTo(val.get(), false); } else { if ( val ) - v->RemoveFrom(val); + v->RemoveFrom(val.get()); } } } @@ -267,7 +264,7 @@ void ID::SetOption() void ID::EvalFunc(IntrusivePtr ef, IntrusivePtr ev) { - auto arg1 = make_intrusive(IntrusivePtr{NewRef{}, val}); + auto arg1 = make_intrusive(val); auto args = make_intrusive(); args->Append(std::move(arg1)); args->Append(std::move(ev)); @@ -488,10 +485,8 @@ void ID::DescribeReST(ODesc* d, bool roles_only) const d->Add(":Default:"); auto ii = zeekygen_mgr->GetIdentifierInfo(Name()); auto redefs = ii->GetRedefs(); - auto iv = val; - - if ( ! redefs.empty() && ii->InitialVal() ) - iv = ii->InitialVal(); + const auto& iv = ! redefs.empty() && ii->InitialVal() ? ii->InitialVal() + : val; if ( type->InternalType() == TYPE_INTERNAL_OTHER ) { diff --git a/src/ID.h b/src/ID.h index 7324032c3c..0ec222f733 100644 --- a/src/ID.h +++ b/src/ID.h @@ -70,8 +70,15 @@ public: void SetVal(IntrusivePtr ev, init_class c); bool HasVal() const { return val != nullptr; } - Val* ID_Val() { return val; } - const Val* ID_Val() const { return val; } + + [[deprecated("Remove in v4.1. Use GetVal().")]] + Val* ID_Val() { return val.get(); } + [[deprecated("Remove in v4.1. Use GetVal().")]] + const Val* ID_Val() const { return val.get(); } + + const IntrusivePtr& GetVal() const + { return val; } + void ClearVal(); void SetConst() { is_const = true; } @@ -139,7 +146,7 @@ protected: IntrusivePtr type; bool is_const, is_enum_const, is_type, is_option; int offset; - Val* val; + IntrusivePtr val; IntrusivePtr attrs; // contains list of functions that are called when an option changes std::multimap> option_handlers; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index ff43f0ecaf..315a40551f 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -164,7 +164,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, } if ( id->GetType()->Tag() != TYPE_FUNC ) - return id->ID_Val()->AsBool(); + return id->GetVal()->AsBool(); // Call function with a signature_state value as argument. zeek::Args args; @@ -180,7 +180,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, try { - auto val = id->ID_Val()->AsFunc()->Call(args); + auto val = id->GetVal()->AsFunc()->Call(args); result = val && val->AsBool(); } diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index b624008271..1137d0ee76 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -1278,7 +1278,7 @@ static Val* get_bro_val(const char* label) return nullptr; } - return id->ID_Val(); + return id->GetVal().get(); } diff --git a/src/Stats.cc b/src/Stats.cc index 3c2508c7f7..70427ebcf5 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -257,9 +257,9 @@ void ProfileLogger::Log() // contained in some other global user-visible container. if ( id->HasVal() ) { - Val* v = id->ID_Val(); + const auto& v = id->GetVal(); - size = id->ID_Val()->MemoryAllocation(); + size = v->MemoryAllocation(); mem += size; bool print = false; diff --git a/src/Trigger.cc b/src/Trigger.cc index f024cfbbe5..18fd850b64 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -50,7 +50,8 @@ TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr) if ( e->Id()->IsGlobal() ) trigger->Register(e->Id()); - Val* v = e->Id()->ID_Val(); + Val* v = e->Id()->GetVal().get(); + if ( v && v->Modifiable() ) trigger->Register(v); break; diff --git a/src/Type.cc b/src/Type.cc index 1c8176ddcf..be18f6d059 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1168,7 +1168,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, // cyclic dependencies. string fullname = make_full_var_name(module_name.c_str(), name); if ( id->Name() != fullname - || (id->HasVal() && val != id->ID_Val()->AsEnum()) + || (id->HasVal() && val != id->GetVal()->AsEnum()) || (names.find(fullname) != names.end() && names[fullname] != val) ) { reporter->Error("identifier or enumerator value in enumerated type definition already exists"); diff --git a/src/Var.cc b/src/Var.cc index cf79a6ba4d..7a5c9026d8 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -525,7 +525,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, if ( id->HasVal() ) { - function_flavor id_flavor = id->ID_Val()->AsFunc()->Flavor(); + function_flavor id_flavor = id->GetVal()->AsFunc()->Flavor(); if ( id_flavor != flavor ) id->Error("inconsistent function flavor", t.get()); @@ -630,7 +630,7 @@ void end_func(IntrusivePtr body) auto ingredients = std::make_unique(pop_scope(), std::move(body)); if ( ingredients->id->HasVal() ) - ingredients->id->ID_Val()->AsFunc()->AddBody( + ingredients->id->GetVal()->AsFunc()->AddBody( ingredients->body, ingredients->inits, ingredients->frame_size, @@ -648,7 +648,7 @@ void end_func(IntrusivePtr body) ingredients->id->SetConst(); } - ingredients->id->ID_Val()->AsFunc()->SetScope(ingredients->scope); + ingredients->id->GetVal()->AsFunc()->SetScope(ingredients->scope); // Note: ideally, something would take ownership of this memory until the // end of script execution, but that's essentially the same as the // lifetime of the process at the moment, so ok to "leak" it. @@ -662,7 +662,7 @@ Val* internal_val(const char* name) if ( ! id ) reporter->InternalError("internal variable %s missing", name); - return id->ID_Val(); + return id->GetVal().get(); } id_list gather_outer_ids(Scope* scope, Stmt* body) @@ -694,13 +694,13 @@ Val* internal_const_val(const char* name) if ( ! id->IsConst() ) reporter->InternalError("internal variable %s is not constant", name); - return id->ID_Val(); + return id->GetVal().get(); } Val* opt_internal_val(const char* name) { auto id = lookup_ID(name, GLOBAL_MODULE_NAME); - return id ? id->ID_Val() : nullptr; + return id ? id->GetVal().get() : nullptr; } double opt_internal_double(const char* name) @@ -739,7 +739,7 @@ ListVal* internal_list_val(const char* name) if ( ! id ) return nullptr; - Val* v = id->ID_Val(); + Val* v = id->GetVal().get(); if ( v ) { diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index 45f6b7792e..d605e04d0e 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -92,10 +92,10 @@ void Manager::InitPostScript() { auto id = global_scope()->Lookup("Tunnel::vxlan_ports"); - if ( ! (id && id->ID_Val()) ) + if ( ! (id && id->GetVal()) ) reporter->FatalError("Tunnel::vxlan_ports not defined"); - auto table_val = id->ID_Val()->AsTableVal(); + auto table_val = id->GetVal()->AsTableVal(); auto port_list = table_val->ToPureListVal(); for ( auto i = 0; i < port_list->Length(); ++i ) diff --git a/src/analyzer/protocol/mqtt/commands/publish.pac b/src/analyzer/protocol/mqtt/commands/publish.pac index a2ded3783d..029f52b899 100644 --- a/src/analyzer/protocol/mqtt/commands/publish.pac +++ b/src/analyzer/protocol/mqtt/commands/publish.pac @@ -31,7 +31,7 @@ refine flow MQTT_Flow += { reinterpret_cast(${msg.topic.str}.begin()))); auto len = ${msg.payload}.length(); - auto max = analyzer::MQTT::MQTT_Analyzer::max_payload_size->ID_Val()->AsCount(); + auto max = analyzer::MQTT::MQTT_Analyzer::max_payload_size->GetVal()->AsCount(); if ( len > static_cast(max) ) len = max; diff --git a/src/broker/Data.cc b/src/broker/Data.cc index cbed055db3..c653256a89 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -357,7 +357,7 @@ struct val_converter { if ( ! id ) return nullptr; - auto rval = id->ID_Val(); + const auto& rval = id->GetVal(); if ( ! rval ) return nullptr; @@ -701,7 +701,7 @@ struct type_checker { if ( ! id ) return false; - auto rval = id->ID_Val(); + const auto& rval = id->GetVal(); if ( ! rval ) return false; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 9155dad4cd..c5be4b918b 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -31,10 +31,10 @@ static inline Val* get_option(const char* option) { auto id = global_scope()->Lookup(option); - if ( ! (id && id->ID_Val()) ) + if ( ! (id && id->GetVal()) ) reporter->FatalError("Unknown Broker option %s", option); - return id->ID_Val(); + return id->GetVal().get(); } class BrokerConfig : public broker::configuration { @@ -418,14 +418,14 @@ bool Manager::PublishIdentifier(std::string topic, std::string id) if ( ! i ) return false; - auto val = i->ID_Val(); + const auto& val = i->GetVal(); if ( ! val ) // Probably could have a special case to also unset the value on the // receiving side, but not sure what use that would be. return false; - auto data = val_to_data(val); + auto data = val_to_data(val.get()); if ( ! data ) { diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index c809b013ee..fd33464371 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -185,7 +185,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool static Func* topic_func = 0; if ( ! topic_func ) - topic_func = global_scope()->Lookup("Cluster::rr_topic")->ID_Val()->AsFunc(); + topic_func = global_scope()->Lookup("Cluster::rr_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; auto topic = topic_func->Call(vl); @@ -222,7 +222,7 @@ function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool static Func* topic_func = 0; if ( ! topic_func ) - topic_func = global_scope()->Lookup("Cluster::hrw_topic")->ID_Val()->AsFunc(); + topic_func = global_scope()->Lookup("Cluster::hrw_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; auto topic = topic_func->Call(vl); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 2a190ba53a..5f0933d234 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1184,7 +1184,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken { ID* id = global_scope()->Lookup("Log::default_rotation_interval"); assert(id); - winfo->interval = id->ID_Val()->AsInterval(); + winfo->interval = id->GetVal()->AsInterval(); } stream->writers.insert( @@ -1527,7 +1527,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con { ID* id = global_scope()->Lookup("Log::__default_rotation_postprocessor"); assert(id); - func = id->ID_Val()->AsFunc(); + func = id->GetVal()->AsFunc(); } assert(func); diff --git a/src/option.bif b/src/option.bif index 016bcd993e..c898b725bf 100644 --- a/src/option.bif +++ b/src/option.bif @@ -104,7 +104,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool // Just coerce an empty/unspecified table to the right type. auto tv = make_intrusive( cast_intrusive(i->GetType()), - IntrusivePtr{NewRef{}, i->ID_Val()->AsTableVal()->Attrs()}); + IntrusivePtr{NewRef{}, i->GetVal()->AsTableVal()->Attrs()}); auto rval = call_option_handlers_and_set_value(ID, i, std::move(tv), location); return val_mgr->Bool(rval); } diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 4b04974245..0f063a3f76 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1195,7 +1195,7 @@ bool Supervisor::SupervisedNode::InitCluster() const auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->GetType()->AsRecordType(); auto cluster_nodes_id = global_scope()->Lookup("Cluster::nodes"); auto cluster_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger"); - auto cluster_nodes = cluster_nodes_id->ID_Val()->AsTableVal(); + auto cluster_nodes = cluster_nodes_id->GetVal()->AsTableVal(); auto has_logger = false; std::optional manager_name; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index b8d65a01b4..cb5e3bd49c 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -631,11 +631,11 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, // initialization). binpac::FlowBuffer::Policy flowbuffer_policy; flowbuffer_policy.max_capacity = global_scope()->Lookup( - "BinPAC::flowbuffer_capacity_max")->ID_Val()->AsCount(); + "BinPAC::flowbuffer_capacity_max")->GetVal()->AsCount(); flowbuffer_policy.min_capacity = global_scope()->Lookup( - "BinPAC::flowbuffer_capacity_min")->ID_Val()->AsCount(); + "BinPAC::flowbuffer_capacity_min")->GetVal()->AsCount(); flowbuffer_policy.contract_threshold = global_scope()->Lookup( - "BinPAC::flowbuffer_contract_threshold")->ID_Val()->AsCount(); + "BinPAC::flowbuffer_contract_threshold")->GetVal()->AsCount(); binpac::init(&flowbuffer_policy); plugin_mgr->InitBifs(); diff --git a/src/zeek.bif b/src/zeek.bif index 93ffc5caed..91e7d82000 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1926,7 +1926,7 @@ function global_sizes%(%): var_sizes if ( id->HasVal() ) { auto id_name = make_intrusive(id->Name()); - auto id_size = val_mgr->Count(id->ID_Val()->MemoryAllocation()); + auto id_size = val_mgr->Count(id->GetVal()->MemoryAllocation()); sizes->Assign(id_name.get(), std::move(id_size)); } } @@ -1959,11 +1959,7 @@ function global_ids%(%): id_table rec->Assign(5, val_mgr->Bool(id->IsRedefinable())); if ( id->HasVal() ) - { - Val* val = id->ID_Val(); - Ref(val); - rec->Assign(6, val); - } + rec->Assign(6, id->GetVal()); auto id_name = make_intrusive(id->Name()); ids->Assign(id_name.get(), std::move(rec)); @@ -1984,10 +1980,10 @@ function lookup_ID%(id: string%) : any if ( ! i ) return make_intrusive(""); - if ( ! i->ID_Val() ) + if ( ! i->GetVal() ) return make_intrusive(""); - return IntrusivePtr{NewRef{}, i->ID_Val()}; + return i->GetVal(); %} ## Generates metadata about a record's fields. The returned information @@ -3908,7 +3904,7 @@ static Val* mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, static bool mmdb_try_open_loc () { // City database is always preferred over Country database. - auto mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->ID_Val(); + const auto& mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->GetVal(); std::string mmdb_dir = mmdb_dir_val->AsString()->CheckString(); if ( ! mmdb_dir.empty() ) @@ -3936,7 +3932,7 @@ static bool mmdb_try_open_loc () static bool mmdb_try_open_asn () { - auto mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->ID_Val(); + const auto& mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->GetVal(); std::string mmdb_dir = mmdb_dir_val->AsString()->CheckString(); if ( ! mmdb_dir.empty() ) diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index 8372582f1c..744aab928b 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -16,8 +16,8 @@ IdentifierInfo::IdentifierInfo(IntrusivePtr arg_id, ScriptInfo* script) comments(), id(std::move(arg_id)), initial_val(), redefs(), fields(), last_field_seen(), declaring_script(script) { - if ( id->ID_Val() && (id->IsOption() || id->IsRedefinable()) ) - initial_val = id->ID_Val()->Clone(); + if ( id->GetVal() && (id->IsOption() || id->IsRedefinable()) ) + initial_val = id->GetVal()->Clone(); } IdentifierInfo::~IdentifierInfo() diff --git a/src/zeekygen/IdentifierInfo.h b/src/zeekygen/IdentifierInfo.h index e21912d8fb..a2292844d1 100644 --- a/src/zeekygen/IdentifierInfo.h +++ b/src/zeekygen/IdentifierInfo.h @@ -42,8 +42,8 @@ public: /** * Returns the initial value of the identifier. */ - Val* InitialVal() const - { return initial_val.get(); } + const IntrusivePtr& InitialVal() const + { return initial_val; } /** * Add a comment associated with the identifier. If the identifier is a From ac06259eeccfb060ae951dbcc1040773ad36000d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 8 May 2020 17:44:20 -0700 Subject: [PATCH 031/151] Deprecate internal_type(), replace with zeek::lookup_type() --- NEWS | 2 + aux/bifcl | 2 +- src/BroString.cc | 2 +- src/DNS_Mgr.cc | 2 +- src/Func.cc | 30 +++--- src/IP.cc | 34 +++--- src/NetVar.cc | 100 +++++++++--------- src/OpaqueVal.cc | 2 +- src/RuleCondition.cc | 4 +- src/SmithWaterman.cc | 8 +- src/Stats.cc | 4 +- src/Stmt.cc | 4 +- src/TunnelEncapsulation.h | 4 +- src/Type.cc | 4 +- src/Val.cc | 8 +- src/Var.cc | 9 +- src/Var.h | 25 +++++ .../protocol/bittorrent/BitTorrentTracker.cc | 10 +- src/analyzer/protocol/icmp/ICMP.cc | 6 +- src/analyzer/protocol/imap/imap-analyzer.pac | 2 +- src/analyzer/protocol/krb/krb-padata.pac | 2 +- src/analyzer/protocol/krb/krb-types.pac | 6 +- .../protocol/mysql/mysql-analyzer.pac | 2 +- src/analyzer/protocol/rpc/MOUNT.cc | 2 +- src/analyzer/protocol/rpc/NFS.cc | 2 +- src/analyzer/protocol/smb/smb2-protocol.pac | 6 +- src/analyzer/protocol/ssh/ssh-analyzer.pac | 2 +- .../protocol/ssl/proc-client-hello.pac | 4 +- .../protocol/ssl/tls-handshake-analyzer.pac | 26 ++--- src/analyzer/protocol/tcp/TCP.cc | 2 +- src/analyzer/protocol/teredo/Teredo.cc | 6 +- src/bro-bif.h | 2 +- src/broker/Data.cc | 4 +- src/broker/Manager.cc | 10 +- src/broker/Store.cc | 4 +- src/broker/comm.bif | 8 +- src/file_analysis/analyzer/pe/pe-analyzer.pac | 4 +- src/file_analysis/analyzer/x509/OCSP.cc | 2 +- src/file_analysis/analyzer/x509/X509.cc | 8 +- src/file_analysis/analyzer/x509/functions.bif | 2 +- src/logging/Manager.cc | 2 +- src/stats.bif | 4 +- src/strings.bif | 4 +- src/zeek.bif | 24 ++--- 44 files changed, 218 insertions(+), 182 deletions(-) diff --git a/NEWS b/NEWS index 055a1a48a6..0d9a23688e 100644 --- a/NEWS +++ b/NEWS @@ -159,6 +159,8 @@ Deprecated Functionality - ``ID::ID_Val()`` is deprecated, use ``ID::GetVal()``. +- ``internal_type()`` is deprecated, use ``zeek::lookup_type()``. + Zeek 3.1.0 ========== diff --git a/aux/bifcl b/aux/bifcl index 9d6a296d28..2d9b8606d5 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 9d6a296d283cfccf2c28a9181d9cee2760229fcb +Subproject commit 2d9b8606d5d7e4ec4a67cc11a72d38c2241ee871 diff --git a/src/BroString.cc b/src/BroString.cc index e9708d1852..80ebe66270 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -341,7 +341,7 @@ BroString::Vec* BroString::Split(const BroString::IdxVec& indices) const VectorVal* BroString:: VecToPolicy(Vec* vec) { VectorVal* result = - new VectorVal(internal_type("string_vec")->AsVectorType()); + new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); if ( ! result ) return nullptr; diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index a97c333a6a..b6f4f4a00e 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -462,7 +462,7 @@ void DNS_Mgr::InitPostScript() dns_mapping_name_changed = internal_handler("dns_mapping_name_changed"); dns_mapping_altered = internal_handler("dns_mapping_altered"); - dm_rec = internal_type("dns_mapping")->AsRecordType(); + dm_rec = zeek::lookup_type("dns_mapping")->AsRecordType(); // Registering will call Init() iosource_mgr->Register(this, true); diff --git a/src/Func.cc b/src/Func.cc index b3fe426b9a..1ac5d9652d 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -54,6 +54,8 @@ #include "iosource/PktSrc.h" #include "iosource/PktDumper.h" +using namespace zeek; + extern RETSIGTYPE sig_handler(int signo); std::vector call_stack; @@ -748,21 +750,21 @@ void builtin_error(const char* msg, BroObj* arg) void init_builtin_funcs() { - ProcStats = internal_type("ProcStats")->AsRecordType(); - NetStats = internal_type("NetStats")->AsRecordType(); - MatcherStats = internal_type("MatcherStats")->AsRecordType(); - ConnStats = internal_type("ConnStats")->AsRecordType(); - ReassemblerStats = internal_type("ReassemblerStats")->AsRecordType(); - DNSStats = internal_type("DNSStats")->AsRecordType(); - GapStats = internal_type("GapStats")->AsRecordType(); - EventStats = internal_type("EventStats")->AsRecordType(); - TimerStats = internal_type("TimerStats")->AsRecordType(); - FileAnalysisStats = internal_type("FileAnalysisStats")->AsRecordType(); - ThreadStats = internal_type("ThreadStats")->AsRecordType(); - BrokerStats = internal_type("BrokerStats")->AsRecordType(); - ReporterStats = internal_type("ReporterStats")->AsRecordType(); + ProcStats = lookup_type("ProcStats")->AsRecordType(); + NetStats = lookup_type("NetStats")->AsRecordType(); + MatcherStats = lookup_type("MatcherStats")->AsRecordType(); + ConnStats = lookup_type("ConnStats")->AsRecordType(); + ReassemblerStats = lookup_type("ReassemblerStats")->AsRecordType(); + DNSStats = lookup_type("DNSStats")->AsRecordType(); + GapStats = lookup_type("GapStats")->AsRecordType(); + EventStats = lookup_type("EventStats")->AsRecordType(); + TimerStats = lookup_type("TimerStats")->AsRecordType(); + FileAnalysisStats = lookup_type("FileAnalysisStats")->AsRecordType(); + ThreadStats = lookup_type("ThreadStats")->AsRecordType(); + BrokerStats = lookup_type("BrokerStats")->AsRecordType(); + ReporterStats = lookup_type("ReporterStats")->AsRecordType(); - var_sizes = internal_type("var_sizes")->AsTableType(); + var_sizes = lookup_type("var_sizes")->AsTableType(); #include "zeek.bif.func_init" #include "stats.bif.func_init" diff --git a/src/IP.cc b/src/IP.cc index 590f932a90..32fc68ba85 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -13,6 +13,8 @@ #include "BroString.h" #include "Reporter.h" +using namespace zeek; + static RecordType* ip4_hdr_type = nullptr; static RecordType* ip6_hdr_type = nullptr; static RecordType* ip6_ext_hdr_type = nullptr; @@ -37,14 +39,14 @@ static RecordType* ip6_mob_be_type = nullptr; static inline RecordType* hdrType(RecordType*& type, const char* name) { if ( ! type ) - type = internal_type(name)->AsRecordType(); + type = lookup_type(name)->AsRecordType(); return type; } static IntrusivePtr BuildOptionsVal(const u_char* data, int len) { - auto vv = make_intrusive(internal_type("ip6_options")->AsVectorType()); + auto vv = make_intrusive(lookup_type("ip6_options")->AsVectorType()); while ( len > 0 ) { @@ -95,7 +97,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const rv->Assign(6, make_intrusive(IPAddr(ip6->ip6_dst))); if ( ! chain ) chain = make_intrusive( - internal_type("ip6_ext_hdr_chain")->AsVectorType()); + lookup_type("ip6_ext_hdr_chain")->AsVectorType()); rv->Assign(7, std::move(chain)); } break; @@ -367,7 +369,7 @@ IntrusivePtr IP_Hdr::ToPktHdrVal() const static RecordType* pkt_hdr_type = nullptr; if ( ! pkt_hdr_type ) - pkt_hdr_type = internal_type("pkt_hdr")->AsRecordType(); + pkt_hdr_type = lookup_type("pkt_hdr")->AsRecordType(); return ToPktHdrVal(make_intrusive(pkt_hdr_type), 0); } @@ -385,9 +387,9 @@ IntrusivePtr IP_Hdr::ToPktHdrVal(IntrusivePtr pkt_hdr, int if ( ! tcp_hdr_type ) { - tcp_hdr_type = internal_type("tcp_hdr")->AsRecordType(); - udp_hdr_type = internal_type("udp_hdr")->AsRecordType(); - icmp_hdr_type = internal_type("icmp_hdr")->AsRecordType(); + tcp_hdr_type = lookup_type("tcp_hdr")->AsRecordType(); + udp_hdr_type = lookup_type("udp_hdr")->AsRecordType(); + icmp_hdr_type = lookup_type("icmp_hdr")->AsRecordType(); } if ( ip4 ) @@ -697,18 +699,18 @@ IntrusivePtr IPv6_Hdr_Chain::ToVal() const { if ( ! ip6_ext_hdr_type ) { - ip6_ext_hdr_type = internal_type("ip6_ext_hdr")->AsRecordType(); - ip6_hopopts_type = internal_type("ip6_hopopts")->AsRecordType(); - ip6_dstopts_type = internal_type("ip6_dstopts")->AsRecordType(); - ip6_routing_type = internal_type("ip6_routing")->AsRecordType(); - ip6_fragment_type = internal_type("ip6_fragment")->AsRecordType(); - ip6_ah_type = internal_type("ip6_ah")->AsRecordType(); - ip6_esp_type = internal_type("ip6_esp")->AsRecordType(); - ip6_mob_type = internal_type("ip6_mobility_hdr")->AsRecordType(); + ip6_ext_hdr_type = lookup_type("ip6_ext_hdr")->AsRecordType(); + ip6_hopopts_type = lookup_type("ip6_hopopts")->AsRecordType(); + ip6_dstopts_type = lookup_type("ip6_dstopts")->AsRecordType(); + ip6_routing_type = lookup_type("ip6_routing")->AsRecordType(); + ip6_fragment_type = lookup_type("ip6_fragment")->AsRecordType(); + ip6_ah_type = lookup_type("ip6_ah")->AsRecordType(); + ip6_esp_type = lookup_type("ip6_esp")->AsRecordType(); + ip6_mob_type = lookup_type("ip6_mobility_hdr")->AsRecordType(); } auto rval = make_intrusive( - internal_type("ip6_ext_hdr_chain")->AsVectorType()); + lookup_type("ip6_ext_hdr_chain")->AsVectorType()); for ( size_t i = 1; i < chain.size(); ++i ) { diff --git a/src/NetVar.cc b/src/NetVar.cc index cb604c75ba..2fcc92735a 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -7,6 +7,8 @@ #include "EventHandler.h" #include "Val.h" +using namespace zeek; + RecordType* conn_id; RecordType* endpoint; RecordType* endpoint_stats; @@ -213,7 +215,7 @@ void init_general_global_var() table_expire_delay = opt_internal_double("table_expire_delay"); table_incremental_step = opt_internal_int("table_incremental_step"); - rotate_info = internal_type("rotate_info")->AsRecordType(); + rotate_info = lookup_type("rotate_info")->AsRecordType(); log_rotate_base_time = opt_internal_string("log_rotate_base_time"); peer_description = @@ -247,26 +249,26 @@ void init_net_var() #include "reporter.bif.netvar_init" #include "supervisor.bif.netvar_init" - conn_id = internal_type("conn_id")->AsRecordType(); - endpoint = internal_type("endpoint")->AsRecordType(); - endpoint_stats = internal_type("endpoint_stats")->AsRecordType(); - connection_type = internal_type("connection")->AsRecordType(); - fa_file_type = internal_type("fa_file")->AsRecordType(); - fa_metadata_type = internal_type("fa_metadata")->AsRecordType(); - icmp_conn = internal_type("icmp_conn")->AsRecordType(); - icmp_context = internal_type("icmp_context")->AsRecordType(); - signature_state = internal_type("signature_state")->AsRecordType(); - SYN_packet = internal_type("SYN_packet")->AsRecordType(); - pcap_packet = internal_type("pcap_packet")->AsRecordType(); - raw_pkt_hdr_type = internal_type("raw_pkt_hdr")->AsRecordType(); - l2_hdr_type = internal_type("l2_hdr")->AsRecordType(); - transport_proto = internal_type("transport_proto")->AsEnumType(); - string_set = internal_type("string_set")->AsTableType(); - string_array = internal_type("string_array")->AsTableType(); - string_vec = internal_type("string_vec")->AsVectorType(); - index_vec = internal_type("index_vec")->AsVectorType(); - mime_match = internal_type("mime_match")->AsRecordType(); - mime_matches = internal_type("mime_matches")->AsVectorType(); + conn_id = lookup_type("conn_id")->AsRecordType(); + endpoint = lookup_type("endpoint")->AsRecordType(); + endpoint_stats = lookup_type("endpoint_stats")->AsRecordType(); + connection_type = lookup_type("connection")->AsRecordType(); + fa_file_type = lookup_type("fa_file")->AsRecordType(); + fa_metadata_type = lookup_type("fa_metadata")->AsRecordType(); + icmp_conn = lookup_type("icmp_conn")->AsRecordType(); + icmp_context = lookup_type("icmp_context")->AsRecordType(); + signature_state = lookup_type("signature_state")->AsRecordType(); + SYN_packet = lookup_type("SYN_packet")->AsRecordType(); + pcap_packet = lookup_type("pcap_packet")->AsRecordType(); + raw_pkt_hdr_type = lookup_type("raw_pkt_hdr")->AsRecordType(); + l2_hdr_type = lookup_type("l2_hdr")->AsRecordType(); + transport_proto = lookup_type("transport_proto")->AsEnumType(); + string_set = lookup_type("string_set")->AsTableType(); + string_array = lookup_type("string_array")->AsTableType(); + string_vec = lookup_type("string_vec")->AsVectorType(); + index_vec = lookup_type("index_vec")->AsVectorType(); + mime_match = lookup_type("mime_match")->AsRecordType(); + mime_matches = lookup_type("mime_matches")->AsVectorType(); ignore_checksums = opt_internal_int("ignore_checksums"); partial_connection_ok = opt_internal_int("partial_connection_ok"); @@ -292,7 +294,7 @@ void init_net_var() opt_internal_int("tcp_excessive_data_without_further_acks"); tcp_max_old_segments = opt_internal_int("tcp_max_old_segments"); - socks_address = internal_type("SOCKS::Address")->AsRecordType(); + socks_address = lookup_type("SOCKS::Address")->AsRecordType(); non_analyzed_lifetime = opt_internal_double("non_analyzed_lifetime"); tcp_inactivity_timeout = opt_internal_double("tcp_inactivity_timeout"); @@ -347,34 +349,34 @@ void init_net_var() mime_segment_length = opt_internal_int("mime_segment_length"); mime_segment_overlap_length = opt_internal_int("mime_segment_overlap_length"); - mime_header_rec = internal_type("mime_header_rec")->AsRecordType(); - mime_header_list = internal_type("mime_header_list")->AsTableType(); + mime_header_rec = lookup_type("mime_header_rec")->AsRecordType(); + mime_header_list = lookup_type("mime_header_list")->AsTableType(); http_entity_data_delivery_size = opt_internal_int("http_entity_data_delivery_size"); - http_stats_rec = internal_type("http_stats_rec")->AsRecordType(); - http_message_stat = internal_type("http_message_stat")->AsRecordType(); + http_stats_rec = lookup_type("http_stats_rec")->AsRecordType(); + http_message_stat = lookup_type("http_message_stat")->AsRecordType(); truncate_http_URI = opt_internal_int("truncate_http_URI"); - pm_mapping = internal_type("pm_mapping")->AsRecordType(); - pm_mappings = internal_type("pm_mappings")->AsTableType(); - pm_port_request = internal_type("pm_port_request")->AsRecordType(); - pm_callit_request = internal_type("pm_callit_request")->AsRecordType(); + pm_mapping = lookup_type("pm_mapping")->AsRecordType(); + pm_mappings = lookup_type("pm_mappings")->AsTableType(); + pm_port_request = lookup_type("pm_port_request")->AsRecordType(); + pm_callit_request = lookup_type("pm_callit_request")->AsRecordType(); - geo_location = internal_type("geo_location")->AsRecordType(); + geo_location = lookup_type("geo_location")->AsRecordType(); - entropy_test_result = internal_type("entropy_test_result")->AsRecordType(); + entropy_test_result = lookup_type("entropy_test_result")->AsRecordType(); - dns_msg = internal_type("dns_msg")->AsRecordType(); - dns_answer = internal_type("dns_answer")->AsRecordType(); - dns_soa = internal_type("dns_soa")->AsRecordType(); + dns_msg = lookup_type("dns_msg")->AsRecordType(); + dns_answer = lookup_type("dns_answer")->AsRecordType(); + dns_soa = lookup_type("dns_soa")->AsRecordType(); dns_edns_additional = - internal_type("dns_edns_additional")->AsRecordType(); + lookup_type("dns_edns_additional")->AsRecordType(); dns_tsig_additional = - internal_type("dns_tsig_additional")->AsRecordType(); - dns_rrsig_rr = internal_type("dns_rrsig_rr")->AsRecordType(); - dns_dnskey_rr = internal_type("dns_dnskey_rr")->AsRecordType(); - dns_nsec3_rr = internal_type("dns_nsec3_rr")->AsRecordType(); - dns_ds_rr = internal_type("dns_ds_rr")->AsRecordType(); + lookup_type("dns_tsig_additional")->AsRecordType(); + dns_rrsig_rr = lookup_type("dns_rrsig_rr")->AsRecordType(); + dns_dnskey_rr = lookup_type("dns_dnskey_rr")->AsRecordType(); + dns_nsec3_rr = lookup_type("dns_nsec3_rr")->AsRecordType(); + dns_ds_rr = lookup_type("dns_ds_rr")->AsRecordType(); dns_skip_auth = internal_val("dns_skip_auth")->AsTableVal(); dns_skip_addl = internal_val("dns_skip_addl")->AsTableVal(); dns_skip_all_auth = opt_internal_int("dns_skip_all_auth"); @@ -410,8 +412,8 @@ void init_net_var() gap_report_freq = opt_internal_double("gap_report_freq"); - irc_join_info = internal_type("irc_join_info")->AsRecordType(); - irc_join_list = internal_type("irc_join_list")->AsTableType(); + irc_join_info = lookup_type("irc_join_info")->AsRecordType(); + irc_join_list = lookup_type("irc_join_list")->AsTableType(); dpd_reassemble_first_packets = opt_internal_int("dpd_reassemble_first_packets"); @@ -425,10 +427,10 @@ void init_net_var() timer_mgr_inactivity_timeout = opt_internal_double("timer_mgr_inactivity_timeout"); - script_id = internal_type("script_id")->AsRecordType(); - 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(); + script_id = lookup_type("script_id")->AsRecordType(); + id_table = lookup_type("id_table")->AsTableType(); + record_field = lookup_type("record_field")->AsRecordType(); + record_field_table = lookup_type("record_field_table")->AsTableType(); + call_argument_vector = lookup_type("call_argument_vector")->AsVectorType(); + call_argument = lookup_type("call_argument")->AsRecordType(); } diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 14867819e8..2138c411b9 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -981,7 +981,7 @@ ParaglobVal::ParaglobVal(std::unique_ptr p) IntrusivePtr ParaglobVal::Get(StringVal* &pattern) { - auto rval = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto rval = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); std::string string_pattern (reinterpret_cast(pattern->Bytes()), pattern->Len()); std::vector matches = this->internal_paraglob->get(string_pattern); diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 315a40551f..a9f878390a 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -7,7 +7,7 @@ #include "Scope.h" #include "Func.h" #include "Val.h" -#include "Var.h" // for internal_type() +#include "Var.h" static inline bool is_established(const analyzer::tcp::TCP_Endpoint* e) { @@ -145,7 +145,7 @@ RuleConditionEval::RuleConditionEval(const char* func) rules_error("eval function type must yield a 'bool'", func); TypeList tl; - tl.Append({NewRef{}, internal_type("signature_state")}); + tl.Append(zeek::lookup_type("signature_state")); tl.Append(base_type(TYPE_STRING)); if ( ! f->CheckArgs(tl.Types()) ) diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index 02b11cf93d..17693e3f8e 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -59,22 +59,22 @@ bool BroSubstring::DoesCover(const BroSubstring* bst) const VectorVal* BroSubstring::VecToPolicy(Vec* vec) { RecordType* sw_substring_type = - internal_type("sw_substring")->AsRecordType(); + zeek::lookup_type("sw_substring")->AsRecordType(); if ( ! sw_substring_type ) return nullptr; RecordType* sw_align_type = - internal_type("sw_align")->AsRecordType(); + zeek::lookup_type("sw_align")->AsRecordType(); if ( ! sw_align_type ) return nullptr; VectorType* sw_align_vec_type = - internal_type("sw_align_vec")->AsVectorType(); + zeek::lookup_type("sw_align_vec")->AsVectorType(); if ( ! sw_align_vec_type ) return nullptr; VectorVal* result = - new VectorVal(internal_type("sw_substring_vec")->AsVectorType()); + new VectorVal(zeek::lookup_type("sw_substring_vec")->AsVectorType()); if ( ! result ) return nullptr; diff --git a/src/Stats.cc b/src/Stats.cc index 70427ebcf5..44d6a5760e 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -5,7 +5,7 @@ #include "Event.h" #include "Net.h" #include "NetVar.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "Sessions.h" #include "Scope.h" #include "DNS_Mgr.h" @@ -342,7 +342,7 @@ SampleLogger::SampleLogger() static TableType* load_sample_info = nullptr; if ( ! load_sample_info ) - load_sample_info = internal_type("load_sample_info")->AsTableType(); + load_sample_info = zeek::lookup_type("load_sample_info")->AsTableType(); load_samples = new TableVal({NewRef{}, load_sample_info}); } diff --git a/src/Stmt.cc b/src/Stmt.cc index 8879921fbf..8184581ce9 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -201,8 +201,8 @@ static IntrusivePtr lookup_enum_val(const char* module_name, const char static void print_log(const std::vector>& vals) { auto plval = lookup_enum_val("Log", "PRINTLOG"); - auto record = make_intrusive(internal_type("Log::PrintLogInfo")->AsRecordType()); - auto vec = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto record = make_intrusive(zeek::lookup_type("Log::PrintLogInfo")->AsRecordType()); + auto vec = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); for ( const auto& val : vals ) { diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 106d5dfb74..67d66ced09 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -6,7 +6,7 @@ #include "IntrusivePtr.h" #include "NetVar.h" #include "IPAddr.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "UID.h" #include @@ -198,7 +198,7 @@ public: IntrusivePtr ToVal() const { auto vv = make_intrusive( - internal_type("EncapsulatingConnVector")->AsVectorType()); + zeek::lookup_type("EncapsulatingConnVector")->AsVectorType()); if ( conns ) { diff --git a/src/Type.cc b/src/Type.cc index be18f6d059..122f5370cd 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -796,7 +796,7 @@ static string container_type_name(const BroType* ft) IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const { - auto rval = make_intrusive(IntrusivePtr{NewRef{}, internal_type("record_field_table")->AsTableType()}); + auto rval = make_intrusive(zeek::lookup_type("record_field_table")); for ( int i = 0; i < NumFields(); ++i ) { @@ -812,7 +812,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const bool logged = (fd->attrs && fd->FindAttr(ATTR_LOG) != nullptr); - auto nr = make_intrusive(internal_type("record_field")->AsRecordType()); + auto nr = make_intrusive(zeek::lookup_type("record_field")->AsRecordType()); string s = container_type_name(ft.get()); nr->Assign(0, make_intrusive(s)); diff --git a/src/Val.cc b/src/Val.cc index cf76a1771f..43d8c4825d 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -34,7 +34,7 @@ #include "Conn.h" #include "Reporter.h" #include "IPAddr.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "broker/Data.h" @@ -417,7 +417,7 @@ IntrusivePtr Val::GetRecordFields() if ( t->Tag() != TYPE_RECORD && t->Tag() != TYPE_TYPE ) { reporter->Error("non-record value/type passed to record_fields"); - return make_intrusive(IntrusivePtr{NewRef{}, internal_type("record_field_table")->AsTableType()}); + return make_intrusive(zeek::lookup_type("record_field_table")); } RecordType* rt = nullptr; @@ -435,7 +435,7 @@ IntrusivePtr Val::GetRecordFields() if ( t->Tag() != TYPE_RECORD ) { reporter->Error("non-record value/type passed to record_fields"); - return make_intrusive(IntrusivePtr{NewRef{}, internal_type("record_field_table")->AsTableType()}); + return make_intrusive(zeek::lookup_type("record_field_table")); } rt = t->AsRecordType(); @@ -1933,7 +1933,7 @@ IntrusivePtr TableVal::LookupSubnets(const SubNetVal* search) if ( ! subnets ) reporter->InternalError("LookupSubnets called on wrong table type"); - auto result = make_intrusive(internal_type("subnet_vec")->AsVectorType()); + auto result = make_intrusive(zeek::lookup_type("subnet_vec")->AsVectorType()); auto matches = subnets->FindAll(search); for ( auto element : matches ) diff --git a/src/Var.cc b/src/Var.cc index 7a5c9026d8..a78d895eb9 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -761,12 +761,17 @@ ListVal* internal_list_val(const char* name) } BroType* internal_type(const char* name) + { + return zeek::lookup_type(name).get(); + } + +const IntrusivePtr& zeek::lookup_type(const char* name) { auto id = lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) - reporter->InternalError("internal type %s missing", name); + reporter->InternalError("Failed to find type named: %s", name); - return id->GetType().get(); + return id->GetType(); } Func* internal_func(const char* name) diff --git a/src/Var.h b/src/Var.h index 92af4cd5e9..15cfd85a11 100644 --- a/src/Var.h +++ b/src/Var.h @@ -49,8 +49,33 @@ extern bro_uint_t opt_internal_unsigned(const char* name); extern StringVal* opt_internal_string(const char* name); extern TableVal* opt_internal_table(const char* name); // nil if not defined extern ListVal* internal_list_val(const char* name); + +[[deprecated("Remove in v4.1. Use zeek::lookup_type().")]] extern BroType* internal_type(const char* name); + extern Func* internal_func(const char* name); extern EventHandlerPtr internal_handler(const char* name); extern int signal_val; // 0 if no signal pending + +namespace zeek { + +/** + * Lookup an ID by its name and return its type. A fatal occurs if the ID + * does not exist. + * @param name The identifier name to lookup + * @return The type of the identifier. + */ +const IntrusivePtr& lookup_type(const char* name); + +/** + * Lookup an ID by its name and return its type (as cast to @c T). + * A fatal occurs if the ID does not exist. + * @param name The identifier name to lookup + * @return The type of the identifier. + */ +template +IntrusivePtr lookup_type(const char* name) + { return cast_intrusive(lookup_type(name)); } + +} // namespace zeek diff --git a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc index eac30667fa..d400cf771d 100644 --- a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc +++ b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc @@ -27,15 +27,15 @@ BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) if ( ! bt_tracker_headers ) { bt_tracker_headers = - internal_type("bt_tracker_headers")->AsTableType(); + zeek::lookup_type("bt_tracker_headers")->AsTableType(); bittorrent_peer = - internal_type("bittorrent_peer")->AsRecordType(); + zeek::lookup_type("bittorrent_peer")->AsRecordType(); bittorrent_peer_set = - internal_type("bittorrent_peer_set")->AsTableType(); + zeek::lookup_type("bittorrent_peer_set")->AsTableType(); bittorrent_benc_value = - internal_type("bittorrent_benc_value")->AsRecordType(); + zeek::lookup_type("bittorrent_benc_value")->AsRecordType(); bittorrent_benc_dir = - internal_type("bittorrent_benc_dir")->AsTableType(); + zeek::lookup_type("bittorrent_benc_dir")->AsTableType(); } keep_alive = false; diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 8575e5e59c..1071d0ea0e 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -726,13 +726,13 @@ IntrusivePtr ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha if ( ! icmp6_nd_option_type ) { - icmp6_nd_option_type = internal_type("icmp6_nd_option")->AsRecordType(); + icmp6_nd_option_type = zeek::lookup_type("icmp6_nd_option")->AsRecordType(); icmp6_nd_prefix_info_type = - internal_type("icmp6_nd_prefix_info")->AsRecordType(); + zeek::lookup_type("icmp6_nd_prefix_info")->AsRecordType(); } auto vv = make_intrusive( - internal_type("icmp6_nd_options")->AsVectorType()); + zeek::lookup_type("icmp6_nd_options")->AsVectorType()); while ( caplen > 0 ) { diff --git a/src/analyzer/protocol/imap/imap-analyzer.pac b/src/analyzer/protocol/imap/imap-analyzer.pac index 51afb21f0e..7e45bda7a0 100644 --- a/src/analyzer/protocol/imap/imap-analyzer.pac +++ b/src/analyzer/protocol/imap/imap-analyzer.pac @@ -59,7 +59,7 @@ refine connection IMAP_Conn += { if ( ! imap_capabilities ) return true; - auto capv = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto capv = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); for ( unsigned int i = 0; i< capabilities->size(); i++ ) { diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index 35e99ff4d9..a73c1cb5d4 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -13,7 +13,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a %code{ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) { - VectorVal* vv = new VectorVal(internal_type("KRB::Type_Value_Vector")->AsVectorType()); + VectorVal* vv = new VectorVal(zeek::lookup_type("KRB::Type_Value_Vector")->AsVectorType()); if ( ! data->data()->has_padata() ) return vv; diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index 8a70075785..dcb320efbe 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -27,7 +27,7 @@ IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pname) VectorVal* proc_cipher_list(const Array* list) { - VectorVal* ciphers = new VectorVal(internal_type("index_vec")->AsVectorType()); + VectorVal* ciphers = new VectorVal(zeek::lookup_type("index_vec")->AsVectorType()); for ( uint i = 0; i < list->data()->size(); ++i ) ciphers->Assign(ciphers->Size(), asn1_integer_to_val((*list->data())[i], TYPE_COUNT)); return ciphers; @@ -35,7 +35,7 @@ VectorVal* proc_cipher_list(const Array* list) VectorVal* proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) { - VectorVal* addrs = new VectorVal(internal_type("KRB::Host_Address_Vector")->AsVectorType()); + VectorVal* addrs = new VectorVal(zeek::lookup_type("KRB::Host_Address_Vector")->AsVectorType()); for ( uint i = 0; i < list->addresses()->size(); ++i ) { @@ -94,7 +94,7 @@ RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list) { - auto tickets = make_intrusive(internal_type("KRB::Ticket_Vector")->AsVectorType()); + auto tickets = make_intrusive(zeek::lookup_type("KRB::Ticket_Vector")->AsVectorType()); for ( uint i = 0; i < list->tickets()->size(); ++i ) { diff --git a/src/analyzer/protocol/mysql/mysql-analyzer.pac b/src/analyzer/protocol/mysql/mysql-analyzer.pac index f49fbe5625..1f49688f5e 100644 --- a/src/analyzer/protocol/mysql/mysql-analyzer.pac +++ b/src/analyzer/protocol/mysql/mysql-analyzer.pac @@ -82,7 +82,7 @@ refine flow MySQL_Flow += { if ( ! mysql_result_row ) return true; - auto vt = internal_type("string_vec")->AsVectorType(); + auto vt = zeek::lookup_type("string_vec")->AsVectorType(); auto vv = make_intrusive(vt); auto& bstring = ${msg.row.first_field.val}; diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index cddb49c547..5a0bfcd8ba 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -192,7 +192,7 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto auxgids = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for (size_t i = 0; i < c->AuxGIDs().size(); ++i) { diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index d1d7ff4b0e..82d3e519a3 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -328,7 +328,7 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_ zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto auxgids = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( size_t i = 0; i < c->AuxGIDs().size(); ++i ) auxgids->Assign(i, val_mgr->Count(c->AuxGIDs()[i])); diff --git a/src/analyzer/protocol/smb/smb2-protocol.pac b/src/analyzer/protocol/smb/smb2-protocol.pac index dd5a2a109a..861d35f22c 100644 --- a/src/analyzer/protocol/smb/smb2-protocol.pac +++ b/src/analyzer/protocol/smb/smb2-protocol.pac @@ -68,7 +68,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) rpreauth->Assign(0, val_mgr->Count(${ncv.preauth_integrity_capabilities.hash_alg_count})); rpreauth->Assign(1, val_mgr->Count(${ncv.preauth_integrity_capabilities.salt_length})); - auto ha = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto ha = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( int i = 0; i < ${ncv.preauth_integrity_capabilities.hash_alg_count}; ++i ) { @@ -87,7 +87,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rencr = make_intrusive(BifType::Record::SMB2::EncryptionCapabilities); rencr->Assign(0, val_mgr->Count(${ncv.encryption_capabilities.cipher_count})); - auto c = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto c = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( int i = 0; i < ${ncv.encryption_capabilities.cipher_count}; ++i ) { @@ -105,7 +105,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rcomp = make_intrusive(BifType::Record::SMB2::CompressionCapabilities); rcomp->Assign(0, val_mgr->Count(${ncv.compression_capabilities.alg_count})); - auto c = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto c = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( int i = 0; i < ${ncv.compression_capabilities.alg_count}; ++i ) { diff --git a/src/analyzer/protocol/ssh/ssh-analyzer.pac b/src/analyzer/protocol/ssh/ssh-analyzer.pac index 52b731ccaa..3f4c6e9c69 100644 --- a/src/analyzer/protocol/ssh/ssh-analyzer.pac +++ b/src/analyzer/protocol/ssh/ssh-analyzer.pac @@ -12,7 +12,7 @@ VectorVal* name_list_to_vector(const bytestring& nl); // Copied from IRC_Analyzer::SplitWords VectorVal* name_list_to_vector(const bytestring& nl) { - VectorVal* vv = new VectorVal(internal_type("string_vec")->AsVectorType()); + VectorVal* vv = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); string name_list = std_str(nl); if ( name_list.size() < 1 ) diff --git a/src/analyzer/protocol/ssl/proc-client-hello.pac b/src/analyzer/protocol/ssl/proc-client-hello.pac index 1eae147996..13accc5318 100644 --- a/src/analyzer/protocol/ssl/proc-client-hello.pac +++ b/src/analyzer/protocol/ssl/proc-client-hello.pac @@ -23,7 +23,7 @@ else std::transform(cipher_suites24->begin(), cipher_suites24->end(), std::back_inserter(cipher_suites), to_int()); - auto cipher_vec = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto cipher_vec = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( unsigned int i = 0; i < cipher_suites.size(); ++i ) { @@ -31,7 +31,7 @@ cipher_vec->Assign(i, ciph); } - auto comp_vec = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto comp_vec = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( compression_methods ) { diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index 46333fcd13..5db9e711a2 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -75,7 +75,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_ec_point_formats ) return true; - auto points = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto points = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( point_format_list ) { @@ -94,7 +94,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_elliptic_curves ) return true; - auto curves = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto curves = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( list ) { @@ -113,7 +113,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto nglist = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( keyshare ) { @@ -131,7 +131,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto nglist = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); nglist->Assign(0u, val_mgr->Count(keyshare->namedgroup())); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -143,7 +143,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto nglist = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); nglist->Assign(0u, val_mgr->Count(namedgroup)); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -155,7 +155,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_signature_algorithm ) return true; - auto slist = make_intrusive(internal_type("signature_and_hashalgorithm_vec")->AsVectorType()); + auto slist = make_intrusive(zeek::lookup_type("signature_and_hashalgorithm_vec")->AsVectorType()); if ( supported_signature_algorithms ) { @@ -178,7 +178,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_application_layer_protocol_negotiation ) return true; - auto plist = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto plist = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); if ( protocols ) { @@ -194,7 +194,7 @@ refine connection Handshake_Conn += { function proc_server_name(rec: HandshakeRecord, list: ServerName[]) : bool %{ - auto servers = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto servers = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); if ( list ) { @@ -226,7 +226,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto versions = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( versions_list ) { @@ -245,7 +245,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto versions = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); versions->Assign(0u, val_mgr->Count(version)); BifEvent::enqueue_ssl_extension_supported_versions(bro_analyzer(), bro_analyzer()->Conn(), @@ -259,7 +259,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_psk_key_exchange_modes ) return true; - auto modes = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto modes = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( mode_list ) { @@ -492,7 +492,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_pre_shared_key_server_hello ) return true; - auto slist = make_intrusive(internal_type("psk_identity_vec")->AsVectorType()); + auto slist = make_intrusive(zeek::lookup_type("psk_identity_vec")->AsVectorType()); if ( identities && identities->identities() ) { @@ -505,7 +505,7 @@ refine connection Handshake_Conn += { } } - auto blist = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto blist = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); if ( binders && binders->binders() ) { diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index d94f67e995..e9acdc65b5 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -1421,7 +1421,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) { auto p = reinterpret_cast(o + 2); auto num_pointers = (length - 2) / 4; - auto vt = internal_type("index_vec")->AsVectorType(); + auto vt = zeek::lookup_type("index_vec")->AsVectorType(); auto sack = new VectorVal(vt); for ( auto i = 0; i < num_pointers; ++i ) diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index 9501378a23..bb551b08b7 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -104,9 +104,9 @@ IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const if ( ! teredo_hdr_type ) { - teredo_hdr_type = internal_type("teredo_hdr")->AsRecordType(); - teredo_auth_type = internal_type("teredo_auth")->AsRecordType(); - teredo_origin_type = internal_type("teredo_origin")->AsRecordType(); + teredo_hdr_type = zeek::lookup_type("teredo_hdr")->AsRecordType(); + teredo_auth_type = zeek::lookup_type("teredo_auth")->AsRecordType(); + teredo_origin_type = zeek::lookup_type("teredo_origin")->AsRecordType(); } auto teredo_hdr = make_intrusive(teredo_hdr_type); diff --git a/src/bro-bif.h b/src/bro-bif.h index a20996152b..a2586c692d 100644 --- a/src/bro-bif.h +++ b/src/bro-bif.h @@ -7,4 +7,4 @@ #include "NetVar.h" #include "Event.h" #include "Reporter.h" -#include "Var.h" // for internal_type() +#include "Var.h" diff --git a/src/broker/Data.cc b/src/broker/Data.cc index c653256a89..bc7b1da326 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -3,7 +3,7 @@ #include "Desc.h" #include "IntrusivePtr.h" #include "RE.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "Scope.h" #include "module_util.h" #include "3rdparty/doctest.h" @@ -1154,7 +1154,7 @@ IntrusivePtr bro_broker::DataVal::castTo(BroType* t) BroType* bro_broker::DataVal::ScriptDataType() { if ( ! script_data_type ) - script_data_type = internal_type("Broker::Data"); + script_data_type = zeek::lookup_type("Broker::Data").get(); return script_data_type; } diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index c5be4b918b..ee93f3b4e7 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -149,8 +149,8 @@ void Manager::InitPostScript() default_log_topic_prefix = get_option("Broker::default_log_topic_prefix")->AsString()->CheckString(); log_topic_func = get_option("Broker::log_topic")->AsFunc(); - log_id_type = internal_type("Log::ID")->AsEnumType(); - writer_id_type = internal_type("Log::Writer")->AsEnumType(); + log_id_type = zeek::lookup_type("Log::ID")->AsEnumType(); + writer_id_type = zeek::lookup_type("Log::Writer")->AsEnumType(); opaque_of_data_type = new OpaqueType("Broker::Data"); opaque_of_set_iterator = new OpaqueType("Broker::SetIterator"); @@ -158,7 +158,7 @@ void Manager::InitPostScript() opaque_of_vector_iterator = new OpaqueType("Broker::VectorIterator"); opaque_of_record_iterator = new OpaqueType("Broker::RecordIterator"); opaque_of_store_handle = new OpaqueType("Broker::Store"); - vector_of_data_type = new VectorType({NewRef{}, internal_type("Broker::Data")}); + vector_of_data_type = new VectorType(zeek::lookup_type("Broker::Data")); // Register as a "dont-count" source first, we may change that later. iosource_mgr->Register(this, true); @@ -1246,13 +1246,13 @@ void Manager::ProcessStatus(broker::status stat) if ( ! event ) return; - auto ei = internal_type("Broker::EndpointInfo")->AsRecordType(); + auto ei = zeek::lookup_type("Broker::EndpointInfo")->AsRecordType(); auto endpoint_info = make_intrusive(ei); if ( ctx ) { endpoint_info->Assign(0, make_intrusive(to_string(ctx->node))); - auto ni = internal_type("Broker::NetworkInfo")->AsRecordType(); + auto ni = zeek::lookup_type("Broker::NetworkInfo")->AsRecordType(); auto network_info = make_intrusive(ni); if ( ctx->network ) diff --git a/src/broker/Store.cc b/src/broker/Store.cc index 81138edcd9..5502179af8 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -1,6 +1,6 @@ #include "Store.h" #include "Desc.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "broker/Manager.h" namespace bro_broker { @@ -15,7 +15,7 @@ EnumVal* query_status(bool success) if ( ! store_query_status ) { - store_query_status = internal_type("Broker::QueryStatus")->AsEnumType(); + store_query_status = zeek::lookup_type("Broker::QueryStatus")->AsEnumType(); success_val = store_query_status->Lookup("Broker", "SUCCESS"); failure_val = store_query_status->Lookup("Broker", "FAILURE"); } diff --git a/src/broker/comm.bif b/src/broker/comm.bif index 4d8ee6c096..aa19638dcc 100644 --- a/src/broker/comm.bif +++ b/src/broker/comm.bif @@ -94,14 +94,14 @@ function Broker::__unpeer%(a: string, p: port%): bool function Broker::__peers%(%): PeerInfos %{ bro_broker::Manager::ScriptScopeGuard ssg; - auto rval = make_intrusive(internal_type("Broker::PeerInfos")->AsVectorType()); + auto rval = make_intrusive(zeek::lookup_type("Broker::PeerInfos")->AsVectorType()); auto i = 0; for ( auto& p : broker_mgr->Peers() ) { - auto pi = internal_type("Broker::PeerInfo")->AsRecordType(); - auto ei = internal_type("Broker::EndpointInfo")->AsRecordType(); - auto ni = internal_type("Broker::NetworkInfo")->AsRecordType(); + auto pi = zeek::lookup_type("Broker::PeerInfo")->AsRecordType(); + auto ei = zeek::lookup_type("Broker::EndpointInfo")->AsRecordType(); + auto ni = zeek::lookup_type("Broker::NetworkInfo")->AsRecordType(); auto peer_info = new RecordVal(pi); auto endpoint_info = new RecordVal(ei); auto network_info = new RecordVal(ni); diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index 56f110563a..3549ec5267 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -11,7 +11,7 @@ VectorVal* process_rvas(const RVAS* rvas); %code{ VectorVal* process_rvas(const RVAS* rva_table) { - VectorVal* rvas = new VectorVal(internal_type("index_vec")->AsVectorType()); + VectorVal* rvas = new VectorVal(zeek::lookup_type("index_vec")->AsVectorType()); for ( uint16 i=0; i < rva_table->rvas()->size(); ++i ) rvas->Assign(i, val_mgr->Count((*rva_table->rvas())[i]->size())); @@ -25,7 +25,7 @@ refine flow File += { function characteristics_to_bro(c: uint32, len: uint8): TableVal %{ uint64 mask = (len==16) ? 0xFFFF : 0xFFFFFFFF; - TableVal* char_set = new TableVal({NewRef{}, internal_type("count_set")->AsTableType()}); + TableVal* char_set = new TableVal(zeek::lookup_type("count_set")); for ( uint16 i=0; i < len; ++i ) { if ( ((c >> i) & 0x1) == 1 ) diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index 3eb9b423c9..7355058eb8 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -634,7 +634,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp) //ocsp_resp_record->Assign(7, make_intrusive(len, buf)); //BIO_reset(bio); - certs_vector = new VectorVal(internal_type("x509_opaque_vector")->AsVectorType()); + certs_vector = new VectorVal(zeek::lookup_type("x509_opaque_vector")->AsVectorType()); vl.emplace_back(AdoptRef{}, certs_vector); #if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER) diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index d32c8434e8..b3fffdce23 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -367,21 +367,21 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) { case GEN_DNS: if ( names == nullptr ) - names = new VectorVal(internal_type("string_vec")->AsVectorType()); + names = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); names->Assign(names->Size(), bs); break; case GEN_URI: if ( uris == nullptr ) - uris = new VectorVal(internal_type("string_vec")->AsVectorType()); + uris = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); uris->Assign(uris->Size(), bs); break; case GEN_EMAIL: if ( emails == nullptr ) - emails = new VectorVal(internal_type("string_vec")->AsVectorType()); + emails = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); emails->Assign(emails->Size(), bs); break; @@ -391,7 +391,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) else if ( gen->type == GEN_IPADD ) { if ( ips == nullptr ) - ips = new VectorVal(internal_type("addr_vec")->AsVectorType()); + ips = new VectorVal(zeek::lookup_type("addr_vec")->AsVectorType()); uint32_t* addr = (uint32_t*) gen->d.ip->data; diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index f45bd422ea..5eba5a776d 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -556,7 +556,7 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str } int num_certs = sk_X509_num(chain); - chainVector = new VectorVal(internal_type("x509_opaque_vector")->AsVectorType()); + chainVector = new VectorVal(zeek::lookup_type("x509_opaque_vector")->AsVectorType()); for ( int i = 0; i < num_certs; i++ ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 5f0933d234..3b37a33e2a 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1276,7 +1276,7 @@ bool Manager::WriteFromRemote(EnumVal* id, EnumVal* writer, const string& path, void Manager::SendAllWritersTo(const broker::endpoint_info& ei) { - auto et = internal_type("Log::Writer")->AsEnumType(); + auto et = zeek::lookup_type("Log::Writer")->AsEnumType(); for ( vector::iterator s = streams.begin(); s != streams.end(); ++s ) { diff --git a/src/stats.bif b/src/stats.bif index 94baccc78a..30853711a7 100644 --- a/src/stats.bif +++ b/src/stats.bif @@ -470,7 +470,7 @@ function get_reporter_stats%(%): ReporterStats auto r = make_intrusive(ReporterStats); int n = 0; - TableVal* weirds_by_type = new TableVal({NewRef{}, internal_type("table_string_of_count")->AsTableType()}); + auto weirds_by_type = make_intrusive(zeek::lookup_type("table_string_of_count")); for ( auto& kv : reporter->GetWeirdsByType() ) { @@ -479,7 +479,7 @@ function get_reporter_stats%(%): ReporterStats } r->Assign(n++, val_mgr->Count(reporter->GetWeirdCount())); - r->Assign(n++, weirds_by_type); + r->Assign(n++, std::move(weirds_by_type)); return r; %} diff --git a/src/strings.bif b/src/strings.bif index 06ce9939c3..fca92c980d 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -204,7 +204,7 @@ static IntrusivePtr do_split_string(StringVal* str_val, int max_num_sep) { // string_vec is used early in the version script - do not use the NetVar. - auto rval = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto rval = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); const u_char* s = str_val->Bytes(); int n = str_val->Len(); const u_char* end_of_s = s + n; @@ -714,7 +714,7 @@ function str_split%(s: string, idx: index_vec%): string_vec BroString::Vec* result = s->AsString()->Split(indices); auto result_v = make_intrusive( - internal_type("string_vec")->AsVectorType()); + zeek::lookup_type("string_vec")->AsVectorType()); if ( result ) { diff --git a/src/zeek.bif b/src/zeek.bif index 91e7d82000..1bd4227ec2 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -30,6 +30,7 @@ #include "Hash.h" using namespace std; +using namespace zeek; TableType* var_sizes; @@ -1470,7 +1471,7 @@ function sort%(v: any, ...%) : any function order%(v: any, ...%) : index_vec %{ auto result_v = make_intrusive( - internal_type("index_vec")->AsVectorType()); + lookup_type("index_vec")->AsVectorType()); if ( v->Type()->Tag() != TYPE_VECTOR ) { @@ -1824,15 +1825,12 @@ function zeek_version%(%): string function record_type_to_vector%(rt: string%): string_vec %{ auto result = - make_intrusive(internal_type("string_vec")->AsVectorType()); + make_intrusive(lookup_type("string_vec")->AsVectorType()); - RecordType *type = internal_type(rt->CheckString())->AsRecordType(); + RecordType* type = lookup_type(rt->CheckString())->AsRecordType(); - if ( type ) - { - for ( int i = 0; i < type->NumFields(); ++i ) - result->Assign(i+1, make_intrusive(type->FieldName(i))); - } + for ( int i = 0; i < type->NumFields(); ++i ) + result->Assign(i+1, make_intrusive(type->FieldName(i))); return result; %} @@ -1856,7 +1854,7 @@ function type_name%(t: any%): string ## Returns: list of command-line arguments (``argv``) used to run Zeek. function zeek_args%(%): string_vec %{ - auto sv = internal_type("string_vec")->AsVectorType(); + auto sv = lookup_type("string_vec")->AsVectorType(); auto rval = make_intrusive(sv); for ( auto i = 0; i < bro_argc; ++i ) @@ -1894,7 +1892,7 @@ function reading_traces%(%): bool ## .. zeek:see:: reading_live_traffic reading_traces function packet_source%(%): PacketSource %{ - auto ps_type = internal_type("PacketSource")->AsRecordType(); + auto ps_type = lookup_type("PacketSource")->AsRecordType(); auto ps = iosource_mgr->GetPktSrc(); auto r = make_intrusive(ps_type); @@ -2002,7 +2000,7 @@ function record_fields%(rec: any%): record_field_table if ( ! id || ! id->IsType() || id->GetType()->Tag() != TYPE_RECORD ) { reporter->Error("record_fields string argument does not name a record type"); - IntrusivePtr tt{NewRef{}, internal_type("record_field_table")->AsTableType()}; + auto tt = lookup_type("record_field_table"); return make_intrusive(std::move(tt)); } @@ -2189,7 +2187,7 @@ function is_v6_subnet%(s: subnet%): bool ## Returns: The vector of addresses contained in the routing header data. function routing0_data_to_addrs%(s: string%): addr_vec %{ - auto rval = make_intrusive(internal_type("addr_vec")->AsVectorType()); + auto rval = make_intrusive(lookup_type("addr_vec")->AsVectorType()); int len = s->Len(); const u_char* bytes = s->Bytes(); @@ -2220,7 +2218,7 @@ function routing0_data_to_addrs%(s: string%): addr_vec ## .. zeek:see:: counts_to_addr function addr_to_counts%(a: addr%): index_vec %{ - auto rval = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto rval = make_intrusive(lookup_type("index_vec")->AsVectorType()); const uint32_t* bytes; int len = a->AsAddr().GetBytes(&bytes); From a83941d64d3fde10d2e7e020a8571af4fc7abf7a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 8 May 2020 18:43:56 -0700 Subject: [PATCH 032/151] Deprecate internal_val() and internal_const_val() Replaced with zeek::lookup_val() and zeek::lookup_const() --- NEWS | 3 +++ aux/bifcl | 2 +- src/NetVar.cc | 40 +++++++++++++++++----------------- src/Reporter.cc | 16 +++++++------- src/Stmt.cc | 2 +- src/Var.cc | 42 +++++++++++++++++++++++------------- src/Var.h | 21 ++++++++++++++++++ src/file_analysis/Manager.cc | 2 +- src/logging/Manager.cc | 2 +- src/zeek-setup.cc | 4 ++-- 10 files changed, 85 insertions(+), 49 deletions(-) diff --git a/NEWS b/NEWS index 0d9a23688e..894380cb67 100644 --- a/NEWS +++ b/NEWS @@ -161,6 +161,9 @@ Deprecated Functionality - ``internal_type()`` is deprecated, use ``zeek::lookup_type()``. +- ``internal_val()`` and ``internal_const_val()`` are deprecated, use + ``zeek::lookup_val()`` or ``zeek::lookup_const()``. + Zeek 3.1.0 ========== diff --git a/aux/bifcl b/aux/bifcl index 2d9b8606d5..883d7174c8 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 2d9b8606d5d7e4ec4a67cc11a72d38c2241ee871 +Subproject commit 883d7174c8d80a44910855b05482fe107a60e55c diff --git a/src/NetVar.cc b/src/NetVar.cc index 2fcc92735a..b6ee3332e4 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -219,7 +219,7 @@ void init_general_global_var() log_rotate_base_time = opt_internal_string("log_rotate_base_time"); peer_description = - internal_val("peer_description")->AsStringVal(); + zeek::lookup_val("peer_description")->AsStringVal(); packet_filter_default = opt_internal_int("packet_filter_default"); @@ -230,12 +230,12 @@ void init_general_global_var() suppress_local_output = opt_internal_int("suppress_local_output"); - trace_output_file = internal_val("trace_output_file")->AsStringVal(); + trace_output_file = zeek::lookup_val("trace_output_file")->AsStringVal(); record_all_packets = opt_internal_int("record_all_packets"); cmd_line_bpf_filter = - internal_val("cmd_line_bpf_filter")->AsStringVal(); + zeek::lookup_val("cmd_line_bpf_filter")->AsStringVal(); global_hash_seed = opt_internal_string("global_hash_seed"); @@ -306,31 +306,31 @@ void init_net_var() opt_internal_double("tcp_storm_interarrival_thresh"); tcp_reassembler_ports_orig = - internal_val("tcp_reassembler_ports_orig")->AsTableVal(); + zeek::lookup_val("tcp_reassembler_ports_orig")->AsTableVal(); tcp_reassembler_ports_resp = - internal_val("tcp_reassembler_ports_resp")->AsTableVal(); + zeek::lookup_val("tcp_reassembler_ports_resp")->AsTableVal(); tcp_content_delivery_ports_orig = - internal_val("tcp_content_delivery_ports_orig")->AsTableVal(); + zeek::lookup_val("tcp_content_delivery_ports_orig")->AsTableVal(); tcp_content_delivery_ports_resp = - internal_val("tcp_content_delivery_ports_resp")->AsTableVal(); + zeek::lookup_val("tcp_content_delivery_ports_resp")->AsTableVal(); tcp_content_deliver_all_orig = - bool(internal_val("tcp_content_deliver_all_orig")->AsBool()); + bool(zeek::lookup_val("tcp_content_deliver_all_orig")->AsBool()); tcp_content_deliver_all_resp = - bool(internal_val("tcp_content_deliver_all_resp")->AsBool()); + bool(zeek::lookup_val("tcp_content_deliver_all_resp")->AsBool()); udp_content_delivery_ports_orig = - internal_val("udp_content_delivery_ports_orig")->AsTableVal(); + zeek::lookup_val("udp_content_delivery_ports_orig")->AsTableVal(); udp_content_delivery_ports_resp = - internal_val("udp_content_delivery_ports_resp")->AsTableVal(); + zeek::lookup_val("udp_content_delivery_ports_resp")->AsTableVal(); udp_content_ports = - internal_val("udp_content_ports")->AsTableVal(); + zeek::lookup_val("udp_content_ports")->AsTableVal(); udp_content_deliver_all_orig = - bool(internal_val("udp_content_deliver_all_orig")->AsBool()); + bool(zeek::lookup_val("udp_content_deliver_all_orig")->AsBool()); udp_content_deliver_all_resp = - bool(internal_val("udp_content_deliver_all_resp")->AsBool()); + bool(zeek::lookup_val("udp_content_deliver_all_resp")->AsBool()); udp_content_delivery_ports_use_resp = - bool(internal_val("udp_content_delivery_ports_use_resp")->AsBool()); + bool(zeek::lookup_val("udp_content_delivery_ports_use_resp")->AsBool()); dns_session_timeout = opt_internal_double("dns_session_timeout"); rpc_timeout = opt_internal_double("rpc_timeout"); @@ -377,15 +377,15 @@ void init_net_var() dns_dnskey_rr = lookup_type("dns_dnskey_rr")->AsRecordType(); dns_nsec3_rr = lookup_type("dns_nsec3_rr")->AsRecordType(); dns_ds_rr = lookup_type("dns_ds_rr")->AsRecordType(); - dns_skip_auth = internal_val("dns_skip_auth")->AsTableVal(); - dns_skip_addl = internal_val("dns_skip_addl")->AsTableVal(); + dns_skip_auth = zeek::lookup_val("dns_skip_auth")->AsTableVal(); + dns_skip_addl = zeek::lookup_val("dns_skip_addl")->AsTableVal(); dns_skip_all_auth = opt_internal_int("dns_skip_all_auth"); dns_skip_all_addl = opt_internal_int("dns_skip_all_addl"); dns_max_queries = opt_internal_int("dns_max_queries"); stp_delta = opt_internal_double("stp_delta"); stp_idle_min = opt_internal_double("stp_idle_min"); - stp_skip_src = internal_val("stp_skip_src")->AsTableVal(); + stp_skip_src = zeek::lookup_val("stp_skip_src")->AsTableVal(); orig_addr_anonymization = opt_internal_int("orig_addr_anonymization"); resp_addr_anonymization = opt_internal_int("resp_addr_anonymization"); @@ -398,7 +398,7 @@ void init_net_var() connection_status_update_interval = opt_internal_double("connection_status_update_interval"); - profiling_file = internal_val("profiling_file"); + profiling_file = zeek::lookup_val("profiling_file").get(); expensive_profiling_multiple = opt_internal_int("expensive_profiling_multiple"); profiling_interval = opt_internal_double("profiling_interval"); @@ -422,7 +422,7 @@ void init_net_var() dpd_late_match_stop = opt_internal_int("dpd_late_match_stop"); dpd_ignore_ports = opt_internal_int("dpd_ignore_ports"); - likely_server_ports = internal_val("likely_server_ports")->AsTableVal(); + likely_server_ports = zeek::lookup_val("likely_server_ports")->AsTableVal(); timer_mgr_inactivity_timeout = opt_internal_double("timer_mgr_inactivity_timeout"); diff --git a/src/Reporter.cc b/src/Reporter.cc index 4f6393d78d..57d35b7baf 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -15,7 +15,7 @@ #include "Net.h" #include "Conn.h" #include "Timer.h" -#include "Var.h" // for internal_val() +#include "Var.h" #include "EventHandler.h" #include "plugin/Plugin.h" #include "plugin/Manager.h" @@ -63,13 +63,13 @@ Reporter::~Reporter() void Reporter::InitOptions() { - info_to_stderr = internal_val("Reporter::info_to_stderr")->AsBool(); - warnings_to_stderr = internal_val("Reporter::warnings_to_stderr")->AsBool(); - errors_to_stderr = internal_val("Reporter::errors_to_stderr")->AsBool(); - weird_sampling_rate = internal_val("Weird::sampling_rate")->AsCount(); - weird_sampling_threshold = internal_val("Weird::sampling_threshold")->AsCount(); - weird_sampling_duration = internal_val("Weird::sampling_duration")->AsInterval(); - auto wl_val = internal_val("Weird::sampling_whitelist")->AsTableVal(); + info_to_stderr = zeek::lookup_val("Reporter::info_to_stderr")->AsBool(); + warnings_to_stderr = zeek::lookup_val("Reporter::warnings_to_stderr")->AsBool(); + errors_to_stderr = zeek::lookup_val("Reporter::errors_to_stderr")->AsBool(); + weird_sampling_rate = zeek::lookup_val("Weird::sampling_rate")->AsCount(); + weird_sampling_threshold = zeek::lookup_val("Weird::sampling_threshold")->AsCount(); + weird_sampling_duration = zeek::lookup_val("Weird::sampling_duration")->AsInterval(); + auto wl_val = zeek::lookup_val("Weird::sampling_whitelist")->AsTableVal(); auto wl_table = wl_val->AsTable(); HashKey* k; diff --git a/src/Stmt.cc b/src/Stmt.cc index 8184581ce9..2ce3760b94 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -237,7 +237,7 @@ IntrusivePtr PrintStmt::DoExec(std::vector> vals, } static auto print_log_type = static_cast( - internal_val("Log::print_to_log")->AsEnum()); + zeek::lookup_val("Log::print_to_log")->AsEnum()); switch ( print_log_type ) { case BifEnum::Log::REDIRECT_NONE: diff --git a/src/Var.cc b/src/Var.cc index a78d895eb9..95f36bec5f 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -657,12 +657,7 @@ void end_func(IntrusivePtr body) Val* internal_val(const char* name) { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); - - if ( ! id ) - reporter->InternalError("internal variable %s missing", name); - - return id->GetVal().get(); + return zeek::lookup_val(name).get(); } id_list gather_outer_ids(Scope* scope, Stmt* body) @@ -687,14 +682,7 @@ id_list gather_outer_ids(Scope* scope, Stmt* body) Val* internal_const_val(const char* name) { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); - if ( ! id ) - reporter->InternalError("internal variable %s missing", name); - - if ( ! id->IsConst() ) - reporter->InternalError("internal variable %s is not constant", name); - - return id->GetVal().get(); + return zeek::lookup_const(name).get(); } Val* opt_internal_val(const char* name) @@ -765,6 +753,29 @@ BroType* internal_type(const char* name) return zeek::lookup_type(name).get(); } +const IntrusivePtr& zeek::lookup_val(const char* name) + { + auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + + if ( ! id ) + reporter->InternalError("Failed to find variable named: %s", name); + + return id->GetVal(); + } + +const IntrusivePtr& zeek::lookup_const(const char* name) + { + auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + + if ( ! id ) + reporter->InternalError("Failed to find variable named: %s", name); + + if ( ! id->IsConst() ) + reporter->InternalError("Variable is not 'const', but expected to be: %s", name); + + return id->GetVal(); + } + const IntrusivePtr& zeek::lookup_type(const char* name) { auto id = lookup_ID(name, GLOBAL_MODULE_NAME); @@ -776,7 +787,8 @@ const IntrusivePtr& zeek::lookup_type(const char* name) Func* internal_func(const char* name) { - Val* v = internal_val(name); + const auto& v = zeek::lookup_val(name); + if ( v ) return v->AsFunc(); else diff --git a/src/Var.h b/src/Var.h index 15cfd85a11..f9524e6ec1 100644 --- a/src/Var.h +++ b/src/Var.h @@ -40,8 +40,12 @@ extern void end_func(IntrusivePtr body); // Gather all IDs referenced inside a body that aren't part of a given scope. extern id_list gather_outer_ids(Scope* scope, Stmt* body); +[[deprecated("Remove in v4.1. Use zeek::lookup_val().")]] extern Val* internal_val(const char* name); + +[[deprecated("Remove in v4.1. Use zeek::lookup_const().")]] extern Val* internal_const_val(const char* name); // internal error if not const + extern Val* opt_internal_val(const char* name); // returns nil if not defined extern double opt_internal_double(const char* name); extern bro_int_t opt_internal_int(const char* name); @@ -54,6 +58,7 @@ extern ListVal* internal_list_val(const char* name); extern BroType* internal_type(const char* name); extern Func* internal_func(const char* name); + extern EventHandlerPtr internal_handler(const char* name); extern int signal_val; // 0 if no signal pending @@ -78,4 +83,20 @@ template IntrusivePtr lookup_type(const char* name) { return cast_intrusive(lookup_type(name)); } +/** + * Lookup an ID by its name and return its value. A fatal occurs if the ID + * does not exist. + * @param name The identifier name to lookup + * @return The current value of the identifier + */ +const IntrusivePtr& lookup_val(const char* name); + +/** + * Lookup an ID by its name and return its value. A fatal occurs if the ID + * does not exist or if it is not "const". + * @param name The identifier name to lookup + * @return The current value of the identifier + */ +const IntrusivePtr& lookup_const(const char* name); + } // namespace zeek diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index f9e843ddf3..a566219b5c 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -432,7 +432,7 @@ string Manager::GetFileID(const analyzer::Tag& tag, Connection* c, bool is_orig) bool Manager::IsDisabled(const analyzer::Tag& tag) { if ( ! disabled ) - disabled = internal_const_val("Files::disable")->AsTableVal(); + disabled = zeek::lookup_const("Files::disable")->AsTableVal(); auto index = val_mgr->Count(bool(tag)); auto yield = disabled->Lookup(index.get()); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 3b37a33e2a..343af8a5a1 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -313,7 +313,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) streams[idx]->event = event ? event_registry->Lookup(event->Name()) : nullptr; streams[idx]->columns = columns->Ref()->AsRecordType(); - streams[idx]->enable_remote = internal_val("Log::enable_remote_logging")->AsBool(); + streams[idx]->enable_remote = zeek::lookup_val("Log::enable_remote_logging")->AsBool(); DBG_LOG(DBG_LOGGING, "Created new logging stream '%s', raising event %s", streams[idx]->name.c_str(), event ? streams[idx]->event->Name() : ""); diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index cb5e3bd49c..c895349138 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -363,7 +363,7 @@ static std::vector get_script_signature_files() // Parse rule files defined on the script level. char* script_signature_files = - copy_string(internal_val("signature_files")->AsString()->CheckString()); + copy_string(zeek::lookup_val("signature_files")->AsString()->CheckString()); char* tmp = script_signature_files; char* s; @@ -724,7 +724,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, if ( ! options.pcap_file && ! options.interface ) { - Val* interfaces_val = internal_val("interfaces"); + const auto& interfaces_val = zeek::lookup_val("interfaces"); if ( interfaces_val ) { char* interfaces_str = From 26f6fe01c8b46786bfbdc9fb36da67f0b848b463 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 8 May 2020 19:12:53 -0700 Subject: [PATCH 033/151] Deprecate internal_func(), replace with zeek::lookup_func() --- NEWS | 2 ++ src/Discard.cc | 8 ++++---- src/Discard.h | 10 ++++++---- src/Var.cc | 13 +++++++++++++ src/Var.h | 9 +++++++++ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 894380cb67..db3192a824 100644 --- a/NEWS +++ b/NEWS @@ -164,6 +164,8 @@ Deprecated Functionality - ``internal_val()`` and ``internal_const_val()`` are deprecated, use ``zeek::lookup_val()`` or ``zeek::lookup_const()``. +- ``internal_func()`` is deprecated, use ``zeek::lookup_func()``. + Zeek 3.1.0 ========== diff --git a/src/Discard.cc b/src/Discard.cc index 3e87ca0bc7..4386874ad8 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -16,10 +16,10 @@ Discarder::Discarder() { - check_ip = internal_func("discarder_check_ip"); - check_tcp = internal_func("discarder_check_tcp"); - check_udp = internal_func("discarder_check_udp"); - check_icmp = internal_func("discarder_check_icmp"); + check_ip = zeek::lookup_func("discarder_check_ip"); + check_tcp = zeek::lookup_func("discarder_check_tcp"); + check_udp = zeek::lookup_func("discarder_check_udp"); + check_icmp = zeek::lookup_func("discarder_check_icmp"); discarder_maxlen = static_cast(opt_internal_int("discarder_maxlen")); } diff --git a/src/Discard.h b/src/Discard.h index 01b55d6e4a..ac69db845f 100644 --- a/src/Discard.h +++ b/src/Discard.h @@ -4,6 +4,8 @@ #include // for u_char +#include "IntrusivePtr.h" + class IP_Hdr; class Val; class Func; @@ -20,10 +22,10 @@ public: protected: Val* BuildData(const u_char* data, int hdrlen, int len, int caplen); - Func* check_ip; - Func* check_tcp; - Func* check_udp; - Func* check_icmp; + IntrusivePtr check_ip; + IntrusivePtr check_tcp; + IntrusivePtr check_udp; + IntrusivePtr check_icmp; // Maximum amount of application data passed to filtering functions. int discarder_maxlen; diff --git a/src/Var.cc b/src/Var.cc index 95f36bec5f..c8d7fbc7c9 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -795,6 +795,19 @@ Func* internal_func(const char* name) return nullptr; } +IntrusivePtr zeek::lookup_func(const char* name) + { + const auto& v = zeek::lookup_val(name); + + if ( ! v ) + return nullptr; + + if ( ! IsFunc(v->Type()->Tag()) ) + reporter->InternalError("Expected variable '%s' to be a function", name); + + return {NewRef{}, v->AsFunc()}; + } + EventHandlerPtr internal_handler(const char* name) { // If there already is an entry in the registry, we have a diff --git a/src/Var.h b/src/Var.h index f9524e6ec1..569a1bf047 100644 --- a/src/Var.h +++ b/src/Var.h @@ -57,6 +57,7 @@ extern ListVal* internal_list_val(const char* name); [[deprecated("Remove in v4.1. Use zeek::lookup_type().")]] extern BroType* internal_type(const char* name); +[[deprecated("Remove in v4.1. Use zeek::lookup_func().")]] extern Func* internal_func(const char* name); extern EventHandlerPtr internal_handler(const char* name); @@ -99,4 +100,12 @@ const IntrusivePtr& lookup_val(const char* name); */ const IntrusivePtr& lookup_const(const char* name); +/** + * Lookup an ID by its name and return the function it references. + * A fatal occurs if the ID does not exist or if it is not a function. + * @param name The identifier name to lookup + * @return The current function value the identifier references. + */ +IntrusivePtr lookup_func(const char* name); + } // namespace zeek From 447b052d11b85b4130ab0d86bf2055af525e8f6b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 8 May 2020 19:38:24 -0700 Subject: [PATCH 034/151] Deprecate opt_internal_val() --- NEWS | 3 +++ src/NetVar.cc | 2 +- src/Var.cc | 20 +++++++++++++++----- src/Var.h | 2 ++ src/scan.l | 3 ++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index db3192a824..8f4d16effd 100644 --- a/NEWS +++ b/NEWS @@ -166,6 +166,9 @@ Deprecated Functionality - ``internal_func()`` is deprecated, use ``zeek::lookup_func()``. +- ``opt_internal_val()`` is deprecated, use ``lookup_ID()`` or + ``zeek::lookup_val()``. + Zeek 3.1.0 ========== diff --git a/src/NetVar.cc b/src/NetVar.cc index b6ee3332e4..245e7e43ef 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -406,7 +406,7 @@ void init_net_var() pkt_profile_mode = opt_internal_int("pkt_profile_mode"); pkt_profile_freq = opt_internal_double("pkt_profile_freq"); - pkt_profile_file = opt_internal_val("pkt_profile_file"); + pkt_profile_file = zeek::lookup_val("pkt_profile_file").get(); load_sample_freq = opt_internal_int("load_sample_freq"); diff --git a/src/Var.cc b/src/Var.cc index c8d7fbc7c9..4f7d677eac 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -693,31 +693,41 @@ Val* opt_internal_val(const char* name) double opt_internal_double(const char* name) { - Val* v = opt_internal_val(name); + auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + if ( ! id ) return 0.0; + const auto& v = id->GetVal(); return v ? v->InternalDouble() : 0.0; } bro_int_t opt_internal_int(const char* name) { - Val* v = opt_internal_val(name); + auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + if ( ! id ) return 0; + const auto& v = id->GetVal(); return v ? v->InternalInt() : 0; } bro_uint_t opt_internal_unsigned(const char* name) { - Val* v = opt_internal_val(name); + auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + if ( ! id ) return 0; + const auto& v = id->GetVal(); return v ? v->InternalUnsigned() : 0; } StringVal* opt_internal_string(const char* name) { - Val* v = opt_internal_val(name); + auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + if ( ! id ) return nullptr; + const auto& v = id->GetVal(); return v ? v->AsStringVal() : nullptr; } TableVal* opt_internal_table(const char* name) { - Val* v = opt_internal_val(name); + auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + if ( ! id ) return nullptr; + const auto& v = id->GetVal(); return v ? v->AsTableVal() : nullptr; } diff --git a/src/Var.h b/src/Var.h index 569a1bf047..268445f9c3 100644 --- a/src/Var.h +++ b/src/Var.h @@ -46,7 +46,9 @@ extern Val* internal_val(const char* name); [[deprecated("Remove in v4.1. Use zeek::lookup_const().")]] extern Val* internal_const_val(const char* name); // internal error if not const +[[deprecated("Remove in v4.1. Use lookup_ID() or zeek::lookup_val().")]] extern Val* opt_internal_val(const char* name); // returns nil if not defined + extern double opt_internal_double(const char* name); extern bro_int_t opt_internal_int(const char* name); extern bro_uint_t opt_internal_unsigned(const char* name); diff --git a/src/scan.l b/src/scan.l index 0fd1a65085..fdd4bac766 100644 --- a/src/scan.l +++ b/src/scan.l @@ -1000,7 +1000,8 @@ int yywrap() // string type.) If no type is found, the value // is left unchanged. std::string opt_quote; // no optional quote by default - Val* v = opt_internal_val(param); + auto param_id = lookup_ID(param, GLOBAL_MODULE_NAME); + Val* v = param_id ? param_id->GetVal().get() : nullptr; if ( v && v->Type() && v->Type()->Tag() == TYPE_STRING ) opt_quote = "\""; // use quotes From c5236ecaee14f01bc1b6788d0fd77593ca54889c Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 8 May 2020 20:08:02 -0700 Subject: [PATCH 035/151] Deprecate internal_list_val() --- src/NetVar.cc | 16 ---------------- src/NetVar.h | 8 -------- src/Var.h | 2 ++ src/analyzer/protocol/login/Login.cc | 23 ++++++++++++++++------- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/NetVar.cc b/src/NetVar.cc index 245e7e43ef..74cc7ca2df 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -85,14 +85,6 @@ bool udp_content_delivery_ports_use_resp; double dns_session_timeout; double rpc_timeout; -ListVal* skip_authentication; -ListVal* direct_login_prompts; -ListVal* login_prompts; -ListVal* login_non_failure_msgs; -ListVal* login_failure_msgs; -ListVal* login_success_msgs; -ListVal* login_timeouts; - int mime_segment_length; int mime_segment_overlap_length; RecordType* mime_header_rec; @@ -339,14 +331,6 @@ void init_net_var() max_timer_expires = opt_internal_int("max_timer_expires"); - skip_authentication = internal_list_val("skip_authentication"); - direct_login_prompts = internal_list_val("direct_login_prompts"); - login_prompts = internal_list_val("login_prompts"); - login_non_failure_msgs = internal_list_val("login_non_failure_msgs"); - login_failure_msgs = internal_list_val("login_failure_msgs"); - login_success_msgs = internal_list_val("login_success_msgs"); - login_timeouts = internal_list_val("login_timeouts"); - mime_segment_length = opt_internal_int("mime_segment_length"); mime_segment_overlap_length = opt_internal_int("mime_segment_overlap_length"); mime_header_rec = lookup_type("mime_header_rec")->AsRecordType(); diff --git a/src/NetVar.h b/src/NetVar.h index 07b1b92f10..fa76529197 100644 --- a/src/NetVar.h +++ b/src/NetVar.h @@ -83,14 +83,6 @@ extern bool udp_content_delivery_ports_use_resp; extern double dns_session_timeout; extern double rpc_timeout; -extern ListVal* skip_authentication; -extern ListVal* direct_login_prompts; -extern ListVal* login_prompts; -extern ListVal* login_non_failure_msgs; -extern ListVal* login_failure_msgs; -extern ListVal* login_success_msgs; -extern ListVal* login_timeouts; - extern int mime_segment_length; extern int mime_segment_overlap_length; extern RecordType* mime_header_rec; diff --git a/src/Var.h b/src/Var.h index 268445f9c3..0d495f92b4 100644 --- a/src/Var.h +++ b/src/Var.h @@ -54,6 +54,8 @@ extern bro_int_t opt_internal_int(const char* name); extern bro_uint_t opt_internal_unsigned(const char* name); extern StringVal* opt_internal_string(const char* name); extern TableVal* opt_internal_table(const char* name); // nil if not defined + +[[deprecated("Remove in v4.1. Use lookup_ID(), zeek::lookup_val(), and/or TableVal::ToPureListVal().")]] extern ListVal* internal_list_val(const char* name); [[deprecated("Remove in v4.1. Use zeek::lookup_type().")]] diff --git a/src/analyzer/protocol/login/Login.cc b/src/analyzer/protocol/login/Login.cc index a2bff4e67d..4339c97fc4 100644 --- a/src/analyzer/protocol/login/Login.cc +++ b/src/analyzer/protocol/login/Login.cc @@ -11,6 +11,7 @@ #include "RE.h" #include "Reporter.h" #include "Event.h" +#include "Var.h" #include "events.bif.h" @@ -44,16 +45,24 @@ Login_Analyzer::Login_Analyzer(const char* name, Connection* conn) if ( ! re_skip_authentication ) { + IntrusivePtr skip_authentication = zeek::lookup_val("skip_authentication")->AsTableVal()->ToPureListVal(); + IntrusivePtr direct_login_prompts = zeek::lookup_val("direct_login_prompts")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_prompts = zeek::lookup_val("login_prompts")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_non_failure_msgs = zeek::lookup_val("login_non_failure_msgs")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_failure_msgs = zeek::lookup_val("login_failure_msgs")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_success_msgs = zeek::lookup_val("login_success_msgs")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_timeouts = zeek::lookup_val("login_timeouts")->AsTableVal()->ToPureListVal(); + #ifdef USE_PERFTOOLS_DEBUG HeapLeakChecker::Disabler disabler; #endif - re_skip_authentication = init_RE(skip_authentication); - re_direct_login_prompts = init_RE(direct_login_prompts); - re_login_prompts = init_RE(login_prompts); - re_login_non_failure_msgs = init_RE(login_non_failure_msgs); - re_login_failure_msgs = init_RE(login_failure_msgs); - re_login_success_msgs = init_RE(login_success_msgs); - re_login_timeouts = init_RE(login_timeouts); + re_skip_authentication = init_RE(skip_authentication.get()); + re_direct_login_prompts = init_RE(direct_login_prompts.get()); + re_login_prompts = init_RE(login_prompts.get()); + re_login_non_failure_msgs = init_RE(login_non_failure_msgs.get()); + re_login_failure_msgs = init_RE(login_failure_msgs.get()); + re_login_success_msgs = init_RE(login_success_msgs.get()); + re_login_timeouts = init_RE(login_timeouts.get()); } } From d4dba40727b5ee6ab67f91d947cc67e8f124fd67 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 9 May 2020 12:01:03 -0700 Subject: [PATCH 036/151] Deprecate VectorVal(VectorType*) ctora Adds a new one taking an IntrusivePtr. --- src/BroString.cc | 8 ++--- src/CompHash.cc | 2 +- src/EventHandler.cc | 2 +- src/Expr.cc | 24 +++++++------- src/IP.cc | 6 ++-- src/OpaqueVal.cc | 2 +- src/SmithWaterman.cc | 13 +++----- src/Stmt.cc | 4 +-- src/TunnelEncapsulation.h | 2 +- src/Type.h | 16 ++++++++++ src/Val.cc | 17 +++++----- src/Val.h | 4 ++- src/Var.cc | 2 +- src/analyzer/protocol/dhcp/dhcp-analyzer.pac | 2 +- src/analyzer/protocol/dhcp/dhcp-options.pac | 32 +++++++++---------- src/analyzer/protocol/dns/DNS.cc | 8 ++--- src/analyzer/protocol/icmp/ICMP.cc | 2 +- src/analyzer/protocol/imap/imap-analyzer.pac | 2 +- src/analyzer/protocol/krb/krb-padata.pac | 6 ++-- src/analyzer/protocol/krb/krb-types.pac | 10 +++--- .../protocol/modbus/modbus-analyzer.pac | 14 ++++---- .../protocol/mqtt/commands/subscribe.pac | 4 +-- .../protocol/mqtt/commands/unsubscribe.pac | 2 +- .../protocol/mysql/mysql-analyzer.pac | 4 +-- .../protocol/radius/radius-analyzer.pac | 4 +-- src/analyzer/protocol/rdp/rdp-analyzer.pac | 2 +- src/analyzer/protocol/rpc/MOUNT.cc | 9 +++--- src/analyzer/protocol/rpc/NFS.cc | 4 +-- .../protocol/smb/smb1-com-negotiate.pac | 2 +- .../protocol/smb/smb2-com-negotiate.pac | 4 +-- .../protocol/smb/smb2-com-set-info.pac | 2 +- src/analyzer/protocol/smb/smb2-protocol.pac | 6 ++-- src/analyzer/protocol/snmp/snmp-analyzer.pac | 4 +-- src/analyzer/protocol/ssh/ssh-analyzer.pac | 2 +- .../protocol/ssl/proc-client-hello.pac | 4 +-- .../protocol/ssl/tls-handshake-analyzer.pac | 26 +++++++-------- src/analyzer/protocol/tcp/TCP.cc | 6 ++-- src/broker/Data.cc | 2 +- src/broker/Manager.cc | 5 ++- src/broker/Manager.h | 3 +- src/broker/comm.bif | 2 +- src/file_analysis/Manager.cc | 2 +- src/file_analysis/analyzer/pe/pe-analyzer.pac | 5 +-- src/file_analysis/analyzer/x509/OCSP.cc | 2 +- src/file_analysis/analyzer/x509/X509.cc | 8 ++--- src/file_analysis/analyzer/x509/functions.bif | 2 +- src/input/Manager.cc | 6 ++-- src/probabilistic/Topk.cc | 7 ++-- src/strings.bif | 4 +-- src/supervisor/Supervisor.cc | 7 ++-- src/zeek.bif | 13 ++++---- 51 files changed, 171 insertions(+), 160 deletions(-) diff --git a/src/BroString.cc b/src/BroString.cc index 80ebe66270..b72ead7572 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -340,10 +340,8 @@ BroString::Vec* BroString::Split(const BroString::IdxVec& indices) const VectorVal* BroString:: VecToPolicy(Vec* vec) { - VectorVal* result = - new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); - if ( ! result ) - return nullptr; + auto result = + make_intrusive(zeek::lookup_type("string_vec")); for ( unsigned int i = 0; i < vec->size(); ++i ) { @@ -353,7 +351,7 @@ VectorVal* BroString:: VecToPolicy(Vec* vec) result->Assign(i+1, val); } - return result; + return result.release(); } BroString::Vec* BroString::VecFromPolicy(VectorVal* vec) diff --git a/src/CompHash.cc b/src/CompHash.cc index ea98690e69..238e8d1129 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -973,7 +973,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, n = *kp; kp1 = reinterpret_cast(kp+1); VectorType* vt = t->AsVectorType(); - auto vv = make_intrusive(vt); + auto vv = make_intrusive(IntrusivePtr{NewRef{}, vt}); for ( unsigned int i = 0; i < n; ++i ) { diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 4813e11f40..5c114d99ba 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -127,7 +127,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) return; RecordType* args = FType()->Args(); - auto vargs = make_intrusive(call_argument_vector); + auto vargs = make_intrusive(IntrusivePtr{NewRef{}, call_argument_vector}); for ( int i = 0; i < args->NumFields(); i++ ) { diff --git a/src/Expr.cc b/src/Expr.cc index 4848a6db73..5bda5ee9c1 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -361,7 +361,7 @@ IntrusivePtr UnaryExpr::Eval(Frame* f) const else out_t = Type()->AsVectorType(); - auto result = make_intrusive(out_t); + auto result = make_intrusive(IntrusivePtr{NewRef{}, out_t}); for ( unsigned int i = 0; i < v_op->Size(); ++i ) { @@ -454,7 +454,7 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const return nullptr; } - auto v_result = make_intrusive(Type()->AsVectorType()); + auto v_result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); for ( unsigned int i = 0; i < v_op1->Size(); ++i ) { @@ -471,7 +471,7 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const if ( IsVector(Type()->Tag()) && (is_vec1 || is_vec2) ) { // fold vector against scalar VectorVal* vv = (is_vec1 ? v1 : v2)->AsVectorVal(); - auto v_result = make_intrusive(Type()->AsVectorType()); + auto v_result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); for ( unsigned int i = 0; i < vv->Size(); ++i ) { @@ -1583,7 +1583,7 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const if ( scalar_v->IsZero() == is_and ) { - result = make_intrusive(Type()->AsVectorType()); + result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); result->Resize(vector_v->Size()); result->AssignRepeat(0, result->Size(), scalar_v.get()); } @@ -1608,7 +1608,7 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const return nullptr; } - auto result = make_intrusive(Type()->AsVectorType()); + auto result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); result->Resize(vec_v1->Size()); for ( unsigned int i = 0; i < vec_v1->Size(); ++i ) @@ -1940,7 +1940,7 @@ IntrusivePtr CondExpr::Eval(Frame* f) const return nullptr; } - auto result = make_intrusive(Type()->AsVectorType()); + auto result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); result->Resize(cond->Size()); for ( unsigned int i = 0; i < cond->Size(); ++i ) @@ -2592,7 +2592,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const { VectorVal* v_v1 = v1->AsVectorVal(); VectorVal* v_v2 = indv->AsVectorVal(); - auto v_result = make_intrusive(Type()->AsVectorType()); + auto v_result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); // Booleans select each element (or not). if ( IsBool(v_v2->Type()->Yield()->Tag()) ) @@ -2659,7 +2659,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const else { size_t len = vect->Size(); - auto result = make_intrusive(vect->Type()->AsVectorType()); + auto result = make_intrusive(IntrusivePtr{NewRef{}, vect->Type()->AsVectorType()}); bro_int_t first = get_slice_index(lv->Idx(0)->CoerceToInt(), len); bro_int_t last = get_slice_index(lv->Idx(1)->CoerceToInt(), len); @@ -3352,7 +3352,7 @@ IntrusivePtr VectorConstructorExpr::Eval(Frame* f) const if ( IsError() ) return nullptr; - auto vec = make_intrusive(Type()->AsVectorType()); + auto vec = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); const expr_list& exprs = op->AsListExpr()->Exprs(); loop_over_list(exprs, i) @@ -3377,7 +3377,7 @@ IntrusivePtr VectorConstructorExpr::InitVal(const BroType* t, IntrusivePtr< VectorType* vt = Type()->AsVectorType(); auto vec = aggr ? IntrusivePtr{AdoptRef{}, aggr.release()->AsVectorVal()} : - make_intrusive(vt); + make_intrusive(IntrusivePtr{NewRef{}, vt}); const expr_list& exprs = op->AsListExpr()->Exprs(); loop_over_list(exprs, i) @@ -3514,7 +3514,7 @@ IntrusivePtr ArithCoerceExpr::Fold(Val* v) const t = Type()->AsVectorType()->Yield()->InternalType(); VectorVal* vv = v->AsVectorVal(); - auto result = make_intrusive(Type()->AsVectorType()); + auto result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); for ( unsigned int i = 0; i < vv->Size(); ++i ) { @@ -3794,7 +3794,7 @@ IntrusivePtr VectorCoerceExpr::Fold(Val* v) const if ( vv->Size() > 0 ) RuntimeErrorWithCallStack("coercion of non-empty vector"); - return make_intrusive(Type()->Ref()->AsVectorType()); + return make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); } FlattenExpr::FlattenExpr(IntrusivePtr arg_op) diff --git a/src/IP.cc b/src/IP.cc index 32fc68ba85..fb98e32a76 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -46,7 +46,7 @@ static inline RecordType* hdrType(RecordType*& type, const char* name) static IntrusivePtr BuildOptionsVal(const u_char* data, int len) { - auto vv = make_intrusive(lookup_type("ip6_options")->AsVectorType()); + auto vv = make_intrusive(lookup_type("ip6_options")); while ( len > 0 ) { @@ -97,7 +97,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const rv->Assign(6, make_intrusive(IPAddr(ip6->ip6_dst))); if ( ! chain ) chain = make_intrusive( - lookup_type("ip6_ext_hdr_chain")->AsVectorType()); + lookup_type("ip6_ext_hdr_chain")); rv->Assign(7, std::move(chain)); } break; @@ -710,7 +710,7 @@ IntrusivePtr IPv6_Hdr_Chain::ToVal() const } auto rval = make_intrusive( - lookup_type("ip6_ext_hdr_chain")->AsVectorType()); + lookup_type("ip6_ext_hdr_chain")); for ( size_t i = 1; i < chain.size(); ++i ) { diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 2138c411b9..db58437a0a 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -981,7 +981,7 @@ ParaglobVal::ParaglobVal(std::unique_ptr p) IntrusivePtr ParaglobVal::Get(StringVal* &pattern) { - auto rval = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); + auto rval = make_intrusive(zeek::lookup_type("string_vec")); std::string string_pattern (reinterpret_cast(pattern->Bytes()), pattern->Len()); std::vector matches = this->internal_paraglob->get(string_pattern); diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index 17693e3f8e..9e679470b2 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -68,15 +68,10 @@ VectorVal* BroSubstring::VecToPolicy(Vec* vec) if ( ! sw_align_type ) return nullptr; - VectorType* sw_align_vec_type = - zeek::lookup_type("sw_align_vec")->AsVectorType(); - if ( ! sw_align_vec_type ) - return nullptr; + auto sw_align_vec_type = zeek::lookup_type("sw_align_vec"); - VectorVal* result = - new VectorVal(zeek::lookup_type("sw_substring_vec")->AsVectorType()); - if ( ! result ) - return nullptr; + auto result = + make_intrusive(zeek::lookup_type("sw_substring_vec")); if ( vec ) { @@ -106,7 +101,7 @@ VectorVal* BroSubstring::VecToPolicy(Vec* vec) } } - return result; + return result.release(); } BroSubstring::Vec* BroSubstring::VecFromPolicy(VectorVal* vec) diff --git a/src/Stmt.cc b/src/Stmt.cc index 2ce3760b94..7ae7b126f1 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -202,7 +202,7 @@ static void print_log(const std::vector>& vals) { auto plval = lookup_enum_val("Log", "PRINTLOG"); auto record = make_intrusive(zeek::lookup_type("Log::PrintLogInfo")->AsRecordType()); - auto vec = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); + auto vec = make_intrusive(zeek::lookup_type("string_vec")); for ( const auto& val : vals ) { @@ -1665,7 +1665,7 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const v = new RecordVal(t->AsRecordType()); break; case TYPE_VECTOR: - v = new VectorVal(t->AsVectorType()); + v = new VectorVal(cast_intrusive(t)); break; case TYPE_TABLE: v = new TableVal(cast_intrusive(t), {NewRef{}, aggr->Attrs()}); diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 67d66ced09..1dc01dfe6b 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -198,7 +198,7 @@ public: IntrusivePtr ToVal() const { auto vv = make_intrusive( - zeek::lookup_type("EncapsulatingConnVector")->AsVectorType()); + zeek::lookup_type("EncapsulatingConnVector")); if ( conns ) { diff --git a/src/Type.h b/src/Type.h index c215603c82..5787424c58 100644 --- a/src/Type.h +++ b/src/Type.h @@ -580,6 +580,14 @@ public: const IntrusivePtr& GetFieldType(const char* field_name) const { return GetFieldType(FieldOffset(field_name)); } + /** + * Looks up a field by name and returns its type as cast to @c T. + * No check for invalid field name is performed. + */ + template + IntrusivePtr GetFieldType(const char* field_name) const + { return cast_intrusive(GetFieldType(field_name)); } + /** * Looks up a field by its index and returns its type. No check for * invalid field offset is performed. @@ -587,6 +595,14 @@ public: const IntrusivePtr& GetFieldType(int field_index) const { return (*types)[field_index]->type; } + /** + * Looks up a field by its index and returns its type as cast to @c T. + * No check for invalid field offset is performed. + */ + template + IntrusivePtr GetFieldType(int field_index) const + { return cast_intrusive((*types)[field_index]->type); } + IntrusivePtr FieldDefault(int field) const; // A field's offset is its position in the type_decl_list, diff --git a/src/Val.cc b/src/Val.cc index 43d8c4825d..cda842b50a 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1933,7 +1933,7 @@ IntrusivePtr TableVal::LookupSubnets(const SubNetVal* search) if ( ! subnets ) reporter->InternalError("LookupSubnets called on wrong table type"); - auto result = make_intrusive(zeek::lookup_type("subnet_vec")->AsVectorType()); + auto result = make_intrusive(zeek::lookup_type("subnet_vec")); auto matches = subnets->FindAll(search); for ( auto element : matches ) @@ -2671,11 +2671,11 @@ RecordVal::RecordVal(RecordType* t, bool init_fields) : Val(t) Attributes* a = t->FieldDecl(i)->attrs.get(); Attr* def_attr = a ? a->FindAttr(ATTR_DEFAULT) : nullptr; auto def = def_attr ? def_attr->AttrExpr()->Eval(nullptr) : nullptr; - BroType* type = t->FieldDecl(i)->type.get(); + const auto& type = t->FieldDecl(i)->type; if ( def && type->Tag() == TYPE_RECORD && def->Type()->Tag() == TYPE_RECORD && - ! same_type(def->Type(), type) ) + ! same_type(def->Type(), type.get()) ) { auto tmp = def->AsRecordVal()->CoerceTo(type->AsRecordType()); @@ -2695,7 +2695,7 @@ RecordVal::RecordVal(RecordType* t, bool init_fields) : Val(t) IntrusivePtr{NewRef{}, a}); else if ( tag == TYPE_VECTOR ) - def = make_intrusive(type->AsVectorType()); + def = make_intrusive(cast_intrusive(type)); } vl->push_back(def.release()); @@ -2977,9 +2977,12 @@ IntrusivePtr EnumVal::DoClone(CloneState* state) return {NewRef{}, this}; } -VectorVal::VectorVal(VectorType* t) : Val(t) +VectorVal::VectorVal(VectorType* t) : VectorVal({NewRef{}, t}) + { } + +VectorVal::VectorVal(IntrusivePtr t) : Val(t.get()) { - vector_type = t->Ref()->AsVectorType(); + vector_type = std::move(t); val.vector_val = new vector(); } @@ -2988,8 +2991,6 @@ VectorVal::~VectorVal() for ( unsigned int i = 0; i < val.vector_val->size(); ++i ) Unref((*val.vector_val)[i]); - Unref(vector_type); - delete val.vector_val; } diff --git a/src/Val.h b/src/Val.h index eb81241c3a..54275a95ad 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1016,7 +1016,9 @@ protected: class VectorVal final : public Val, public notifier::Modifiable { public: + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit VectorVal(VectorType* t); + explicit VectorVal(IntrusivePtr t); ~VectorVal() override; IntrusivePtr SizeVal() const override; @@ -1076,7 +1078,7 @@ protected: void ValDescribe(ODesc* d) const override; IntrusivePtr DoClone(CloneState* state) override; - VectorType* vector_type; + IntrusivePtr vector_type; }; // Checks the given value for consistency with the given type. If an diff --git a/src/Var.cc b/src/Var.cc index 4f7d677eac..afc4fcd0c1 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -253,7 +253,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, IntrusivePtr{NewRef{}, id->Attrs()}); else if ( t->Tag() == TYPE_VECTOR ) - aggr = make_intrusive(t->AsVectorType()); + aggr = make_intrusive(cast_intrusive(t)); IntrusivePtr v; diff --git a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac index 887069dc4e..1164cd4677 100644 --- a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac +++ b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac @@ -20,7 +20,7 @@ refine flow DHCP_Flow += { if ( ! options ) { options = make_intrusive(BifType::Record::DHCP::Options); - all_options = make_intrusive(index_vec); + all_options = make_intrusive(IntrusivePtr{NewRef{}, index_vec}); options->Assign(0, all_options); } diff --git a/src/analyzer/protocol/dhcp/dhcp-options.pac b/src/analyzer/protocol/dhcp/dhcp-options.pac index 848aa05868..d6f917cf7f 100644 --- a/src/analyzer/protocol/dhcp/dhcp-options.pac +++ b/src/analyzer/protocol/dhcp/dhcp-options.pac @@ -57,7 +57,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_router_option(v: OptionValue): bool %{ - VectorVal* router_list = new VectorVal(BifType::Vector::DHCP::Addrs); + auto router_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); int num_routers = ${v.router_list}->size(); vector* rlist = ${v.router_list}; @@ -67,7 +67,7 @@ refine flow DHCP_Flow += { router_list->Assign(i, make_intrusive(htonl(raddr))); } - ${context.flow}->options->Assign(2, router_list); + ${context.flow}->options->Assign(2, std::move(router_list)); return true; %} @@ -91,7 +91,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_timeserver_option(v: OptionValue): bool %{ - VectorVal* timeserver_list = new VectorVal(BifType::Vector::DHCP::Addrs); + auto timeserver_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); int num_servers = ${v.timeserver_list}->size(); vector* rlist = ${v.timeserver_list}; @@ -101,7 +101,7 @@ refine flow DHCP_Flow += { timeserver_list->Assign(i, make_intrusive(htonl(raddr))); } - ${context.flow}->options->Assign(26, timeserver_list); + ${context.flow}->options->Assign(26, std::move(timeserver_list)); return true; %} @@ -125,7 +125,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_nameserver_option(v: OptionValue): bool %{ - VectorVal* nameserver_list = new VectorVal(BifType::Vector::DHCP::Addrs); + auto nameserver_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); int num_servers = ${v.nameserver_list}->size(); vector* rlist = ${v.nameserver_list}; @@ -135,7 +135,7 @@ refine flow DHCP_Flow += { nameserver_list->Assign(i, make_intrusive(htonl(raddr))); } - ${context.flow}->options->Assign(27, nameserver_list); + ${context.flow}->options->Assign(27, std::move(nameserver_list)); return true; %} @@ -159,7 +159,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_dns_server_option(v: OptionValue): bool %{ - VectorVal* server_list = new VectorVal(BifType::Vector::DHCP::Addrs); + auto server_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); int num_servers = ${v.dns_server_list}->size(); vector* rlist = ${v.dns_server_list}; @@ -169,7 +169,7 @@ refine flow DHCP_Flow += { server_list->Assign(i, make_intrusive(htonl(raddr))); } - ${context.flow}->options->Assign(3, server_list); + ${context.flow}->options->Assign(3, std::move(server_list)); return true; %} }; @@ -298,7 +298,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_ntpserver_option(v: OptionValue): bool %{ - VectorVal* ntpserver_list = new VectorVal(BifType::Vector::DHCP::Addrs); + auto ntpserver_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); int num_servers = ${v.ntpserver_list}->size(); vector* rlist = ${v.ntpserver_list}; @@ -308,7 +308,7 @@ refine flow DHCP_Flow += { ntpserver_list->Assign(i, make_intrusive(htonl(raddr))); } - ${context.flow}->options->Assign(28, ntpserver_list); + ${context.flow}->options->Assign(28, std::move(ntpserver_list)); return true; %} @@ -356,7 +356,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_nbns_option(v: OptionValue): bool %{ - VectorVal* server_list = new VectorVal(BifType::Vector::DHCP::Addrs); + auto server_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); int num_servers = ${v.nbns}->size(); vector* rlist = ${v.nbns}; @@ -366,7 +366,7 @@ refine flow DHCP_Flow += { server_list->Assign(i, make_intrusive(htonl(raddr))); } - ${context.flow}->options->Assign(9, server_list); + ${context.flow}->options->Assign(9, std::move(server_list)); return true; %} }; @@ -462,7 +462,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_par_req_list_option(v: OptionValue): bool %{ - VectorVal* params = new VectorVal(index_vec); + auto params = make_intrusive(IntrusivePtr{NewRef{}, index_vec}); int num_parms = ${v.par_req_list}->size(); vector* plist = ${v.par_req_list}; @@ -472,7 +472,7 @@ refine flow DHCP_Flow += { params->Assign(i, val_mgr->Count(param)); } - ${context.flow}->options->Assign(13, params); + ${context.flow}->options->Assign(13, std::move(params)); return true; %} @@ -743,7 +743,7 @@ refine flow DHCP_Flow += { function process_relay_agent_inf_option(v: OptionValue): bool %{ - VectorVal* relay_agent_sub_opt = new VectorVal(BifType::Vector::DHCP::SubOpts); + auto relay_agent_sub_opt = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::SubOpts}); uint16 i = 0; @@ -758,7 +758,7 @@ refine flow DHCP_Flow += { ++i; } - ${context.flow}->options->Assign(22, relay_agent_sub_opt); + ${context.flow}->options->Assign(22, std::move(relay_agent_sub_opt)); return true; %} }; diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 849b611525..6db7fa1183 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -998,7 +998,7 @@ bool DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, int typebitmaps_len = rdlength - (data - data_start); - auto char_strings = make_intrusive(string_vec); + auto char_strings = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); while ( typebitmaps_len > 0 && len > 0 ) { @@ -1073,7 +1073,7 @@ bool DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, int typebitmaps_len = rdlength - (data - data_start); - auto char_strings = make_intrusive(string_vec); + auto char_strings = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); while ( typebitmaps_len > 0 && len > 0 ) { @@ -1288,7 +1288,7 @@ bool DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, return true; } - auto char_strings = make_intrusive(string_vec); + auto char_strings = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); IntrusivePtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) @@ -1316,7 +1316,7 @@ bool DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, return true; } - auto char_strings = make_intrusive(string_vec); + auto char_strings = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); IntrusivePtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 1071d0ea0e..84a2fc2351 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -732,7 +732,7 @@ IntrusivePtr ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha } auto vv = make_intrusive( - zeek::lookup_type("icmp6_nd_options")->AsVectorType()); + zeek::lookup_type("icmp6_nd_options")); while ( caplen > 0 ) { diff --git a/src/analyzer/protocol/imap/imap-analyzer.pac b/src/analyzer/protocol/imap/imap-analyzer.pac index 7e45bda7a0..5b587f77c0 100644 --- a/src/analyzer/protocol/imap/imap-analyzer.pac +++ b/src/analyzer/protocol/imap/imap-analyzer.pac @@ -59,7 +59,7 @@ refine connection IMAP_Conn += { if ( ! imap_capabilities ) return true; - auto capv = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); + auto capv = make_intrusive(zeek::lookup_type("string_vec")); for ( unsigned int i = 0; i< capabilities->size(); i++ ) { diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index a73c1cb5d4..f61a12c4bc 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -13,10 +13,10 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a %code{ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) { - VectorVal* vv = new VectorVal(zeek::lookup_type("KRB::Type_Value_Vector")->AsVectorType()); + auto vv = make_intrusive(zeek::lookup_type("KRB::Type_Value_Vector")); if ( ! data->data()->has_padata() ) - return vv; + return vv.release(); for ( uint i = 0; i < data->data()->padata_elems()->size(); ++i) { @@ -119,7 +119,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a } } } - return vv; + return vv.release(); } %} diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index dcb320efbe..cbe588b38e 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -27,22 +27,22 @@ IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pname) VectorVal* proc_cipher_list(const Array* list) { - VectorVal* ciphers = new VectorVal(zeek::lookup_type("index_vec")->AsVectorType()); + auto ciphers = make_intrusive(zeek::lookup_type("index_vec")); for ( uint i = 0; i < list->data()->size(); ++i ) ciphers->Assign(ciphers->Size(), asn1_integer_to_val((*list->data())[i], TYPE_COUNT)); - return ciphers; + return ciphers.release(); } VectorVal* proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) { - VectorVal* addrs = new VectorVal(zeek::lookup_type("KRB::Host_Address_Vector")->AsVectorType()); + auto addrs = make_intrusive(zeek::lookup_type("KRB::Host_Address_Vector")); for ( uint i = 0; i < list->addresses()->size(); ++i ) { addrs->Assign(addrs->Size(), proc_host_address(a, (*list->addresses())[i])); } - return addrs; + return addrs.release(); } RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) @@ -94,7 +94,7 @@ RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list) { - auto tickets = make_intrusive(zeek::lookup_type("KRB::Ticket_Vector")->AsVectorType()); + auto tickets = make_intrusive(zeek::lookup_type("KRB::Ticket_Vector")); for ( uint i = 0; i < list->tickets()->size(); ++i ) { diff --git a/src/analyzer/protocol/modbus/modbus-analyzer.pac b/src/analyzer/protocol/modbus/modbus-analyzer.pac index c4668a775c..ac0c027d8f 100644 --- a/src/analyzer/protocol/modbus/modbus-analyzer.pac +++ b/src/analyzer/protocol/modbus/modbus-analyzer.pac @@ -16,7 +16,7 @@ %code{ IntrusivePtr bytestring_to_coils(const bytestring& coils, uint quantity) { - auto modbus_coils = make_intrusive(BifType::Vector::ModbusCoils); + auto modbus_coils = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusCoils}); for ( uint i = 0; i < quantity; i++ ) { @@ -40,7 +40,7 @@ IntrusivePtr create_vector_of_count() { auto vt = make_intrusive(base_type(TYPE_COUNT)); - auto vv = make_intrusive(vt.get()); + auto vv = make_intrusive(std::move(vt)); return vv; } @@ -209,7 +209,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_read_holding_registers_response ) { - auto t = make_intrusive(BifType::Vector::ModbusRegisters); + auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); for ( unsigned int i=0; i < ${message.registers}->size(); ++i ) { @@ -253,7 +253,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_read_input_registers_response ) { - auto t = make_intrusive(BifType::Vector::ModbusRegisters); + auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); for ( unsigned int i=0; i < (${message.registers})->size(); ++i ) { @@ -397,7 +397,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_write_multiple_registers_request ) { - auto t = make_intrusive(BifType::Vector::ModbusRegisters); + auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); for ( unsigned int i = 0; i < (${message.registers}->size()); ++i ) { @@ -582,7 +582,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_read_write_multiple_registers_request ) { - auto t = make_intrusive(BifType::Vector::ModbusRegisters); + auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); for ( unsigned int i = 0; i < ${message.write_register_values}->size(); ++i ) { @@ -614,7 +614,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_read_write_multiple_registers_response ) { - auto t = make_intrusive(BifType::Vector::ModbusRegisters); + auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); for ( unsigned int i = 0; i < ${message.registers}->size(); ++i ) { diff --git a/src/analyzer/protocol/mqtt/commands/subscribe.pac b/src/analyzer/protocol/mqtt/commands/subscribe.pac index 2ee0d1592b..496f9953df 100644 --- a/src/analyzer/protocol/mqtt/commands/subscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/subscribe.pac @@ -19,8 +19,8 @@ refine flow MQTT_Flow += { %{ if ( mqtt_subscribe ) { - auto topics = make_intrusive(string_vec); - auto qos_levels = make_intrusive(index_vec); + auto topics = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); + auto qos_levels = make_intrusive(IntrusivePtr{NewRef{}, index_vec}); for ( auto topic: *${msg.topics} ) { diff --git a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac index 670b312d5b..f7abcf68ae 100644 --- a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac @@ -14,7 +14,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_unsubscribe ) { - auto topics = make_intrusive(string_vec); + auto topics = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); for ( auto topic: *${msg.topics} ) { diff --git a/src/analyzer/protocol/mysql/mysql-analyzer.pac b/src/analyzer/protocol/mysql/mysql-analyzer.pac index 1f49688f5e..b9ea38e3bf 100644 --- a/src/analyzer/protocol/mysql/mysql-analyzer.pac +++ b/src/analyzer/protocol/mysql/mysql-analyzer.pac @@ -82,8 +82,8 @@ refine flow MySQL_Flow += { if ( ! mysql_result_row ) return true; - auto vt = zeek::lookup_type("string_vec")->AsVectorType(); - auto vv = make_intrusive(vt); + auto vt = zeek::lookup_type("string_vec"); + auto vv = make_intrusive(std::move(vt)); auto& bstring = ${msg.row.first_field.val}; auto ptr = reinterpret_cast(bstring.data()); diff --git a/src/analyzer/protocol/radius/radius-analyzer.pac b/src/analyzer/protocol/radius/radius-analyzer.pac index 713e249e4e..059a61f58a 100644 --- a/src/analyzer/protocol/radius/radius-analyzer.pac +++ b/src/analyzer/protocol/radius/radius-analyzer.pac @@ -32,9 +32,9 @@ refine flow RADIUS_Flow += { else { - VectorVal* attribute_list = new VectorVal(BifType::Vector::RADIUS::AttributeList); + auto attribute_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::RADIUS::AttributeList}); attribute_list->Assign((unsigned int)0, std::move(val)); - attributes->Assign(index.get(), attribute_list); + attributes->Assign(index.get(), std::move(attribute_list)); } } diff --git a/src/analyzer/protocol/rdp/rdp-analyzer.pac b/src/analyzer/protocol/rdp/rdp-analyzer.pac index b80129bfc2..4caa48393e 100644 --- a/src/analyzer/protocol/rdp/rdp-analyzer.pac +++ b/src/analyzer/protocol/rdp/rdp-analyzer.pac @@ -124,7 +124,7 @@ refine flow RDP_Flow += { if ( ${cnetwork.channel_def_array}->size() ) { - auto channels = make_intrusive(BifType::Vector::RDP::ClientChannelList); + auto channels = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::RDP::ClientChannelList}); for ( uint i = 0; i < ${cnetwork.channel_def_array}->size(); ++i ) { diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index 5a0bfcd8ba..1569279e7d 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -192,7 +192,7 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto auxgids = make_intrusive(zeek::lookup_type("index_vec")); for (size_t i = 0; i < c->AuxGIDs().size(); ++i) { @@ -272,9 +272,8 @@ RecordVal* MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n, auth_flavors_count = max_auth_flavors; } - VectorType* enum_vector = new VectorType(base_type(TYPE_ENUM)); - VectorVal* auth_flavors = new VectorVal(enum_vector); - Unref(enum_vector); + auto enum_vector = make_intrusive(base_type(TYPE_ENUM)); + auto auth_flavors = make_intrusive(std::move(enum_vector)); for ( auto i = 0u; i < auth_flavors_count; ++i ) auth_flavors->Assign(auth_flavors->Size(), @@ -284,7 +283,7 @@ RecordVal* MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n, // Prevent further "excess RPC" weirds n = 0; - rep->Assign(1, auth_flavors); + rep->Assign(1, std::move(auth_flavors)); } else { diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index 82d3e519a3..0ecce74ff1 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -328,7 +328,7 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_ zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto auxgids = make_intrusive(zeek::lookup_type("index_vec")); for ( size_t i = 0; i < c->AuxGIDs().size(); ++i ) auxgids->Assign(i, val_mgr->Count(c->AuxGIDs()[i])); @@ -769,7 +769,7 @@ RecordVal* NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char*& buf, if ( status == BifEnum::NFS3::NFS3ERR_OK ) { unsigned pos; - VectorVal *entries = new VectorVal(BifType::Vector::NFS3::direntry_vec_t); + auto entries = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::NFS3::direntry_vec_t}); rep->Assign(1, nfs3_post_op_attr(buf,n)); // dir_attr rep->Assign(2, ExtractUint64(buf,n)); // cookieverf diff --git a/src/analyzer/protocol/smb/smb1-com-negotiate.pac b/src/analyzer/protocol/smb/smb1-com-negotiate.pac index 73ee56693f..f225cf9df5 100644 --- a/src/analyzer/protocol/smb/smb1-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb1-com-negotiate.pac @@ -15,7 +15,7 @@ refine connection SMB_Conn += { %{ if ( smb1_negotiate_request ) { - auto dialects = make_intrusive(string_vec); + auto dialects = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); for ( unsigned int i = 0; i < ${val.dialects}->size(); ++i ) { diff --git a/src/analyzer/protocol/smb/smb2-com-negotiate.pac b/src/analyzer/protocol/smb/smb2-com-negotiate.pac index 0ebeda9012..c40591b580 100644 --- a/src/analyzer/protocol/smb/smb2-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb2-com-negotiate.pac @@ -22,7 +22,7 @@ refine connection SMB_Conn += { %{ if ( smb2_negotiate_request ) { - auto dialects = make_intrusive(index_vec); + auto dialects = make_intrusive(IntrusivePtr{NewRef{}, index_vec}); for ( unsigned int i = 0; i < ${val.dialects}->size(); ++i ) dialects->Assign(i, val_mgr->Count((*${val.dialects})[i])); @@ -48,7 +48,7 @@ refine connection SMB_Conn += { nr->Assign(4, filetime2brotime(${val.server_start_time})); nr->Assign(5, val_mgr->Count(${val.negotiate_context_count})); - auto cv = make_intrusive(BifType::Vector::SMB2::NegotiateContextValues); + auto cv = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::SMB2::NegotiateContextValues}); if ( ${val.dialect_revision} == 0x0311 && ${val.negotiate_context_count} > 0 ) { diff --git a/src/analyzer/protocol/smb/smb2-com-set-info.pac b/src/analyzer/protocol/smb/smb2-com-set-info.pac index ce6b089986..9f13d9b91a 100644 --- a/src/analyzer/protocol/smb/smb2-com-set-info.pac +++ b/src/analyzer/protocol/smb/smb2-com-set-info.pac @@ -93,7 +93,7 @@ refine connection SMB_Conn += { %{ if ( smb2_file_fullea ) { - auto eas = make_intrusive(BifType::Vector::SMB2::FileEAs); + auto eas = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::SMB2::FileEAs}); for ( auto i = 0u; i < ${val.ea_vector}->size(); ++i ) { diff --git a/src/analyzer/protocol/smb/smb2-protocol.pac b/src/analyzer/protocol/smb/smb2-protocol.pac index 861d35f22c..2da119cdf3 100644 --- a/src/analyzer/protocol/smb/smb2-protocol.pac +++ b/src/analyzer/protocol/smb/smb2-protocol.pac @@ -68,7 +68,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) rpreauth->Assign(0, val_mgr->Count(${ncv.preauth_integrity_capabilities.hash_alg_count})); rpreauth->Assign(1, val_mgr->Count(${ncv.preauth_integrity_capabilities.salt_length})); - auto ha = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto ha = make_intrusive(zeek::lookup_type("index_vec")); for ( int i = 0; i < ${ncv.preauth_integrity_capabilities.hash_alg_count}; ++i ) { @@ -87,7 +87,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rencr = make_intrusive(BifType::Record::SMB2::EncryptionCapabilities); rencr->Assign(0, val_mgr->Count(${ncv.encryption_capabilities.cipher_count})); - auto c = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto c = make_intrusive(zeek::lookup_type("index_vec")); for ( int i = 0; i < ${ncv.encryption_capabilities.cipher_count}; ++i ) { @@ -105,7 +105,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rcomp = make_intrusive(BifType::Record::SMB2::CompressionCapabilities); rcomp->Assign(0, val_mgr->Count(${ncv.compression_capabilities.alg_count})); - auto c = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto c = make_intrusive(zeek::lookup_type("index_vec")); for ( int i = 0; i < ${ncv.compression_capabilities.alg_count}; ++i ) { diff --git a/src/analyzer/protocol/snmp/snmp-analyzer.pac b/src/analyzer/protocol/snmp/snmp-analyzer.pac index 17296e11f8..0fa56d3c2f 100644 --- a/src/analyzer/protocol/snmp/snmp-analyzer.pac +++ b/src/analyzer/protocol/snmp/snmp-analyzer.pac @@ -155,7 +155,7 @@ RecordVal* build_hdrV3(const Header* header) VectorVal* build_bindings(const VarBindList* vbl) { - VectorVal* vv = new VectorVal(BifType::Vector::SNMP::Bindings); + auto vv = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::SNMP::Bindings}); for ( size_t i = 0; i < vbl->bindings()->size(); ++i ) { @@ -166,7 +166,7 @@ VectorVal* build_bindings(const VarBindList* vbl) vv->Assign(i, binding); } - return vv; + return vv.release(); } IntrusivePtr build_pdu(const CommonPDU* pdu) diff --git a/src/analyzer/protocol/ssh/ssh-analyzer.pac b/src/analyzer/protocol/ssh/ssh-analyzer.pac index 3f4c6e9c69..8a6f0adc13 100644 --- a/src/analyzer/protocol/ssh/ssh-analyzer.pac +++ b/src/analyzer/protocol/ssh/ssh-analyzer.pac @@ -12,7 +12,7 @@ VectorVal* name_list_to_vector(const bytestring& nl); // Copied from IRC_Analyzer::SplitWords VectorVal* name_list_to_vector(const bytestring& nl) { - VectorVal* vv = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); + VectorVal* vv = new VectorVal(zeek::lookup_type("string_vec")); string name_list = std_str(nl); if ( name_list.size() < 1 ) diff --git a/src/analyzer/protocol/ssl/proc-client-hello.pac b/src/analyzer/protocol/ssl/proc-client-hello.pac index 13accc5318..80afbb56f9 100644 --- a/src/analyzer/protocol/ssl/proc-client-hello.pac +++ b/src/analyzer/protocol/ssl/proc-client-hello.pac @@ -23,7 +23,7 @@ else std::transform(cipher_suites24->begin(), cipher_suites24->end(), std::back_inserter(cipher_suites), to_int()); - auto cipher_vec = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto cipher_vec = make_intrusive(zeek::lookup_type("index_vec")); for ( unsigned int i = 0; i < cipher_suites.size(); ++i ) { @@ -31,7 +31,7 @@ cipher_vec->Assign(i, ciph); } - auto comp_vec = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto comp_vec = make_intrusive(zeek::lookup_type("index_vec")); if ( compression_methods ) { diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index 5db9e711a2..4f499039f5 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -75,7 +75,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_ec_point_formats ) return true; - auto points = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto points = make_intrusive(zeek::lookup_type("index_vec")); if ( point_format_list ) { @@ -94,7 +94,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_elliptic_curves ) return true; - auto curves = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto curves = make_intrusive(zeek::lookup_type("index_vec")); if ( list ) { @@ -113,7 +113,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto nglist = make_intrusive(zeek::lookup_type("index_vec")); if ( keyshare ) { @@ -131,7 +131,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto nglist = make_intrusive(zeek::lookup_type("index_vec")); nglist->Assign(0u, val_mgr->Count(keyshare->namedgroup())); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -143,7 +143,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto nglist = make_intrusive(zeek::lookup_type("index_vec")); nglist->Assign(0u, val_mgr->Count(namedgroup)); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -155,7 +155,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_signature_algorithm ) return true; - auto slist = make_intrusive(zeek::lookup_type("signature_and_hashalgorithm_vec")->AsVectorType()); + auto slist = make_intrusive(zeek::lookup_type("signature_and_hashalgorithm_vec")); if ( supported_signature_algorithms ) { @@ -178,7 +178,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_application_layer_protocol_negotiation ) return true; - auto plist = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); + auto plist = make_intrusive(zeek::lookup_type("string_vec")); if ( protocols ) { @@ -194,7 +194,7 @@ refine connection Handshake_Conn += { function proc_server_name(rec: HandshakeRecord, list: ServerName[]) : bool %{ - auto servers = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); + auto servers = make_intrusive(zeek::lookup_type("string_vec")); if ( list ) { @@ -226,7 +226,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto versions = make_intrusive(zeek::lookup_type("index_vec")); if ( versions_list ) { @@ -245,7 +245,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto versions = make_intrusive(zeek::lookup_type("index_vec")); versions->Assign(0u, val_mgr->Count(version)); BifEvent::enqueue_ssl_extension_supported_versions(bro_analyzer(), bro_analyzer()->Conn(), @@ -259,7 +259,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_psk_key_exchange_modes ) return true; - auto modes = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); + auto modes = make_intrusive(zeek::lookup_type("index_vec")); if ( mode_list ) { @@ -492,7 +492,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_pre_shared_key_server_hello ) return true; - auto slist = make_intrusive(zeek::lookup_type("psk_identity_vec")->AsVectorType()); + auto slist = make_intrusive(zeek::lookup_type("psk_identity_vec")); if ( identities && identities->identities() ) { @@ -505,7 +505,7 @@ refine connection Handshake_Conn += { } } - auto blist = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); + auto blist = make_intrusive(zeek::lookup_type("string_vec")); if ( binders && binders->binders() ) { diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index e9acdc65b5..81b6f20f7e 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -1355,7 +1355,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) if ( tcp_options ) { - auto option_list = make_intrusive(BifType::Vector::TCP::OptionList); + auto option_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::TCP::OptionList}); auto add_option_data = [](RecordVal* rv, const u_char* odata, int olen) { @@ -1421,8 +1421,8 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) { auto p = reinterpret_cast(o + 2); auto num_pointers = (length - 2) / 4; - auto vt = zeek::lookup_type("index_vec")->AsVectorType(); - auto sack = new VectorVal(vt); + auto vt = zeek::lookup_type("index_vec"); + auto sack = make_intrusive(std::move(vt)); for ( auto i = 0; i < num_pointers; ++i ) sack->Assign(sack->Size(), val_mgr->Count(ntohl(p[i]))); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index bc7b1da326..77adc010fc 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -330,7 +330,7 @@ struct val_converter { if ( type->Tag() == TYPE_VECTOR ) { auto vt = type->AsVectorType(); - auto rval = make_intrusive(vt); + auto rval = make_intrusive(IntrusivePtr{NewRef{}, vt}); for ( auto& item : a ) { diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index ee93f3b4e7..8e1e5f5416 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -132,7 +132,6 @@ Manager::Manager(bool arg_use_real_time) peer_count = 0; log_batch_size = 0; log_topic_func = nullptr; - vector_of_data_type = nullptr; log_id_type = nullptr; writer_id_type = nullptr; } @@ -158,7 +157,7 @@ void Manager::InitPostScript() opaque_of_vector_iterator = new OpaqueType("Broker::VectorIterator"); opaque_of_record_iterator = new OpaqueType("Broker::RecordIterator"); opaque_of_store_handle = new OpaqueType("Broker::Store"); - vector_of_data_type = new VectorType(zeek::lookup_type("Broker::Data")); + vector_of_data_type = make_intrusive(zeek::lookup_type("Broker::Data")); // Register as a "dont-count" source first, we may change that later. iosource_mgr->Register(this, true); @@ -701,7 +700,7 @@ bool Manager::AutoUnpublishEvent(const string& topic, Val* event) RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) { auto rval = new RecordVal(BifType::Record::Broker::Event); - auto arg_vec = new VectorVal(vector_of_data_type); + auto arg_vec = make_intrusive(vector_of_data_type); rval->Assign(1, arg_vec); Func* func = nullptr; scoped_reporter_location srl{frame}; diff --git a/src/broker/Manager.h b/src/broker/Manager.h index bbd38f88be..a57b86057c 100644 --- a/src/broker/Manager.h +++ b/src/broker/Manager.h @@ -17,6 +17,7 @@ #include #include +#include "IntrusivePtr.h" #include "iosource/IOSource.h" #include "logging/WriterBackend.h" @@ -394,7 +395,7 @@ private: size_t log_batch_size; Func* log_topic_func; - VectorType* vector_of_data_type; + IntrusivePtr vector_of_data_type; EnumType* log_id_type; EnumType* writer_id_type; diff --git a/src/broker/comm.bif b/src/broker/comm.bif index aa19638dcc..8b6789464f 100644 --- a/src/broker/comm.bif +++ b/src/broker/comm.bif @@ -94,7 +94,7 @@ function Broker::__unpeer%(a: string, p: port%): bool function Broker::__peers%(%): PeerInfos %{ bro_broker::Manager::ScriptScopeGuard ssg; - auto rval = make_intrusive(zeek::lookup_type("Broker::PeerInfos")->AsVectorType()); + auto rval = make_intrusive(zeek::lookup_type("Broker::PeerInfos")); auto i = 0; for ( auto& p : broker_mgr->Peers() ) diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index a566219b5c..bc18568444 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -499,7 +499,7 @@ string Manager::DetectMIME(const u_char* data, uint64_t len) const IntrusivePtr file_analysis::GenMIMEMatchesVal(const RuleMatcher::MIME_Matches& m) { - auto rval = make_intrusive(mime_matches); + auto rval = make_intrusive(IntrusivePtr{NewRef{}, mime_matches}); for ( RuleMatcher::MIME_Matches::const_iterator it = m.begin(); it != m.end(); ++it ) diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index 3549ec5267..95dfa436a9 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -11,11 +11,12 @@ VectorVal* process_rvas(const RVAS* rvas); %code{ VectorVal* process_rvas(const RVAS* rva_table) { - VectorVal* rvas = new VectorVal(zeek::lookup_type("index_vec")->AsVectorType()); + auto rvas = make_intrusive(zeek::lookup_type("index_vec")); + for ( uint16 i=0; i < rva_table->rvas()->size(); ++i ) rvas->Assign(i, val_mgr->Count((*rva_table->rvas())[i]->size())); - return rvas; + return rvas.release(); } %} diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index 7355058eb8..f8996a94ea 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -634,7 +634,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp) //ocsp_resp_record->Assign(7, make_intrusive(len, buf)); //BIO_reset(bio); - certs_vector = new VectorVal(zeek::lookup_type("x509_opaque_vector")->AsVectorType()); + certs_vector = new VectorVal(zeek::lookup_type("x509_opaque_vector")); vl.emplace_back(AdoptRef{}, certs_vector); #if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER) diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index b3fffdce23..8c98ed179b 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -367,21 +367,21 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) { case GEN_DNS: if ( names == nullptr ) - names = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); + names = new VectorVal(zeek::lookup_type("string_vec")); names->Assign(names->Size(), bs); break; case GEN_URI: if ( uris == nullptr ) - uris = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); + uris = new VectorVal(zeek::lookup_type("string_vec")); uris->Assign(uris->Size(), bs); break; case GEN_EMAIL: if ( emails == nullptr ) - emails = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); + emails = new VectorVal(zeek::lookup_type("string_vec")); emails->Assign(emails->Size(), bs); break; @@ -391,7 +391,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) else if ( gen->type == GEN_IPADD ) { if ( ips == nullptr ) - ips = new VectorVal(zeek::lookup_type("addr_vec")->AsVectorType()); + ips = new VectorVal(zeek::lookup_type("addr_vec")); uint32_t* addr = (uint32_t*) gen->d.ip->data; diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index 5eba5a776d..622b08958f 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -556,7 +556,7 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str } int num_certs = sk_X509_num(chain); - chainVector = new VectorVal(zeek::lookup_type("x509_opaque_vector")->AsVectorType()); + chainVector = new VectorVal(zeek::lookup_type("x509_opaque_vector")); for ( int i = 0; i < num_certs; i++ ) { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index d59c428033..0bbb083a9f 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -2356,7 +2356,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ // all entries have to have the same type... const auto& type = request_type->AsVectorType()->Yield(); auto vt = make_intrusive(type); - auto v = make_intrusive(vt.get()); + auto v = make_intrusive(std::move(vt)); for ( int j = 0; j < val->val.vector_val.size; j++ ) v->Assign(j, ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error)); @@ -2548,12 +2548,12 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co } auto vt = make_intrusive(std::move(type)); - VectorVal* v = new VectorVal(vt.get()); + auto v = make_intrusive(std::move(vt)); for ( int j = 0; j < val->val.vector_val.size; j++ ) v->Assign(j, ValueToVal(i, val->val.vector_val.vals[j], have_error)); - return v; + return v.release(); } case TYPE_ENUM: { diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index fff53cbc1b..6c79e9ff6a 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -201,8 +201,8 @@ VectorVal* TopkVal::GetTopK(int k) const // returns vector auto vector_index = make_intrusive(IntrusivePtr{NewRef{}, type}); vector_index->Append({NewRef{}, type}); - VectorType* v = new VectorType(std::move(vector_index)); - VectorVal* t = new VectorVal(v); + auto v = make_intrusive(std::move(vector_index)); + auto t = make_intrusive(std::move(v)); // this does no estimation if the results is correct! // in any case - just to make this future-proof (and I am lazy) - this can return more than k. @@ -228,8 +228,7 @@ VectorVal* TopkVal::GetTopK(int k) const // returns vector it--; } - Unref(v); - return t; + return t.release(); } uint64_t TopkVal::GetCount(Val* value) const diff --git a/src/strings.bif b/src/strings.bif index fca92c980d..412b065065 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -204,7 +204,7 @@ static IntrusivePtr do_split_string(StringVal* str_val, int max_num_sep) { // string_vec is used early in the version script - do not use the NetVar. - auto rval = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); + auto rval = make_intrusive(zeek::lookup_type("string_vec")); const u_char* s = str_val->Bytes(); int n = str_val->Len(); const u_char* end_of_s = s + n; @@ -714,7 +714,7 @@ function str_split%(s: string, idx: index_vec%): string_vec BroString::Vec* result = s->AsString()->Split(indices); auto result_v = make_intrusive( - zeek::lookup_type("string_vec")->AsVectorType()); + zeek::lookup_type("string_vec")); if ( result ) { diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 0f063a3f76..0a7e588112 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1123,13 +1123,14 @@ IntrusivePtr Supervisor::NodeConfig::ToRecord() const if ( cpu_affinity ) rval->Assign(rt->FieldOffset("cpu_affinity"), val_mgr->Int(*cpu_affinity)); - const auto& st = rt->GetFieldType("scripts"); - auto scripts_val = new VectorVal(st->AsVectorType()); - rval->Assign(rt->FieldOffset("scripts"), scripts_val); + auto st = rt->GetFieldType("scripts"); + auto scripts_val = make_intrusive(std::move(st)); for ( const auto& s : scripts ) scripts_val->Assign(scripts_val->Size(), make_intrusive(s)); + rval->Assign(rt->FieldOffset("scripts"), std::move(scripts_val)); + const auto& tt = rt->GetFieldType("cluster"); auto cluster_val = new TableVal({NewRef{}, tt->AsTableType()}); rval->Assign(rt->FieldOffset("cluster"), cluster_val); diff --git a/src/zeek.bif b/src/zeek.bif index 1bd4227ec2..5d3a5692fa 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1470,8 +1470,7 @@ function sort%(v: any, ...%) : any ## .. zeek:see:: sort function order%(v: any, ...%) : index_vec %{ - auto result_v = make_intrusive( - lookup_type("index_vec")->AsVectorType()); + auto result_v = make_intrusive(lookup_type("index_vec")); if ( v->Type()->Tag() != TYPE_VECTOR ) { @@ -1825,7 +1824,7 @@ function zeek_version%(%): string function record_type_to_vector%(rt: string%): string_vec %{ auto result = - make_intrusive(lookup_type("string_vec")->AsVectorType()); + make_intrusive(lookup_type("string_vec")); RecordType* type = lookup_type(rt->CheckString())->AsRecordType(); @@ -1854,8 +1853,8 @@ function type_name%(t: any%): string ## Returns: list of command-line arguments (``argv``) used to run Zeek. function zeek_args%(%): string_vec %{ - auto sv = lookup_type("string_vec")->AsVectorType(); - auto rval = make_intrusive(sv); + auto sv = lookup_type("string_vec"); + auto rval = make_intrusive(std::move(sv)); for ( auto i = 0; i < bro_argc; ++i ) rval->Assign(rval->Size(), make_intrusive(bro_argv[i])); @@ -2187,7 +2186,7 @@ function is_v6_subnet%(s: subnet%): bool ## Returns: The vector of addresses contained in the routing header data. function routing0_data_to_addrs%(s: string%): addr_vec %{ - auto rval = make_intrusive(lookup_type("addr_vec")->AsVectorType()); + auto rval = make_intrusive(lookup_type("addr_vec")); int len = s->Len(); const u_char* bytes = s->Bytes(); @@ -2218,7 +2217,7 @@ function routing0_data_to_addrs%(s: string%): addr_vec ## .. zeek:see:: counts_to_addr function addr_to_counts%(a: addr%): index_vec %{ - auto rval = make_intrusive(lookup_type("index_vec")->AsVectorType()); + auto rval = make_intrusive(lookup_type("index_vec")); const uint32_t* bytes; int len = a->AsAddr().GetBytes(&bytes); From afd939ceb10eca4f90f508eb8600c507c0d51ac5 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 9 May 2020 14:14:00 -0700 Subject: [PATCH 037/151] Remove VectorVal::vector_type member --- src/Val.cc | 7 +++---- src/Val.h | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index cda842b50a..fd8d5a4152 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2982,7 +2982,6 @@ VectorVal::VectorVal(VectorType* t) : VectorVal({NewRef{}, t}) VectorVal::VectorVal(IntrusivePtr t) : Val(t.get()) { - vector_type = std::move(t); val.vector_val = new vector(); } @@ -3002,7 +3001,7 @@ IntrusivePtr VectorVal::SizeVal() const bool VectorVal::Assign(unsigned int index, IntrusivePtr element) { if ( element && - ! same_type(element->Type(), vector_type->Yield().get(), false) ) + ! same_type(element->Type(), Type()->AsVectorType()->Yield().get(), false) ) return false; Val* val_at_index = nullptr; @@ -3043,7 +3042,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, bool VectorVal::Insert(unsigned int index, Val* element) { if ( element && - ! same_type(element->Type(), vector_type->Yield().get(), false) ) + ! same_type(element->Type(), Type()->AsVectorType()->Yield().get(), false) ) { Unref(element); return false; @@ -3130,7 +3129,7 @@ unsigned int VectorVal::ResizeAtLeast(unsigned int new_num_elements) IntrusivePtr VectorVal::DoClone(CloneState* state) { - auto vv = make_intrusive(vector_type); + auto vv = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); vv->val.vector_val->reserve(val.vector_val->size()); state->NewClone(this, vv); diff --git a/src/Val.h b/src/Val.h index 54275a95ad..c73579d1e4 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1077,8 +1077,6 @@ public: protected: void ValDescribe(ODesc* d) const override; IntrusivePtr DoClone(CloneState* state) override; - - IntrusivePtr vector_type; }; // Checks the given value for consistency with the given type. If an From 737420c359abd00186e6edbf335c453d9956d22b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 9 May 2020 14:59:50 -0700 Subject: [PATCH 038/151] Change Val to store IntrusivePtr --- src/OpaqueVal.cc | 2 +- src/Val.cc | 30 ++++++++++++++---------------- src/Val.h | 48 +++++++++++++++++++++--------------------------- 3 files changed, 36 insertions(+), 44 deletions(-) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index db58437a0a..fc5f01ed41 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -37,7 +37,7 @@ OpaqueMgr* OpaqueMgr::mgr() return &mgr; } -OpaqueVal::OpaqueVal(OpaqueType* t) : Val(t) +OpaqueVal::OpaqueVal(OpaqueType* t) : Val(IntrusivePtr{NewRef{}, t}) { } diff --git a/src/Val.cc b/src/Val.cc index fd8d5a4152..ecb9914113 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -43,21 +43,21 @@ using namespace std; Val::Val(Func* f) - : val(f), type(f->FType()->Ref()) + : val(f), type({NewRef{}, f->FType()}) { ::Ref(val.func_val); } -static FileType* GetStringFileType() noexcept +static const IntrusivePtr& GetStringFileType() noexcept { - static FileType* string_file_type = nullptr; - if ( ! string_file_type ) - string_file_type = new FileType(base_type(TYPE_STRING)); + static IntrusivePtr string_file_type + = make_intrusive(base_type(TYPE_STRING)); + return string_file_type; } Val::Val(BroFile* f) - : val(f), type(GetStringFileType()->Ref()) + : val(f), type(GetStringFileType()) { assert(f->FType()->Tag() == TYPE_STRING); } @@ -73,7 +73,6 @@ Val::~Val() else if ( type->Tag() == TYPE_FILE ) Unref(val.file_val); - Unref(type); #ifdef DEBUG delete [] bound_id; #endif @@ -1122,7 +1121,7 @@ IntrusivePtr StringVal::DoClone(CloneState* state) } PatternVal::PatternVal(RE_Matcher* re) - : Val(base_type(TYPE_PATTERN).get()) + : Val(base_type(TYPE_PATTERN)) { val.re_val = re; } @@ -1181,14 +1180,13 @@ IntrusivePtr PatternVal::DoClone(CloneState* state) } ListVal::ListVal(TypeTag t) - : Val(new TypeList(t == TYPE_ANY ? nullptr : base_type(t))) + : Val(make_intrusive(t == TYPE_ANY ? nullptr : base_type(t))) { tag = t; } ListVal::~ListVal() { - Unref(type); } IntrusivePtr ListVal::SizeVal() const @@ -1371,7 +1369,7 @@ static void find_nested_record_types(BroType* t, std::set* found) } } -TableVal::TableVal(IntrusivePtr t, IntrusivePtr a) : Val(t.get()) +TableVal::TableVal(IntrusivePtr t, IntrusivePtr a) : Val(t) { Init(std::move(t)); SetAttrs(std::move(a)); @@ -1593,7 +1591,7 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const TableVal* t = val->AsTableVal(); - if ( ! same_type(type, t->Type()) ) + if ( ! same_type(type.get(), t->Type()) ) { type->Error("table type clash", t->Type()); return false; @@ -1639,7 +1637,7 @@ bool TableVal::RemoveFrom(Val* val) const TableVal* t = val->AsTableVal(); - if ( ! same_type(type, t->Type()) ) + if ( ! same_type(type.get(), t->Type()) ) { type->Error("table type clash", t->Type()); return false; @@ -2652,7 +2650,7 @@ TableVal::TableRecordDependencies TableVal::parse_time_table_record_dependencies RecordVal::RecordTypeValMap RecordVal::parse_time_records; -RecordVal::RecordVal(RecordType* t, bool init_fields) : Val(t) +RecordVal::RecordVal(RecordType* t, bool init_fields) : Val(IntrusivePtr{NewRef{}, t}) { origin = nullptr; int n = t->NumFields(); @@ -2980,7 +2978,7 @@ IntrusivePtr EnumVal::DoClone(CloneState* state) VectorVal::VectorVal(VectorType* t) : VectorVal({NewRef{}, t}) { } -VectorVal::VectorVal(IntrusivePtr t) : Val(t.get()) +VectorVal::VectorVal(IntrusivePtr t) : Val(std::move(t)) { val.vector_val = new vector(); } @@ -3088,7 +3086,7 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const VectorVal* v = val->AsVectorVal(); - if ( ! same_type(type, v->Type()) ) + if ( ! same_type(type.get(), v->Type()) ) { type->Error("vector type clash", v->Type()); return false; diff --git a/src/Val.h b/src/Val.h index c73579d1e4..4dfa7528a6 100644 --- a/src/Val.h +++ b/src/Val.h @@ -126,9 +126,8 @@ union BroValUnion { class Val : public BroObj { public: Val(double d, TypeTag t) - : val(d), type(base_type(t)->Ref()) - { - } + : val(d), type(base_type(t)) + {} explicit Val(Func* f); @@ -138,18 +137,16 @@ public: // Extra arg to differentiate from protected version. Val(IntrusivePtr t, bool type_type) - : type(new TypeType(std::move(t))) - { } + : type(make_intrusive(std::move(t))) + {} [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] Val(BroType* t, bool type_type) : Val({NewRef{}, t}, type_type) - { - } + {} Val() - : val(bro_int_t(0)), type(base_type(TYPE_ERROR)->Ref()) - { - } + : val(bro_int_t(0)), type(base_type(TYPE_ERROR)) + {} ~Val() override; @@ -183,8 +180,8 @@ public: // Remove this value from the given value (if appropriate). virtual bool RemoveFrom(Val* v) const; - BroType* Type() { return type; } - const BroType* Type() const { return type; } + BroType* Type() { return type.get(); } + const BroType* Type() const { return type.get(); } #define CONST_ACCESSOR(tag, ctype, accessor, name) \ const ctype name() const \ @@ -226,7 +223,7 @@ public: BroType* AsType() const { CHECK_TAG(type->Tag(), TYPE_TYPE, "Val::Type", type_name) - return type; + return type.get(); } const IPAddr& AsAddr() const @@ -344,21 +341,18 @@ protected: static IntrusivePtr MakeCount(bro_uint_t u); template - Val(V &&v, TypeTag t) noexcept - : val(std::forward(v)), type(base_type(t)->Ref()) - { - } + Val(V&& v, TypeTag t) noexcept + : val(std::forward(v)), type(base_type(t)) + {} template - Val(V &&v, BroType* t) noexcept - : val(std::forward(v)), type(t->Ref()) - { - } + Val(V&& v, IntrusivePtr t) noexcept + : val(std::forward(v)), type(std::move(t)) + {} - explicit Val(BroType* t) - : type(t->Ref()) - { - } + explicit Val(IntrusivePtr t) noexcept + : type(std::move(t)) + {} ACCESSOR(TYPE_TABLE, PDict*, table_val, AsNonConstTable) ACCESSOR(TYPE_RECORD, val_list*, val_list_val, AsNonConstRecord) @@ -377,7 +371,7 @@ protected: virtual IntrusivePtr DoClone(CloneState* state); BroValUnion val; - BroType* type; + IntrusivePtr type; #ifdef DEBUG // For debugging, we keep the name of the ID to which a Val is bound. @@ -1005,7 +999,7 @@ protected: template friend IntrusivePtr make_intrusive(Ts&&... args); - EnumVal(EnumType* t, int i) : Val(bro_int_t(i), t) + EnumVal(EnumType* t, int i) : Val(bro_int_t(i), {NewRef{}, t}) { } From 1eb723fc9d6ba8c0bf98353ba958b96d288987f3 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 11 May 2020 12:14:54 -0700 Subject: [PATCH 039/151] Deprecate Val::Type(), replace with GetType() --- NEWS | 2 + src/CompHash.cc | 40 ++++---- src/DbgBreakpoint.cc | 4 +- src/Expr.cc | 99 +++++++++--------- src/Frame.cc | 4 +- src/Func.cc | 8 +- src/ID.cc | 6 +- src/OpaqueVal.cc | 2 +- src/PrefixTable.cc | 14 +-- src/RuleMatcher.cc | 8 +- src/Sessions.cc | 2 +- src/Stats.cc | 2 +- src/Stmt.cc | 12 +-- src/Val.cc | 117 +++++++++++----------- src/Val.h | 11 +- src/Var.cc | 6 +- src/broker/Data.cc | 14 +-- src/broker/Manager.cc | 22 ++-- src/broker/messaging.bif | 4 +- src/input/Manager.cc | 22 ++-- src/input/ReaderFrontend.cc | 2 +- src/logging/Manager.cc | 22 ++-- src/logging/WriterFrontend.cc | 2 +- src/option.bif | 22 ++-- src/parse.y | 6 +- src/probabilistic/Topk.cc | 4 +- src/probabilistic/bloom-filter.bif | 6 +- src/probabilistic/cardinality-counter.bif | 4 +- src/scan.l | 2 +- src/zeek.bif | 56 +++++------ 30 files changed, 270 insertions(+), 255 deletions(-) diff --git a/NEWS b/NEWS index 8f4d16effd..0c9339663b 100644 --- a/NEWS +++ b/NEWS @@ -169,6 +169,8 @@ Deprecated Functionality - ``opt_internal_val()`` is deprecated, use ``lookup_ID()`` or ``zeek::lookup_val()``. +- ``Val::Type()`` is deprecated, use ``Val::GetType``. + Zeek 3.1.0 ========== diff --git a/src/CompHash.cc b/src/CompHash.cc index 238e8d1129..b018919b2b 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -88,7 +88,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, if ( type_check ) { - InternalTypeTag vt = v->Type()->InternalType(); + InternalTypeTag vt = v->GetType()->InternalType(); if ( vt != t ) return nullptr; } @@ -138,7 +138,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, case TYPE_INTERNAL_VOID: case TYPE_INTERNAL_OTHER: { - switch ( v->Type()->Tag() ) { + switch ( v->GetType()->Tag() ) { case TYPE_FUNC: { uint32_t* kp = AlignAndPadType(kp0); @@ -240,15 +240,15 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, auto idx = kv.second; Val* key = lv->Idx(idx).get(); - if ( ! (kp1 = SingleValHash(type_check, kp1, key->Type(), key, + if ( ! (kp1 = SingleValHash(type_check, kp1, key->GetType().get(), key, false)) ) return nullptr; - if ( ! v->Type()->IsSet() ) + if ( ! v->GetType()->IsSet() ) { auto val = tv->Lookup(key); - if ( ! (kp1 = SingleValHash(type_check, kp1, val->Type(), + if ( ! (kp1 = SingleValHash(type_check, kp1, val->GetType().get(), val.get(), false)) ) return nullptr; } @@ -261,7 +261,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, { unsigned int* kp = AlignAndPadType(kp0); VectorVal* vv = v->AsVectorVal(); - VectorType* vt = v->Type()->AsVectorType(); + VectorType* vt = v->GetType()->AsVectorType(); *kp = vv->Size(); kp1 = reinterpret_cast(kp+1); for ( unsigned int i = 0; i < vv->Size(); ++i ) @@ -293,7 +293,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, for ( int i = 0; i < lv->Length(); ++i ) { Val* v = lv->Idx(i).get(); - if ( ! (kp1 = SingleValHash(type_check, kp1, v->Type(), v, + if ( ! (kp1 = SingleValHash(type_check, kp1, v->GetType().get(), v, false)) ) return nullptr; } @@ -341,7 +341,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const if ( is_singleton ) return ComputeSingletonHash(v, type_check); - if ( is_complex_type && v->Type()->Tag() != TYPE_LIST ) + if ( is_complex_type && v->GetType()->Tag() != TYPE_LIST ) { ListVal lv(TYPE_ANY); @@ -368,7 +368,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const const auto& tl = type->Types(); - if ( type_check && v->Type()->Tag() != TYPE_LIST ) + if ( type_check && v->GetType()->Tag() != TYPE_LIST ) return nullptr; auto lv = v->AsListVal(); @@ -389,7 +389,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) const { - if ( v->Type()->Tag() == TYPE_LIST ) + if ( v->GetType()->Tag() == TYPE_LIST ) { auto lv = v->AsListVal(); @@ -399,7 +399,7 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) cons v = lv->Idx(0).get(); } - if ( type_check && v->Type()->InternalType() != singleton_tag ) + if ( type_check && v->GetType()->InternalType() != singleton_tag ) return nullptr; switch ( singleton_tag ) { @@ -418,10 +418,10 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) cons case TYPE_INTERNAL_VOID: case TYPE_INTERNAL_OTHER: - if ( v->Type()->Tag() == TYPE_FUNC ) + if ( v->GetType()->Tag() == TYPE_FUNC ) return new HashKey(v->AsFunc()->GetUniqueFuncID()); - if ( v->Type()->Tag() == TYPE_PATTERN ) + if ( v->GetType()->Tag() == TYPE_PATTERN ) { const char* texts[2] = { v->AsPattern()->PatternText(), @@ -460,7 +460,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, if ( type_check && v ) { - InternalTypeTag vt = v->Type()->InternalType(); + InternalTypeTag vt = v->GetType()->InternalType(); if ( vt != t ) return 0; } @@ -539,7 +539,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, for ( int i = 0; i < tv->Size(); ++i ) { Val* key = lv->Idx(i).get(); - sz = SingleTypeKeySize(key->Type(), key, type_check, sz, false, + sz = SingleTypeKeySize(key->GetType().get(), key, type_check, sz, false, calc_static_size); if ( ! sz ) return 0; @@ -547,7 +547,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, if ( ! bt->IsSet() ) { auto val = tv->Lookup(key); - sz = SingleTypeKeySize(val->Type(), val.get(), type_check, sz, + sz = SingleTypeKeySize(val->GetType().get(), val.get(), type_check, sz, false, calc_static_size); if ( ! sz ) return 0; @@ -588,7 +588,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, ListVal* lv = const_cast(v->AsListVal()); for ( int i = 0; i < lv->Length(); ++i ) { - sz = SingleTypeKeySize(lv->Idx(i)->Type(), lv->Idx(i).get(), + sz = SingleTypeKeySize(lv->Idx(i)->GetType().get(), lv->Idx(i).get(), type_check, sz, false, calc_static_size); if ( ! sz) return 0; } @@ -628,7 +628,7 @@ int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_stati if ( v ) { - if ( type_check && v->Type()->Tag() != TYPE_LIST ) + if ( type_check && v->GetType()->Tag() != TYPE_LIST ) return 0; auto lv = v->AsListVal(); @@ -851,12 +851,12 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, reporter->InternalError("failed to look up unique function id %" PRIu32 " in CompositeHash::RecoverOneVal()", *kp); *pval = make_intrusive(f); - auto pvt = (*pval)->Type(); + const auto& pvt = (*pval)->GetType(); if ( ! pvt ) reporter->InternalError("bad aggregate Val in CompositeHash::RecoverOneVal()"); - else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt, t) ) + else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt.get(), t) ) // ### Maybe fix later, but may be fundamentally // un-checkable --US reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index e238156eec..2ad5d3ef94 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -258,8 +258,8 @@ BreakCode DbgBreakpoint::HasHit() return bcHit; } - if ( ! IsIntegral(yes->Type()->Tag()) && - ! IsBool(yes->Type()->Tag()) ) + if ( ! IsIntegral(yes->GetType()->Tag()) && + ! IsBool(yes->GetType()->Tag()) ) { PrintHitMsg(); debug_msg("Breakpoint condition should return an integral type"); diff --git a/src/Expr.cc b/src/Expr.cc index 5bda5ee9c1..85404a7991 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -310,10 +310,10 @@ void NameExpr::ExprDescribe(ODesc* d) const ConstExpr::ConstExpr(IntrusivePtr arg_val) : Expr(EXPR_CONST), val(std::move(arg_val)) { - if ( val->Type()->Tag() == TYPE_LIST && val->AsListVal()->Length() == 1 ) + if ( val->GetType()->Tag() == TYPE_LIST && val->AsListVal()->Length() == 1 ) val = val->AsListVal()->Idx(0); - SetType({NewRef{}, val->Type()}); + SetType(val->GetType()); } void ConstExpr::ExprDescribe(ODesc* d) const @@ -355,13 +355,14 @@ IntrusivePtr UnaryExpr::Eval(Frame* f) const if ( is_vector(v.get()) && Tag() != EXPR_IS && Tag() != EXPR_CAST ) { VectorVal* v_op = v->AsVectorVal(); - VectorType* out_t; - if ( Type()->Tag() == TYPE_ANY ) - out_t = v->Type()->AsVectorType(); - else - out_t = Type()->AsVectorType(); + IntrusivePtr out_t; - auto result = make_intrusive(IntrusivePtr{NewRef{}, out_t}); + if ( Type()->Tag() == TYPE_ANY ) + out_t = v->GetType(); + else + out_t = {NewRef{}, Type()->AsVectorType()}; + + auto result = make_intrusive(std::move(out_t)); for ( unsigned int i = 0; i < v_op->Size(); ++i ) { @@ -524,15 +525,15 @@ void BinaryExpr::ExprDescribe(ODesc* d) const IntrusivePtr BinaryExpr::Fold(Val* v1, Val* v2) const { - InternalTypeTag it = v1->Type()->InternalType(); + InternalTypeTag it = v1->GetType()->InternalType(); if ( it == TYPE_INTERNAL_STRING ) return StringFold(v1, v2); - if ( v1->Type()->Tag() == TYPE_PATTERN ) + if ( v1->GetType()->Tag() == TYPE_PATTERN ) return PatternFold(v1, v2); - if ( v1->Type()->IsSet() ) + if ( v1->GetType()->IsSet() ) return SetFold(v1, v2); if ( it == TYPE_INTERNAL_ADDR ) @@ -950,7 +951,7 @@ IntrusivePtr IncrExpr::DoSingleEval(Frame* f, Val* v) const --k; if ( k < 0 && - v->Type()->InternalType() == TYPE_INTERNAL_UNSIGNED ) + v->GetType()->InternalType() == TYPE_INTERNAL_UNSIGNED ) RuntimeError("count underflow"); } @@ -1071,7 +1072,7 @@ PosExpr::PosExpr(IntrusivePtr arg_op) IntrusivePtr PosExpr::Fold(Val* v) const { - TypeTag t = v->Type()->Tag(); + TypeTag t = v->GetType()->Tag(); if ( t == TYPE_DOUBLE || t == TYPE_INTERVAL || t == TYPE_INT ) return {NewRef{}, v}; @@ -1109,9 +1110,9 @@ NegExpr::NegExpr(IntrusivePtr arg_op) IntrusivePtr NegExpr::Fold(Val* v) const { - if ( v->Type()->Tag() == TYPE_DOUBLE ) - return make_intrusive(- v->InternalDouble(), v->Type()->Tag()); - else if ( v->Type()->Tag() == TYPE_INTERVAL ) + if ( v->GetType()->Tag() == TYPE_DOUBLE ) + return make_intrusive(- v->InternalDouble(), v->GetType()->Tag()); + else if ( v->GetType()->Tag() == TYPE_INTERVAL ) return make_intrusive(- v->InternalDouble(), 1.0); else return val_mgr->Int(- v->CoerceToInt()); @@ -1440,7 +1441,7 @@ IntrusivePtr DivideExpr::AddrFold(Val* v1, Val* v2) const { uint32_t mask; - if ( v2->Type()->Tag() == TYPE_COUNT ) + if ( v2->GetType()->Tag() == TYPE_COUNT ) mask = static_cast(v2->InternalUnsigned()); else mask = static_cast(v2->InternalInt()); @@ -2026,7 +2027,10 @@ AssignExpr::AssignExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, if ( IsError() ) return; - SetType({NewRef{}, arg_val ? arg_val->Type() : op1->Type()}); + if ( arg_val ) + SetType(arg_val->GetType()); + else + SetType({NewRef{}, op1->Type()}); if ( is_init ) { @@ -2368,7 +2372,7 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) return nullptr; } - if ( aggr->Type()->Tag() != TYPE_RECORD ) + if ( aggr->GetType()->Tag() != TYPE_RECORD ) Internal("bad aggregate in AssignExpr::InitVal"); RecordVal* aggr_r = aggr->AsRecordVal(); @@ -2390,12 +2394,12 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) return nullptr; } - if ( aggr->Type()->Tag() != TYPE_TABLE ) + if ( aggr->GetType()->Tag() != TYPE_TABLE ) Internal("bad aggregate in AssignExpr::InitVal"); auto tv = cast_intrusive(std::move(aggr)); - const TableType* tt = tv->Type()->AsTableType(); - const auto& yt = tv->Type()->Yield(); + const TableType* tt = tv->GetType()->AsTableType(); + const auto& yt = tv->GetType()->Yield(); auto index = op1->InitVal(tt->Indices(), nullptr); auto v = op2->InitVal(yt.get(), nullptr); @@ -2595,7 +2599,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const auto v_result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); // Booleans select each element (or not). - if ( IsBool(v_v2->Type()->Yield()->Tag()) ) + if ( IsBool(v_v2->GetType()->Yield()->Tag()) ) { if ( v_v1->Size() != v_v2->Size() ) { @@ -2648,7 +2652,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const IntrusivePtr v; - switch ( v1->Type()->Tag() ) { + switch ( v1->GetType()->Tag() ) { case TYPE_VECTOR: { VectorVal* vect = v1->AsVectorVal(); @@ -2659,7 +2663,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const else { size_t len = vect->Size(); - auto result = make_intrusive(IntrusivePtr{NewRef{}, vect->Type()->AsVectorType()}); + auto result = make_intrusive(vect->GetType()); bro_int_t first = get_slice_index(lv->Idx(0)->CoerceToInt(), len); bro_int_t last = get_slice_index(lv->Idx(1)->CoerceToInt(), len); @@ -2749,7 +2753,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) // from the original value after the assignment already unref'd. auto v_extra = v; - switch ( v1->Type()->Tag() ) { + switch ( v1->GetType()->Tag() ) { case TYPE_VECTOR: { const ListVal* lv = v2->AsListVal(); @@ -2779,7 +2783,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) { ODesc d; v->Describe(&d); - auto vt = v->Type(); + const auto& vt = v->GetType(); auto vtt = vt->Tag(); std::string tn = vtt == TYPE_RECORD ? vt->GetName() : type_name(vtt); RuntimeErrorWithCallStack(fmt( @@ -2801,7 +2805,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) { ODesc d; v->Describe(&d); - auto vt = v->Type(); + const auto& vt = v->GetType(); auto vtt = vt->Tag(); std::string tn = vtt == TYPE_RECORD ? vt->GetName() : type_name(vtt); RuntimeErrorWithCallStack(fmt( @@ -3656,7 +3660,7 @@ IntrusivePtr RecordCoerceExpr::InitVal(const BroType* t, IntrusivePtr IntrusivePtr RecordCoerceExpr::Fold(Val* v) const { auto val = make_intrusive(Type()->AsRecordType()); - RecordType* val_type = val->Type()->AsRecordType(); + RecordType* val_type = val->GetType()->AsRecordType(); RecordVal* rv = v->AsRecordVal(); @@ -3668,7 +3672,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const if ( ! rhs ) { - const Attr* def = rv->Type()->AsRecordType()->FieldDecl( + const Attr* def = rv->GetType()->AsRecordType()->FieldDecl( map[i])->FindAttr(ATTR_DEFAULT); if ( def ) @@ -3684,7 +3688,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const continue; } - BroType* rhs_type = rhs->Type(); + BroType* rhs_type = rhs->GetType().get(); BroType* field_type = val_type->GetFieldType(i).get(); if ( rhs_type->Tag() == TYPE_RECORD && @@ -3710,12 +3714,12 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const if ( const Attr* def = Type()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_DEFAULT) ) { auto def_val = def->AttrExpr()->Eval(nullptr); - BroType* def_type = def_val->Type(); + const auto& def_type = def_val->GetType(); const auto& field_type = Type()->AsRecordType()->GetFieldType(i); if ( def_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && - ! same_type(def_type, field_type.get()) ) + ! same_type(def_type.get(), field_type.get()) ) { auto tmp = def_val->AsRecordVal()->CoerceTo( field_type->AsRecordType()); @@ -3833,7 +3837,7 @@ IntrusivePtr FlattenExpr::Fold(Val* v) const continue; } - const RecordType* rv_t = rv->Type()->AsRecordType(); + const RecordType* rv_t = rv->GetType()->AsRecordType(); if ( const Attr* fa = rv_t->FieldDecl(i)->FindAttr(ATTR_DEFAULT) ) l->Append(fa->AttrExpr()->Eval(nullptr)); @@ -4020,14 +4024,14 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) IntrusivePtr InExpr::Fold(Val* v1, Val* v2) const { - if ( v1->Type()->Tag() == TYPE_PATTERN ) + if ( v1->GetType()->Tag() == TYPE_PATTERN ) { RE_Matcher* re = v1->AsPattern(); const BroString* s = v2->AsString(); return val_mgr->Bool(re->MatchAnywhere(s) != 0); } - if ( v2->Type()->Tag() == TYPE_STRING ) + if ( v2->GetType()->Tag() == TYPE_STRING ) { const BroString* s1 = v1->AsString(); const BroString* s2 = v2->AsString(); @@ -4038,8 +4042,8 @@ IntrusivePtr InExpr::Fold(Val* v1, Val* v2) const return val_mgr->Bool(res); } - if ( v1->Type()->Tag() == TYPE_ADDR && - v2->Type()->Tag() == TYPE_SUBNET ) + if ( v1->GetType()->Tag() == TYPE_ADDR && + v2->GetType()->Tag() == TYPE_SUBNET ) return val_mgr->Bool(v2->AsSubNetVal()->Contains(v1->AsAddr())); bool res; @@ -4633,7 +4637,8 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co loop_over_list(exprs, i) { Expr* e = exprs[i]; - auto promoted_e = check_and_promote_expr(e, vec->Type()->AsVectorType()->Yield().get()); + const auto& vyt = vec->GetType()->AsVectorType()->Yield(); + auto promoted_e = check_and_promote_expr(e, vyt.get()); if ( promoted_e ) e = promoted_e.get(); @@ -4670,9 +4675,9 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co auto v = e->Eval(nullptr); - if ( ! same_type(v->Type(), t) ) + if ( ! same_type(v->GetType().get(), t) ) { - v->Type()->Error("type clash in table initializer", t); + v->GetType()->Error("type clash in table initializer", t); return nullptr; } @@ -4686,11 +4691,11 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) const { - if ( aggr->Type()->Tag() != TYPE_TABLE ) + if ( aggr->GetType()->Tag() != TYPE_TABLE ) Internal("bad aggregate in ListExpr::InitVal"); TableVal* tv = aggr->AsTableVal(); - const TableType* tt = tv->Type()->AsTableType(); + const TableType* tt = tv->GetType()->AsTableType(); const TypeList* it = tt->Indices(); for ( const auto& expr : exprs ) @@ -4708,9 +4713,9 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) if ( ! element ) return nullptr; - if ( element->Type()->IsSet() ) + if ( element->GetType()->IsSet() ) { - if ( ! same_type(element->Type(), t) ) + if ( ! same_type(element->GetType().get(), t) ) { element->Error("type clash in set initializer", t); return nullptr; @@ -4875,12 +4880,12 @@ IntrusivePtr CastExpr::Eval(Frame* f) const ODesc d; d.Add("invalid cast of value with type '"); - v->Type()->Describe(&d); + v->GetType()->Describe(&d); d.Add("' to type '"); Type()->Describe(&d); d.Add("'"); - if ( same_type(v->Type(), bro_broker::DataVal::ScriptDataType()) && + if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) && ! v->AsRecordVal()->Lookup(0) ) d.Add(" (nil $data field)"); diff --git a/src/Frame.cc b/src/Frame.cc index 9a7fa733d6..cecea12385 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -198,7 +198,7 @@ Frame* Frame::Clone() const static bool val_is_func(Val* v, BroFunc* func) { - if ( v->Type()->Tag() != TYPE_FUNC ) + if ( v->GetType()->Tag() != TYPE_FUNC ) return false; return v->AsFunc() == func; @@ -357,7 +357,7 @@ broker::expected Frame::Serialize(const Frame* target, const id_li Val* val = target->frame[location]; - TypeTag tag = val->Type()->Tag(); + TypeTag tag = val->GetType()->Tag(); auto expected = bro_broker::val_to_data(val); if ( ! expected ) diff --git a/src/Func.cc b/src/Func.cc index 1ac5d9652d..ae0fd88809 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -240,7 +240,7 @@ std::pair Func::HandlePluginResult(std::pair plugin_resu break; case FUNC_FLAVOR_HOOK: - if ( plugin_result.second->Type()->Tag() != TYPE_BOOL ) + if ( plugin_result.second->GetType()->Tag() != TYPE_BOOL ) reporter->InternalError("plugin returned non-bool for hook %s", this->Name()); break; @@ -255,10 +255,10 @@ std::pair Func::HandlePluginResult(std::pair plugin_resu reporter->InternalError("plugin returned non-void result for void method %s", this->Name()); } - else if ( plugin_result.second && plugin_result.second->Type()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY) + else if ( plugin_result.second && plugin_result.second->GetType()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY) { reporter->InternalError("plugin returned wrong type (got %d, expecting %d) for %s", - plugin_result.second->Type()->Tag(), yt->Tag(), this->Name()); + plugin_result.second->GetType()->Tag(), yt->Tag(), this->Name()); } break; @@ -859,7 +859,7 @@ static int get_func_priority(const attr_list& attrs) continue; } - if ( ! IsIntegral(v->Type()->Tag()) ) + if ( ! IsIntegral(v->GetType()->Tag()) ) { a->Error("expression is not of integral type"); continue; diff --git a/src/ID.cc b/src/ID.cc index 20d4e1df85..01cd943784 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -158,10 +158,10 @@ void ID::UpdateValAttrs() if ( ! attrs ) return; - if ( val && val->Type()->Tag() == TYPE_TABLE ) + if ( val && val->GetType()->Tag() == TYPE_TABLE ) val->AsTableVal()->SetAttrs(attrs); - if ( val && val->Type()->Tag() == TYPE_FILE ) + if ( val && val->GetType()->Tag() == TYPE_FILE ) val->AsFile()->SetAttrs(attrs.get()); if ( GetType()->Tag() == TYPE_FUNC ) @@ -287,7 +287,7 @@ TraversalCode ID::Traverse(TraversalCallback* cb) const } // FIXME: Perhaps we should be checking at other than global scope. - else if ( val && IsFunc(val->Type()->Tag()) && + else if ( val && IsFunc(val->GetType()->Tag()) && cb->current_scope == global_scope() ) { tc = val->AsFunc()->Traverse(cb); diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index fc5f01ed41..ac2ae55711 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -221,7 +221,7 @@ MD5Val::~MD5Val() void HashVal::digest_one(EVP_MD_CTX* h, const Val* v) { - if ( v->Type()->Tag() == TYPE_STRING ) + if ( v->GetType()->Tag() == TYPE_STRING ) { const BroString* str = v->AsString(); hash_update(h, str->Bytes(), str->Len()); diff --git a/src/PrefixTable.cc b/src/PrefixTable.cc index 9506539b69..b0d50b0619 100644 --- a/src/PrefixTable.cc +++ b/src/PrefixTable.cc @@ -43,11 +43,11 @@ void* PrefixTable::Insert(const IPAddr& addr, int width, void* data) void* PrefixTable::Insert(const Val* value, void* data) { // [elem] -> elem - if ( value->Type()->Tag() == TYPE_LIST && + if ( value->GetType()->Tag() == TYPE_LIST && value->AsListVal()->Length() == 1 ) value = value->AsListVal()->Idx(0).get(); - switch ( value->Type()->Tag() ) { + switch ( value->GetType()->Tag() ) { case TYPE_ADDR: return Insert(value->AsAddr(), 128, data); break; @@ -103,11 +103,11 @@ void* PrefixTable::Lookup(const IPAddr& addr, int width, bool exact) const void* PrefixTable::Lookup(const Val* value, bool exact) const { // [elem] -> elem - if ( value->Type()->Tag() == TYPE_LIST && + if ( value->GetType()->Tag() == TYPE_LIST && value->AsListVal()->Length() == 1 ) value = value->AsListVal()->Idx(0).get(); - switch ( value->Type()->Tag() ) { + switch ( value->GetType()->Tag() ) { case TYPE_ADDR: return Lookup(value->AsAddr(), 128, exact); break; @@ -119,7 +119,7 @@ void* PrefixTable::Lookup(const Val* value, bool exact) const default: reporter->InternalWarning("Wrong index type %d for PrefixTable", - value->Type()->Tag()); + value->GetType()->Tag()); return nullptr; } } @@ -142,11 +142,11 @@ void* PrefixTable::Remove(const IPAddr& addr, int width) void* PrefixTable::Remove(const Val* value) { // [elem] -> elem - if ( value->Type()->Tag() == TYPE_LIST && + if ( value->GetType()->Tag() == TYPE_LIST && value->AsListVal()->Length() == 1 ) value = value->AsListVal()->Idx(0).get(); - switch ( value->Type()->Tag() ) { + switch ( value->GetType()->Tag() ) { case TYPE_ADDR: return Remove(value->AsAddr(), 128); break; diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index 1137d0ee76..1341cc9c2b 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -1290,7 +1290,7 @@ static bool val_to_maskedval(Val* v, maskedvalue_list* append_to, { MaskedValue* mval = new MaskedValue; - switch ( v->Type()->Tag() ) { + switch ( v->GetType()->Tag() ) { case TYPE_PORT: mval->val = v->AsPortVal()->Port(); mval->mask = 0xffffffff; @@ -1359,7 +1359,7 @@ void id_to_maskedvallist(const char* id, maskedvalue_list* append_to, if ( ! v ) return; - if ( v->Type()->Tag() == TYPE_TABLE ) + if ( v->GetType()->Tag() == TYPE_TABLE ) { auto lv = v->AsTableVal()->ToPureListVal(); @@ -1381,7 +1381,7 @@ char* id_to_str(const char* id) if ( ! v ) goto error; - if ( v->Type()->Tag() != TYPE_STRING ) + if ( v->GetType()->Tag() != TYPE_STRING ) { rules_error("Identifier must refer to string"); goto error; @@ -1404,7 +1404,7 @@ uint32_t id_to_uint(const char* id) if ( ! v ) return 0; - TypeTag t = v->Type()->Tag(); + TypeTag t = v->GetType()->Tag(); if ( t == TYPE_BOOL || t == TYPE_COUNT || t == TYPE_ENUM || t == TYPE_INT || t == TYPE_PORT ) diff --git a/src/Sessions.cc b/src/Sessions.cc index 8843300f02..afdddbdf1c 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -904,7 +904,7 @@ FragReassembler* NetSessions::NextFragment(double t, const IP_Hdr* ip, Connection* NetSessions::FindConnection(Val* v) { - BroType* vt = v->Type(); + const auto& vt = v->GetType(); if ( ! IsRecord(vt->Tag()) ) return nullptr; diff --git a/src/Stats.cc b/src/Stats.cc index 44d6a5760e..e340e9ebb2 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -269,7 +269,7 @@ void ProfileLogger::Log() if ( size > 100 * 1024 ) print = true; - if ( v->Type()->Tag() == TYPE_TABLE ) + if ( v->GetType()->Tag() == TYPE_TABLE ) { entries = v->AsTable()->Length(); total_table_entries += entries; diff --git a/src/Stmt.cc b/src/Stmt.cc index 7ae7b126f1..f20e154d57 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -227,7 +227,7 @@ IntrusivePtr PrintStmt::DoExec(std::vector> vals, BroFile* f = print_stdout; int offset = 0; - if ( vals.size() > 0 && (vals)[0]->Type()->Tag() == TYPE_FILE ) + if ( vals.size() > 0 && (vals)[0]->GetType()->Tag() == TYPE_FILE ) { f = (vals)[0]->AsFile(); if ( ! f->IsOpen() ) @@ -724,7 +724,7 @@ bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx) { reporter->PushLocation(e->GetLocationInfo()); reporter->InternalError("switch expression type mismatch (%s/%s)", - type_name(v->Type()->Tag()), type_name(e->Type()->Tag())); + type_name(v->GetType()->Tag()), type_name(e->Type()->Tag())); } int* label_idx = case_label_value_map.Lookup(hk); @@ -768,7 +768,7 @@ std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const { reporter->PushLocation(e->GetLocationInfo()); reporter->Error("switch expression type mismatch (%s/%s)", - type_name(v->Type()->Tag()), type_name(e->Type()->Tag())); + type_name(v->GetType()->Tag()), type_name(e->Type()->Tag())); return std::make_pair(-1, nullptr); } @@ -1179,7 +1179,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const { IntrusivePtr ret; - if ( v->Type()->Tag() == TYPE_TABLE ) + if ( v->GetType()->Tag() == TYPE_TABLE ) { TableVal* tv = v->AsTableVal(); const PDict* loop_vals = tv->AsTable(); @@ -1223,7 +1223,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const } } - else if ( v->Type()->Tag() == TYPE_VECTOR ) + else if ( v->GetType()->Tag() == TYPE_VECTOR ) { VectorVal* vv = v->AsVectorVal(); @@ -1243,7 +1243,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const break; } } - else if ( v->Type()->Tag() == TYPE_STRING ) + else if ( v->GetType()->Tag() == TYPE_STRING ) { StringVal* sval = v->AsStringVal(); diff --git a/src/Val.cc b/src/Val.cc index ecb9914113..cd5b0c2934 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -411,7 +411,7 @@ bool Val::WouldOverflow(const BroType* from_type, const BroType* to_type, const IntrusivePtr Val::GetRecordFields() { - auto t = Type(); + auto t = GetType().get(); if ( t->Tag() != TYPE_RECORD && t->Tag() != TYPE_TYPE ) { @@ -457,8 +457,8 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* } rapidjson::Value j; - BroType* type = val->Type(); - switch ( type->Tag() ) + + switch ( val->GetType()->Tag() ) { case TYPE_BOOL: writer.Bool(val->AsBool()); @@ -525,7 +525,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* auto* table = val->AsTable(); auto* tval = val->AsTableVal(); - if ( tval->Type()->IsSet() ) + if ( tval->GetType()->IsSet() ) writer.StartArray(); else writer.StartObject(); @@ -539,7 +539,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* delete k; Val* entry_key = lv->Length() == 1 ? lv->Idx(0).get() : lv.get(); - if ( tval->Type()->IsSet() ) + if ( tval->GetType()->IsSet() ) BuildJSON(writer, entry_key, only_loggable, re); else { @@ -558,7 +558,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* } } - if ( tval->Type()->IsSet() ) + if ( tval->GetType()->IsSet() ) writer.EndArray(); else writer.EndObject(); @@ -571,7 +571,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* writer.StartObject(); auto* rval = val->AsRecordVal(); - auto rt = rval->Type()->AsRecordType(); + auto rt = rval->GetType()->AsRecordType(); for ( auto i = 0; i < rt->NumFields(); ++i ) { @@ -1133,7 +1133,7 @@ PatternVal::~PatternVal() bool PatternVal::AddTo(Val* v, bool /* is_first_init */) const { - if ( v->Type()->Tag() != TYPE_PATTERN ) + if ( v->GetType()->Tag() != TYPE_PATTERN ) { v->Error("not a pattern"); return false; @@ -1213,13 +1213,13 @@ void ListVal::Append(IntrusivePtr v) { if ( type->AsTypeList()->IsPure() ) { - if ( v->Type()->Tag() != tag ) + if ( v->GetType()->Tag() != tag ) Internal("heterogeneous list in ListVal::Append"); } - auto vt = v->Type(); + const auto& vt = v->GetType(); vals.emplace_back(std::move(v)); - type->AsTypeList()->Append({NewRef{}, vt}); + type->AsTypeList()->Append(vt); } void ListVal::Append(Val* v) @@ -1436,9 +1436,8 @@ int TableVal::RecursiveSize() const { int n = AsTable()->Length(); - if ( Type()->IsSet() || - const_cast(Type()->AsTableType())->Yield()->Tag() - != TYPE_TABLE ) + if ( GetType()->IsSet() || + GetType()->AsTableType()->Yield()->Tag() != TYPE_TABLE ) return n; PDict* v = val.table_val; @@ -1583,7 +1582,7 @@ bool TableVal::AddTo(Val* val, bool is_first_init) const bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const { - if ( val->Type()->Tag() != TYPE_TABLE ) + if ( val->GetType()->Tag() != TYPE_TABLE ) { val->Error("not a table"); return false; @@ -1591,9 +1590,9 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const TableVal* t = val->AsTableVal(); - if ( ! same_type(type.get(), t->Type()) ) + if ( ! same_type(type.get(), t->GetType().get()) ) { - type->Error("table type clash", t->Type()); + type->Error("table type clash", t->GetType().get()); return false; } @@ -1629,7 +1628,7 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const bool TableVal::RemoveFrom(Val* val) const { - if ( val->Type()->Tag() != TYPE_TABLE ) + if ( val->GetType()->Tag() != TYPE_TABLE ) { val->Error("not a table"); return false; @@ -1637,9 +1636,9 @@ bool TableVal::RemoveFrom(Val* val) const TableVal* t = val->AsTableVal(); - if ( ! same_type(type.get(), t->Type()) ) + if ( ! same_type(type.get(), t->GetType().get()) ) { - type->Error("table type clash", t->Type()); + type->Error("table type clash", t->GetType().get()); return false; } @@ -1748,7 +1747,7 @@ bool TableVal::IsSubsetOf(const TableVal* tv) const bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) { - BroType* index_type = index->Type(); + const auto& index_type = index->GetType(); if ( index_type->IsSet() ) { @@ -1783,7 +1782,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) // ### if CompositeHash::ComputeHash did flattening // of 1-element lists (like ComputeSingletonHash does), // then we could optimize here. - BroType* t = v->Type(); + const auto& t = v->GetType(); if ( t->IsSet() || t->Tag() == TYPE_LIST ) break; @@ -1807,7 +1806,7 @@ IntrusivePtr TableVal::Default(Val* index) if ( ! def_val ) { - const auto& ytype = Type()->Yield(); + const auto& ytype = GetType()->Yield(); BroType* dtype = def_attr->AttrExpr()->Type(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && @@ -1831,8 +1830,8 @@ IntrusivePtr TableVal::Default(Val* index) return nullptr; } - if ( def_val->Type()->Tag() != TYPE_FUNC || - same_type(def_val->Type(), Type()->Yield().get()) ) + if ( def_val->GetType()->Tag() != TYPE_FUNC || + same_type(def_val->GetType().get(), GetType()->Yield().get()) ) { if ( def_attr->AttrExpr()->IsConst() ) return def_val; @@ -1851,7 +1850,7 @@ IntrusivePtr TableVal::Default(Val* index) const Func* f = def_val->AsFunc(); zeek::Args vl; - if ( index->Type()->Tag() == TYPE_LIST ) + if ( index->GetType()->Tag() == TYPE_LIST ) { auto lv = index->AsListVal(); vl.reserve(lv->Length()); @@ -1945,7 +1944,7 @@ IntrusivePtr TableVal::LookupSubnetValues(const SubNetVal* search) if ( ! subnets ) reporter->InternalError("LookupSubnetValues called on wrong table type"); - auto nt = make_intrusive(IntrusivePtr{NewRef{}, this->Type()->AsTableType()}); + auto nt = make_intrusive(this->GetType()); auto matches = subnets->FindAll(search); for ( auto element : matches ) @@ -2017,7 +2016,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe return; } - if ( thefunc->Type()->Tag() != TYPE_FUNC ) + if ( thefunc->GetType()->Tag() != TYPE_FUNC ) { thefunc->Error("not a function"); return; @@ -2252,7 +2251,7 @@ void TableVal::Describe(ODesc* d) const bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr new_val) { Val* ind_k_v = lv->Idx(k).get(); - auto ind_k = ind_k_v->Type()->IsSet() ? + auto ind_k = ind_k_v->GetType()->IsSet() ? ind_k_v->AsTableVal()->ToListVal() : IntrusivePtr{NewRef{}, ind_k_v->AsListVal()}; @@ -2303,7 +2302,7 @@ void TableVal::InitDefaultFunc(Frame* f) if ( ! def_attr ) return; - const auto& ytype = Type()->Yield(); + const auto& ytype = GetType()->Yield(); BroType* dtype = def_attr->AttrExpr()->Type(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && @@ -2469,7 +2468,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) // Will have been reported already. return 0; - if ( vf->Type()->Tag() != TYPE_FUNC ) + if ( vf->GetType()->Tag() != TYPE_FUNC ) { vf->Error("not a function"); return 0; @@ -2672,8 +2671,8 @@ RecordVal::RecordVal(RecordType* t, bool init_fields) : Val(IntrusivePtr{NewRef{ const auto& type = t->FieldDecl(i)->type; if ( def && type->Tag() == TYPE_RECORD && - def->Type()->Tag() == TYPE_RECORD && - ! same_type(def->Type(), type.get()) ) + def->GetType()->Tag() == TYPE_RECORD && + ! same_type(def->GetType().get(), type.get()) ) { auto tmp = def->AsRecordVal()->CoerceTo(type->AsRecordType()); @@ -2707,7 +2706,7 @@ RecordVal::~RecordVal() IntrusivePtr RecordVal::SizeVal() const { - return val_mgr->Count(Type()->AsRecordType()->NumFields()); + return val_mgr->Count(GetType()->AsRecordType()->NumFields()); } void RecordVal::Assign(int field, IntrusivePtr new_val) @@ -2734,7 +2733,7 @@ IntrusivePtr RecordVal::LookupWithDefault(int field) const if ( val ) return {NewRef{}, val}; - return Type()->AsRecordType()->FieldDefault(field); + return GetType()->AsRecordType()->FieldDefault(field); } void RecordVal::ResizeParseTimeRecords(RecordType* rt) @@ -2769,7 +2768,7 @@ void RecordVal::DoneParsing() IntrusivePtr RecordVal::Lookup(const char* field, bool with_default) const { - int idx = Type()->AsRecordType()->FieldOffset(field); + int idx = GetType()->AsRecordType()->FieldOffset(field); if ( idx < 0 ) reporter->InternalError("missing record field: %s", field); @@ -2779,16 +2778,16 @@ IntrusivePtr RecordVal::Lookup(const char* field, bool with_default) const IntrusivePtr RecordVal::CoerceTo(const RecordType* t, Val* aggr, bool allow_orphaning) const { - if ( ! record_promotion_compatible(t->AsRecordType(), Type()->AsRecordType()) ) + if ( ! record_promotion_compatible(t->AsRecordType(), GetType()->AsRecordType()) ) return nullptr; if ( ! aggr ) aggr = new RecordVal(const_cast(t->AsRecordType())); RecordVal* ar = aggr->AsRecordVal(); - RecordType* ar_t = aggr->Type()->AsRecordType(); + RecordType* ar_t = aggr->GetType()->AsRecordType(); - const RecordType* rv_t = Type()->AsRecordType(); + const RecordType* rv_t = GetType()->AsRecordType(); int i; for ( i = 0; i < rv_t->NumFields(); ++i ) @@ -2816,7 +2815,7 @@ IntrusivePtr RecordVal::CoerceTo(const RecordType* t, Val* aggr, bool const auto& ft = ar_t->GetFieldType(t_i); - if ( ft->Tag() == TYPE_RECORD && ! same_type(ft.get(), v->Type()) ) + if ( ft->Tag() == TYPE_RECORD && ! same_type(ft.get(), v->GetType().get()) ) { auto rhs = make_intrusive(IntrusivePtr{NewRef{}, v}); auto e = make_intrusive(std::move(rhs), @@ -2843,7 +2842,7 @@ IntrusivePtr RecordVal::CoerceTo(const RecordType* t, Val* aggr, bool IntrusivePtr RecordVal::CoerceTo(RecordType* t, bool allow_orphaning) { - if ( same_type(Type(), t) ) + if ( same_type(GetType().get(), t) ) return {NewRef{}, this}; return CoerceTo(t, nullptr, allow_orphaning); @@ -2851,14 +2850,14 @@ IntrusivePtr RecordVal::CoerceTo(RecordType* t, bool allow_orphaning) IntrusivePtr RecordVal::GetRecordFieldsVal() const { - return Type()->AsRecordType()->GetRecordFieldsVal(this); + return GetType()->AsRecordType()->GetRecordFieldsVal(this); } void RecordVal::Describe(ODesc* d) const { const val_list* vl = AsRecord(); int n = vl->length(); - auto record_type = Type()->AsRecordType(); + auto record_type = GetType()->AsRecordType(); if ( d->IsBinary() || d->IsPortable() ) { @@ -2895,7 +2894,7 @@ void RecordVal::DescribeReST(ODesc* d) const { const val_list* vl = AsRecord(); int n = vl->length(); - auto record_type = Type()->AsRecordType(); + auto record_type = GetType()->AsRecordType(); d->Add("{"); d->PushIndent(); @@ -2927,7 +2926,7 @@ IntrusivePtr RecordVal::DoClone(CloneState* state) // record. As we cannot guarantee that it will ber zeroed out at the // approproate time (as it seems to be guaranteed for the original record) // we don't touch it. - auto rv = make_intrusive(Type()->AsRecordType(), false); + auto rv = make_intrusive(GetType()->AsRecordType(), false); rv->origin = nullptr; state->NewClone(this, rv); @@ -2999,7 +2998,7 @@ IntrusivePtr VectorVal::SizeVal() const bool VectorVal::Assign(unsigned int index, IntrusivePtr element) { if ( element && - ! same_type(element->Type(), Type()->AsVectorType()->Yield().get(), false) ) + ! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) ) return false; Val* val_at_index = nullptr; @@ -3040,7 +3039,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, bool VectorVal::Insert(unsigned int index, Val* element) { if ( element && - ! same_type(element->Type(), Type()->AsVectorType()->Yield().get(), false) ) + ! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) ) { Unref(element); return false; @@ -3078,7 +3077,7 @@ bool VectorVal::Remove(unsigned int index) bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const { - if ( val->Type()->Tag() != TYPE_VECTOR ) + if ( val->GetType()->Tag() != TYPE_VECTOR ) { val->Error("not a vector"); return false; @@ -3086,9 +3085,9 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const VectorVal* v = val->AsVectorVal(); - if ( ! same_type(type.get(), v->Type()) ) + if ( ! same_type(type.get(), v->GetType().get()) ) { - type->Error("vector type clash", v->Type()); + type->Error("vector type clash", v->GetType().get()); return false; } @@ -3127,7 +3126,7 @@ unsigned int VectorVal::ResizeAtLeast(unsigned int new_num_elements) IntrusivePtr VectorVal::DoClone(CloneState* state) { - auto vv = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + auto vv = make_intrusive(GetType()); vv->val.vector_val->reserve(val.vector_val->size()); state->NewClone(this, vv); @@ -3166,7 +3165,7 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, if ( ! v ) return nullptr; - BroType* vt = v->Type(); + BroType* vt = v->GetType().get(); vt = flatten_type(vt); t = flatten_type(t); @@ -3275,17 +3274,17 @@ bool same_val(const Val* /* v1 */, const Val* /* v2 */) bool is_atomic_val(const Val* v) { - return is_atomic_type(v->Type()); + return is_atomic_type(v->GetType().get()); } bool same_atomic_val(const Val* v1, const Val* v2) { // This is a very preliminary implementation of same_val(), // true only for equal, simple atomic values of same type. - if ( v1->Type()->Tag() != v2->Type()->Tag() ) + if ( v1->GetType()->Tag() != v2->GetType()->Tag() ) return false; - switch ( v1->Type()->InternalType() ) { + switch ( v1->GetType()->InternalType() ) { case TYPE_INTERNAL_INT: return v1->InternalInt() == v2->InternalInt(); case TYPE_INTERNAL_UNSIGNED: @@ -3362,10 +3361,10 @@ IntrusivePtr cast_value_to_type(Val* v, BroType* t) // Always allow casting to same type. This also covers casting 'any' // to the actual type. - if ( same_type(v->Type(), t) ) + if ( same_type(v->GetType().get(), t) ) return {NewRef{}, v}; - if ( same_type(v->Type(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) { auto dv = v->AsRecordVal()->Lookup(0); @@ -3388,10 +3387,10 @@ bool can_cast_value_to_type(const Val* v, BroType* t) // Always allow casting to same type. This also covers casting 'any' // to the actual type. - if ( same_type(v->Type(), t) ) + if ( same_type(v->GetType().get(), t) ) return true; - if ( same_type(v->Type(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) { auto dv = v->AsRecordVal()->Lookup(0); diff --git a/src/Val.h b/src/Val.h index 4dfa7528a6..e523882f2e 100644 --- a/src/Val.h +++ b/src/Val.h @@ -180,9 +180,18 @@ public: // Remove this value from the given value (if appropriate). virtual bool RemoveFrom(Val* v) const; + [[deprecated("Remove in v4.1. Use GetType().")]] BroType* Type() { return type.get(); } + [[deprecated("Remove in v4.1. Use GetType().")]] const BroType* Type() const { return type.get(); } + const IntrusivePtr& GetType() const + { return type; } + + template + IntrusivePtr GetType() const + { return cast_intrusive(type); } + #define CONST_ACCESSOR(tag, ctype, accessor, name) \ const ctype name() const \ { \ @@ -1091,7 +1100,7 @@ extern void describe_vals(const std::vector>& vals, extern void delete_vals(val_list* vals); // True if the given Val* has a vector type. -inline bool is_vector(Val* v) { return v->Type()->Tag() == TYPE_VECTOR; } +inline bool is_vector(Val* v) { return v->GetType()->Tag() == TYPE_VECTOR; } // Returns v casted to type T if the type supports that. Returns null if not. // diff --git a/src/Var.cc b/src/Var.cc index afc4fcd0c1..37b699c835 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -741,10 +741,10 @@ ListVal* internal_list_val(const char* name) if ( v ) { - if ( v->Type()->Tag() == TYPE_LIST ) + if ( v->GetType()->Tag() == TYPE_LIST ) return (ListVal*) v; - else if ( v->Type()->IsSet() ) + else if ( v->GetType()->IsSet() ) { TableVal* tv = v->AsTableVal(); auto lv = tv->ToPureListVal(); @@ -812,7 +812,7 @@ IntrusivePtr zeek::lookup_func(const char* name) if ( ! v ) return nullptr; - if ( ! IsFunc(v->Type()->Tag()) ) + if ( ! IsFunc(v->GetType()->Tag()) ) reporter->InternalError("Expected variable '%s' to be a function", name); return {NewRef{}, v->AsFunc()}; diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 77adc010fc..fa2de5dd73 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -361,7 +361,7 @@ struct val_converter { if ( ! rval ) return nullptr; - auto t = rval->Type(); + const auto& t = rval->GetType(); if ( ! t ) return nullptr; @@ -705,7 +705,7 @@ struct type_checker { if ( ! rval ) return false; - auto t = rval->Type(); + const auto& t = rval->GetType(); if ( ! t ) return false; @@ -793,7 +793,7 @@ IntrusivePtr bro_broker::data_to_val(broker::data d, BroType* type) broker::expected bro_broker::val_to_data(const Val* v) { - switch ( v->Type()->Tag() ) { + switch ( v->GetType()->Tag() ) { case TYPE_BOOL: return {v->AsBool()}; case TYPE_INT: @@ -843,7 +843,7 @@ broker::expected bro_broker::val_to_data(const Val* v) } case TYPE_ENUM: { - auto enum_type = v->Type()->AsEnumType(); + auto enum_type = v->GetType()->AsEnumType(); auto enum_name = enum_type->Lookup(v->AsEnum()); return {broker::enum_value(enum_name ? enum_name : "")}; } @@ -884,7 +884,7 @@ broker::expected bro_broker::val_to_data(const Val* v) } case TYPE_TABLE: { - auto is_set = v->Type()->IsSet(); + auto is_set = v->GetType()->IsSet(); auto table = v->AsTable(); auto table_val = v->AsTableVal(); broker::data rval; @@ -965,7 +965,7 @@ broker::expected bro_broker::val_to_data(const Val* v) { auto rec = v->AsRecordVal(); broker::vector rval; - size_t num_fields = v->Type()->AsRecordType()->NumFields(); + size_t num_fields = v->GetType()->AsRecordType()->NumFields(); rval.reserve(num_fields); for ( auto i = 0u; i < num_fields; ++i ) @@ -1007,7 +1007,7 @@ broker::expected bro_broker::val_to_data(const Val* v) } default: reporter->Error("unsupported Broker::Data type: %s", - type_name(v->Type()->Tag())); + type_name(v->GetType()->Tag())); break; } diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 8e1e5f5416..940407b032 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -429,7 +429,7 @@ bool Manager::PublishIdentifier(std::string topic, std::string id) if ( ! data ) { Error("Failed to publish ID with unsupported type: %s (%s)", - id.c_str(), type_name(val->Type()->Tag())); + id.c_str(), type_name(val->GetType()->Tag())); return false; } @@ -452,7 +452,7 @@ bool Manager::PublishLogCreate(EnumVal* stream, EnumVal* writer, if ( peer_count == 0 ) return true; - auto stream_id = stream->Type()->AsEnumType()->Lookup(stream->AsEnum()); + auto stream_id = stream->GetType()->AsEnumType()->Lookup(stream->AsEnum()); if ( ! stream_id ) { @@ -461,7 +461,7 @@ bool Manager::PublishLogCreate(EnumVal* stream, EnumVal* writer, return false; } - auto writer_id = writer->Type()->AsEnumType()->Lookup(writer->AsEnum()); + auto writer_id = writer->GetType()->AsEnumType()->Lookup(writer->AsEnum()); if ( ! writer_id ) { @@ -507,7 +507,7 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int return true; auto stream_id_num = stream->AsEnum(); - auto stream_id = stream->Type()->AsEnumType()->Lookup(stream_id_num); + auto stream_id = stream->GetType()->AsEnumType()->Lookup(stream_id_num); if ( ! stream_id ) { @@ -516,7 +516,7 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int return false; } - auto writer_id = writer->Type()->AsEnumType()->Lookup(writer->AsEnum()); + auto writer_id = writer->GetType()->AsEnumType()->Lookup(writer->AsEnum()); if ( ! writer_id ) { @@ -638,7 +638,7 @@ void Manager::Error(const char* format, ...) bool Manager::AutoPublishEvent(string topic, Val* event) { - if ( event->Type()->Tag() != TYPE_FUNC ) + if ( event->GetType()->Tag() != TYPE_FUNC ) { Error("Broker::auto_publish must operate on an event"); return false; @@ -667,7 +667,7 @@ bool Manager::AutoPublishEvent(string topic, Val* event) bool Manager::AutoUnpublishEvent(const string& topic, Val* event) { - if ( event->Type()->Tag() != TYPE_FUNC ) + if ( event->GetType()->Tag() != TYPE_FUNC ) { Error("Broker::auto_event_stop must operate on an event"); return false; @@ -713,7 +713,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) { // Event val must come first. - if ( arg_val->Type()->Tag() != TYPE_FUNC ) + if ( arg_val->GetType()->Tag() != TYPE_FUNC ) { Error("attempt to convert non-event into an event type"); return rval; @@ -740,10 +740,10 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) continue; } - auto got_type = (*args)[i]->Type(); + const auto& got_type = (*args)[i]->GetType(); const auto& expected_type = func->FType()->ArgTypes()->Types()[i - 1]; - if ( ! same_type(got_type, expected_type.get()) ) + if ( ! same_type(got_type.get(), expected_type.get()) ) { rval->Assign(0, nullptr); Error("event parameter #%d type mismatch, got %s, expect %s", i, @@ -754,7 +754,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) IntrusivePtr data_val; - if ( same_type(got_type, bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(got_type.get(), bro_broker::DataVal::ScriptDataType()) ) data_val = {NewRef{}, (*args)[i]->AsRecordVal()}; else data_val = make_data_val((*args)[i]); diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index fd33464371..fc5cfd3f31 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -24,7 +24,7 @@ std::set val_to_topic_set(Val* val) { std::set rval; - if ( val->Type()->Tag() == TYPE_STRING ) + if ( val->GetType()->Tag() == TYPE_STRING ) rval.emplace(val->AsString()->CheckString()); else { @@ -53,7 +53,7 @@ static bool publish_event_args(val_list& args, const BroString* topic, bro_broker::Manager::ScriptScopeGuard ssg; auto rval = false; - if ( args[0]->Type()->Tag() == TYPE_RECORD ) + if ( args[0]->GetType()->Tag() == TYPE_RECORD ) rval = broker_mgr->PublishEvent(topic->CheckString(), args[0]->AsRecordVal()); else diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 0bbb083a9f..23931b6f56 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -224,7 +224,7 @@ ReaderBackend* Manager::CreateBackend(ReaderFrontend* frontend, EnumVal* tag) // Create a new input reader object to be used at whomevers leisure later on. bool Manager::CreateStream(Stream* info, RecordVal* description) { - RecordType* rtype = description->Type()->AsRecordType(); + RecordType* rtype = description->GetType()->AsRecordType(); if ( ! ( same_type(rtype, BifType::Record::Input::TableDescription, false) || same_type(rtype, BifType::Record::Input::EventDescription, false) || same_type(rtype, BifType::Record::Input::AnalysisDescription, false) ) ) @@ -310,7 +310,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) bool Manager::CreateEventStream(RecordVal* fval) { - RecordType* rtype = fval->Type()->AsRecordType(); + RecordType* rtype = fval->GetType()->AsRecordType(); if ( ! same_type(rtype, BifType::Record::Input::EventDescription, false) ) { reporter->Error("EventDescription argument not of right type"); @@ -463,7 +463,7 @@ bool Manager::CreateEventStream(RecordVal* fval) bool Manager::CreateTableStream(RecordVal* fval) { - RecordType* rtype = fval->Type()->AsRecordType(); + RecordType* rtype = fval->GetType()->AsRecordType(); if ( ! same_type(rtype, BifType::Record::Input::TableDescription, false) ) { reporter->Error("TableDescription argument not of right type"); @@ -486,7 +486,7 @@ bool Manager::CreateTableStream(RecordVal* fval) // check if index fields match table description int num = idx->NumFields(); - const auto& tl = dst->Type()->AsTableType()->IndexTypes(); + const auto& tl = dst->GetType()->AsTableType()->IndexTypes(); int j; for ( j = 0; j < static_cast(tl.size()); ++j ) @@ -522,7 +522,7 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( val ) { - const auto& table_yield = dst->Type()->AsTableType()->Yield(); + const auto& table_yield = dst->GetType()->AsTableType()->Yield(); const BroType* compare_type = val.get(); if ( want_record->InternalInt() == 0 ) @@ -541,7 +541,7 @@ bool Manager::CreateTableStream(RecordVal* fval) } else { - if ( ! dst->Type()->IsSet() ) + if ( ! dst->GetType()->IsSet() ) { reporter->Error("Input stream %s: 'destination' field is a table," " but 'val' field is not provided" @@ -748,7 +748,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e bool Manager::CreateAnalysisStream(RecordVal* fval) { - RecordType* rtype = fval->Type()->AsRecordType(); + RecordType* rtype = fval->GetType()->AsRecordType(); if ( ! same_type(rtype, BifType::Record::Input::AnalysisDescription, false) ) { @@ -955,7 +955,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, c = rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN)->AttrExpr()->Eval(nullptr); assert(c); - assert(c->Type()->Tag() == TYPE_STRING); + assert(c->GetType()->Tag() == TYPE_STRING); secondary = c->AsStringVal()->AsString()->CheckString(); } @@ -1000,7 +1000,7 @@ Val* Manager::RecordValToIndexVal(RecordVal *r) const { IntrusivePtr idxval; - RecordType *type = r->Type()->AsRecordType(); + RecordType *type = r->GetType()->AsRecordType(); int num_fields = type->NumFields(); @@ -1845,10 +1845,10 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu Val* v = ValueToVal(i, vals[j], convert_error); vl.emplace_back(AdoptRef{}, v); - if ( v && ! convert_error && ! same_type(type->GetFieldType(j).get(), v->Type()) ) + if ( v && ! convert_error && ! same_type(type->GetFieldType(j).get(), v->GetType().get()) ) { convert_error = true; - type->GetFieldType(j)->Error("SendEvent types do not match", v->Type()); + type->GetFieldType(j)->Error("SendEvent types do not match", v->GetType().get()); } } diff --git a/src/input/ReaderFrontend.cc b/src/input/ReaderFrontend.cc index 7fce36ee71..e634570d85 100644 --- a/src/input/ReaderFrontend.cc +++ b/src/input/ReaderFrontend.cc @@ -39,7 +39,7 @@ ReaderFrontend::ReaderFrontend(const ReaderBackend::ReaderInfo& arg_info, EnumVa disabled = initialized = false; info = new ReaderBackend::ReaderInfo(arg_info); - const char* t = type->Type()->AsEnumType()->Lookup(type->InternalInt()); + const char* t = type->GetType()->AsEnumType()->Lookup(type->InternalInt()); name = copy_string(fmt("%s/%s", arg_info.source, t)); backend = input_mgr->CreateBackend(this, type); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 343af8a5a1..9dfbeff286 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -229,7 +229,7 @@ void Manager::RemoveDisabledWriters(Stream* stream) bool Manager::CreateStream(EnumVal* id, RecordVal* sval) { - RecordType* rtype = sval->Type()->AsRecordType(); + RecordType* rtype = sval->GetType()->AsRecordType(); if ( ! same_type(rtype, BifType::Record::Log::Stream, false) ) { @@ -309,7 +309,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) streams[idx] = new Stream; streams[idx]->id = id->Ref()->AsEnumVal(); streams[idx]->enabled = true; - streams[idx]->name = id->Type()->AsEnumType()->Lookup(idx); + streams[idx]->name = id->GetType()->AsEnumType()->Lookup(idx); streams[idx]->event = event ? event_registry->Lookup(event->Name()) : nullptr; streams[idx]->columns = columns->Ref()->AsRecordType(); @@ -532,7 +532,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, bool Manager::AddFilter(EnumVal* id, RecordVal* fval) { - RecordType* rtype = fval->Type()->AsRecordType(); + RecordType* rtype = fval->GetType()->AsRecordType(); if ( ! same_type(rtype, BifType::Record::Log::Filter, false) ) { @@ -759,7 +759,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) if ( ! v ) return false; - if ( v->Type()->Tag() != TYPE_STRING ) + if ( v->GetType()->Tag() != TYPE_STRING ) { reporter->Error("path_func did not return string"); return false; @@ -826,7 +826,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) auto wi = w->second; wi->hook_initialized = true; PLUGIN_HOOK_VOID(HOOK_LOG_INIT, - HookLogInit(filter->writer->Type()->AsEnumType()->Lookup(filter->writer->InternalInt()), + HookLogInit(filter->writer->GetType()->AsEnumType()->Lookup(filter->writer->InternalInt()), wi->instantiating_filter, filter->local, filter->remote, *wi->info, filter->num_fields, @@ -891,7 +891,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) threading::Value** vals = RecordToFilterVals(stream, filter, columns.get()); if ( ! PLUGIN_HOOK_WITH_RESULT(HOOK_LOG_WRITE, - HookLogWrite(filter->writer->Type()->AsEnumType()->Lookup(filter->writer->InternalInt()), + HookLogWrite(filter->writer->GetType()->AsEnumType()->Lookup(filter->writer->InternalInt()), filter->name, *info, filter->num_fields, filter->fields, vals), @@ -922,7 +922,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) { if ( ! ty ) - ty = val->Type(); + ty = val->GetType().get(); if ( ! val ) return new threading::Value(ty->Tag(), false); @@ -938,7 +938,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) case TYPE_ENUM: { const char* s = - val->Type()->AsEnumType()->Lookup(val->InternalInt()); + val->GetType()->AsEnumType()->Lookup(val->InternalInt()); if ( s ) { @@ -948,7 +948,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) else { - val->Type()->Error("enum type does not contain value", val); + val->GetType()->Error("enum type does not contain value", val); lval->val.string_val.data = copy_string(""); lval->val.string_val.length = 0; } @@ -1038,7 +1038,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) { lval->val.vector_val.vals[i] = ValToLogVal(vec->Lookup(i), - vec->Type()->Yield().get()); + vec->GetType()->Yield().get()); } break; @@ -1206,7 +1206,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken { winfo->hook_initialized = true; PLUGIN_HOOK_VOID(HOOK_LOG_INIT, - HookLogInit(writer->Type()->AsEnumType()->Lookup(writer->InternalInt()), + HookLogInit(writer->GetType()->AsEnumType()->Lookup(writer->InternalInt()), instantiating_filter, local, remote, *winfo->info, num_fields, fields)); } diff --git a/src/logging/WriterFrontend.cc b/src/logging/WriterFrontend.cc index c8953b817e..307b121e17 100644 --- a/src/logging/WriterFrontend.cc +++ b/src/logging/WriterFrontend.cc @@ -116,7 +116,7 @@ WriterFrontend::WriterFrontend(const WriterBackend::WriterInfo& arg_info, EnumVa num_fields = 0; fields = nullptr; - const char* w = arg_writer->Type()->AsEnumType()->Lookup(arg_writer->InternalInt()); + const char* w = arg_writer->GetType()->AsEnumType()->Lookup(arg_writer->InternalInt()); name = copy_string(fmt("%s/%s", arg_info.path, w)); if ( local ) diff --git a/src/option.bif b/src/option.bif index c898b725bf..353dc414c1 100644 --- a/src/option.bif +++ b/src/option.bif @@ -79,7 +79,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool return val_mgr->False(); } - if ( same_type(val->Type(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(val->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) { auto dv = static_cast(val->AsRecordVal()->Lookup(0)); auto val_from_data = dv->castTo(i->GetType().get()); @@ -95,11 +95,11 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool return val_mgr->Bool(rval); } - if ( ! same_type(i->GetType().get(), val->Type()) ) + if ( ! same_type(i->GetType().get(), val->GetType().get()) ) { if ( i->GetType()->Tag() == TYPE_TABLE && - val->Type()->Tag() == TYPE_TABLE && - val->Type()->AsTableType()->IsUnspecifiedTable() ) + val->GetType()->Tag() == TYPE_TABLE && + val->GetType()->AsTableType()->IsUnspecifiedTable() ) { // Just coerce an empty/unspecified table to the right type. auto tv = make_intrusive( @@ -110,7 +110,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool } builtin_error(fmt("Incompatible type for set of ID '%s': got '%s', need '%s'", - ID->CheckString(), type_name(val->Type()->Tag()), type_name(i->GetType()->Tag()))); + ID->CheckString(), type_name(val->GetType()->Tag()), type_name(i->GetType()->Tag()))); return val_mgr->False(); } @@ -157,20 +157,20 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( on_change->Type()->Tag() != TYPE_FUNC ) + if ( on_change->GetType()->Tag() != TYPE_FUNC ) { builtin_error(fmt("Option::on_change needs function argument; got '%s' for ID '%s'", - type_name(on_change->Type()->Tag()), ID->CheckString())); + type_name(on_change->GetType()->Tag()), ID->CheckString())); return val_mgr->False(); } - if ( on_change->Type()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) + if ( on_change->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) { builtin_error("Option::on_change needs function argument; not hook or event"); return val_mgr->False(); } - const auto& args = on_change->Type()->AsFuncType()->ArgTypes()->Types(); + const auto& args = on_change->GetType()->AsFuncType()->ArgTypes()->Types(); if ( args.size() < 2 || args.size() > 3 ) { builtin_error(fmt("Wrong number of arguments for passed function in Option::on_change for ID '%s'; expected 2 or 3, got %zu", @@ -199,10 +199,10 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( ! same_type(on_change->Type()->AsFuncType()->Yield().get(), i->GetType().get()) ) + if ( ! same_type(on_change->GetType()->AsFuncType()->Yield().get(), i->GetType().get()) ) { builtin_error(fmt("Passed function needs to return type '%s' for ID '%s'; got '%s'", - type_name(i->GetType()->Tag()), ID->CheckString(), type_name(on_change->Type()->AsFuncType()->Yield()->Tag()))); + type_name(i->GetType()->Tag()), ID->CheckString(), type_name(on_change->GetType()->AsFuncType()->Yield()->Tag()))); return val_mgr->False(); } diff --git a/src/parse.y b/src/parse.y index 0025cb4eb1..645a64e399 100644 --- a/src/parse.y +++ b/src/parse.y @@ -813,7 +813,7 @@ enum_body_elem: set_location(@1, @3); assert(cur_enum_type); - if ( $3->Type()->Tag() != TYPE_COUNT ) + if ( $3->GetType()->Tag() != TYPE_COUNT ) reporter->Error("enumerator is not a count constant"); else cur_enum_type->AddName(current_module, $1, @@ -1382,7 +1382,7 @@ attr: { $$ = new Attr(ATTR_DEPRECATED); } | TOK_ATTR_DEPRECATED '=' TOK_CONSTANT { - if ( IsString($3->Type()->Tag()) ) + if ( IsString($3->GetType()->Tag()) ) $$ = new Attr(ATTR_DEPRECATED, make_intrusive(IntrusivePtr{AdoptRef{}, $3})); else { @@ -1869,7 +1869,7 @@ opt_deprecated: | TOK_ATTR_DEPRECATED '=' TOK_CONSTANT { - if ( IsString($3->Type()->Tag()) ) + if ( IsString($3->GetType()->Tag()) ) $$ = new ConstExpr({AdoptRef{}, $3}); else { diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 6c79e9ff6a..841fc771c8 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -284,9 +284,9 @@ void TopkVal::Encountered(Val* encountered) // ok, let's see if we already know this one. if ( numElements == 0 ) - Typify(encountered->Type()); + Typify(encountered->GetType().get()); else - if ( ! same_type(type, encountered->Type()) ) + if ( ! same_type(type, encountered->GetType().get()) ) { reporter->Error("Trying to add element to topk with differing type from other elements"); return; diff --git a/src/probabilistic/bloom-filter.bif b/src/probabilistic/bloom-filter.bif index fb9784658e..ae88af31c4 100644 --- a/src/probabilistic/bloom-filter.bif +++ b/src/probabilistic/bloom-filter.bif @@ -146,10 +146,10 @@ function bloomfilter_add%(bf: opaque of bloomfilter, x: any%): any %{ BloomFilterVal* bfv = static_cast(bf); - if ( ! bfv->Type() && ! bfv->Typify(x->Type()) ) + if ( ! bfv->Type() && ! bfv->Typify(x->GetType().get()) ) reporter->Error("failed to set Bloom filter type"); - else if ( ! same_type(bfv->Type(), x->Type()) ) + else if ( ! same_type(bfv->Type(), x->GetType().get()) ) reporter->Error("incompatible Bloom filter types"); else @@ -176,7 +176,7 @@ function bloomfilter_lookup%(bf: opaque of bloomfilter, x: any%): count if ( ! bfv->Type() ) return val_mgr->Count(0); - else if ( ! same_type(bfv->Type(), x->Type()) ) + else if ( ! same_type(bfv->Type(), x->GetType().get()) ) reporter->Error("incompatible Bloom filter types"); else diff --git a/src/probabilistic/cardinality-counter.bif b/src/probabilistic/cardinality-counter.bif index 5b92754267..a8a6581a7e 100644 --- a/src/probabilistic/cardinality-counter.bif +++ b/src/probabilistic/cardinality-counter.bif @@ -42,13 +42,13 @@ function hll_cardinality_add%(handle: opaque of cardinality, elem: any%): bool %{ CardinalityVal* cv = static_cast(handle); - if ( ! cv->Type() && ! cv->Typify(elem->Type()) ) + if ( ! cv->Type() && ! cv->Typify(elem->GetType().get()) ) { reporter->Error("failed to set HLL type"); return val_mgr->False(); } - else if ( ! same_type(cv->Type(), elem->Type()) ) + else if ( ! same_type(cv->Type(), elem->GetType().get()) ) { reporter->Error("incompatible HLL data type"); return val_mgr->False(); diff --git a/src/scan.l b/src/scan.l index fdd4bac766..fd23c6e5c8 100644 --- a/src/scan.l +++ b/src/scan.l @@ -1003,7 +1003,7 @@ int yywrap() auto param_id = lookup_ID(param, GLOBAL_MODULE_NAME); Val* v = param_id ? param_id->GetVal().get() : nullptr; - if ( v && v->Type() && v->Type()->Tag() == TYPE_STRING ) + if ( v && v->GetType() && v->GetType()->Tag() == TYPE_STRING ) opt_quote = "\""; // use quotes policy += std::string("redef ") + param + "=" diff --git a/src/zeek.bif b/src/zeek.bif index 5d3a5692fa..1876dc741e 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -69,8 +69,8 @@ static int check_fmt_type(TypeTag t, TypeTag ok[]) static void do_fmt(const char*& fmt, Val* v, ODesc* d) { - TypeTag t = v->Type()->Tag(); - InternalTypeTag it = v->Type()->InternalType(); + TypeTag t = v->GetType()->Tag(); + InternalTypeTag it = v->GetType()->InternalType(); bool zero_pad = false; bool left_just = false; @@ -199,9 +199,9 @@ static void do_fmt(const char*& fmt, Val* v, ODesc* d) { bro_uint_t u = v->CoerceToUnsigned(); - if ( v->Type()->IsNetworkOrder() ) + if ( v->GetType()->IsNetworkOrder() ) { - if ( v->Type()->Tag() == TYPE_PORT ) + if ( v->GetType()->Tag() == TYPE_PORT ) u = v->AsPortVal()->Port(); else u = ntohl(uint32_t(u)); @@ -409,8 +409,8 @@ static bool prepare_environment(TableVal* tbl, bool set) const auto& key = idxs->Idx(i); auto val = tbl->Lookup(key.get(), false); - if ( key->Type()->Tag() != TYPE_STRING || - val->Type()->Tag() != TYPE_STRING ) + if ( key->GetType()->Tag() != TYPE_STRING || + val->GetType()->Tag() != TYPE_STRING ) { builtin_error("system_env() needs a table[string] of string"); return false; @@ -488,7 +488,7 @@ function system%(str: string%): int ## .. zeek:see:: system safe_shell_quote piped_exec function system_env%(str: string, env: table_string_of_string%): int %{ - if ( env->Type()->Tag() != TYPE_TABLE ) + if ( env->GetType()->Tag() != TYPE_TABLE ) { builtin_error("system_env() requires a table argument"); return val_mgr->Int(-1); @@ -804,8 +804,8 @@ function sha256_hash_finish%(handle: opaque of sha256%): string ## .. zeek:see::paraglob_match paraglob_equals paraglob_add function paraglob_init%(v: any%) : opaque of paraglob %{ - if ( v->Type()->Tag() != TYPE_VECTOR || - v->Type()->Yield()->Tag() != TYPE_STRING ) + if ( v->GetType()->Tag() != TYPE_VECTOR || + v->GetType()->Yield()->Tag() != TYPE_STRING ) { // reporter->Error will throw an exception. reporter->Error("paraglob requires a vector of strings for initialization."); @@ -1155,7 +1155,7 @@ function unique_id_from%(pool: int, prefix: string%) : string ## v: The set or table function clear_table%(v: any%): any %{ - if ( v->Type()->Tag() == TYPE_TABLE ) + if ( v->GetType()->Tag() == TYPE_TABLE ) v->AsTableVal()->RemoveAll(); else builtin_error("clear_table() requires a table/set argument"); @@ -1172,7 +1172,7 @@ function clear_table%(v: any%): any ## Returns: All the keys of the set or table that cover the subnet searched for. function matching_subnets%(search: subnet, t: any%): subnet_vec %{ - if ( t->Type()->Tag() != TYPE_TABLE || ! t->Type()->AsTableType()->IsSubNetIndex() ) + if ( t->GetType()->Tag() != TYPE_TABLE || ! t->GetType()->AsTableType()->IsSubNetIndex() ) { reporter->Error("matching_subnets needs to be called on a set[subnet]/table[subnet]."); return nullptr; @@ -1191,7 +1191,7 @@ function matching_subnets%(search: subnet, t: any%): subnet_vec ## Returns: A new table that contains all the entries that cover the subnet searched for. function filter_subnet_table%(search: subnet, t: any%): any %{ - if ( t->Type()->Tag() != TYPE_TABLE || ! t->Type()->AsTableType()->IsSubNetIndex() ) + if ( t->GetType()->Tag() != TYPE_TABLE || ! t->GetType()->AsTableType()->IsSubNetIndex() ) { reporter->Error("filter_subnet_table needs to be called on a set[subnet]/table[subnet]."); return nullptr; @@ -1211,7 +1211,7 @@ function filter_subnet_table%(search: subnet, t: any%): any ## Returns: True if the exact subnet is a member, false otherwise. function check_subnet%(search: subnet, t: any%): bool %{ - if ( t->Type()->Tag() != TYPE_TABLE || ! t->Type()->AsTableType()->IsSubNetIndex() ) + if ( t->GetType()->Tag() != TYPE_TABLE || ! t->GetType()->AsTableType()->IsSubNetIndex() ) { reporter->Error("check_subnet needs to be called on a set[subnet]/table[subnet]."); return nullptr; @@ -1262,7 +1262,7 @@ function val_size%(v: any%): count ## Returns: The old size of *aggr*, or 0 if *aggr* is not a :zeek:type:`vector`. function resize%(aggr: any, newsize: count%) : count %{ - if ( aggr->Type()->Tag() != TYPE_VECTOR ) + if ( aggr->GetType()->Tag() != TYPE_VECTOR ) { builtin_error("resize() operates on vectors"); return nullptr; @@ -1281,8 +1281,8 @@ function resize%(aggr: any, newsize: count%) : count ## .. zeek:see:: all_set function any_set%(v: any%) : bool %{ - if ( v->Type()->Tag() != TYPE_VECTOR || - v->Type()->Yield()->Tag() != TYPE_BOOL ) + if ( v->GetType()->Tag() != TYPE_VECTOR || + v->GetType()->Yield()->Tag() != TYPE_BOOL ) { builtin_error("any_set() requires vector of bool"); return val_mgr->False(); @@ -1310,8 +1310,8 @@ function any_set%(v: any%) : bool ## Missing elements count as false. function all_set%(v: any%) : bool %{ - if ( v->Type()->Tag() != TYPE_VECTOR || - v->Type()->Yield()->Tag() != TYPE_BOOL ) + if ( v->GetType()->Tag() != TYPE_VECTOR || + v->GetType()->Yield()->Tag() != TYPE_BOOL ) { builtin_error("all_set() requires vector of bool"); return val_mgr->False(); @@ -1403,13 +1403,13 @@ function sort%(v: any, ...%) : any %{ IntrusivePtr rval{NewRef{}, v}; - if ( v->Type()->Tag() != TYPE_VECTOR ) + if ( v->GetType()->Tag() != TYPE_VECTOR ) { builtin_error("sort() requires vector"); return rval; } - const auto& elt_type = v->Type()->Yield(); + const auto& elt_type = v->GetType()->Yield(); Func* comp = 0; if ( @ARG@.size() > 2 ) @@ -1418,7 +1418,7 @@ function sort%(v: any, ...%) : any if ( @ARG@.size() == 2 ) { Val* comp_val = @ARG@[1].get(); - if ( ! IsFunc(comp_val->Type()->Tag()) ) + if ( ! IsFunc(comp_val->GetType()->Tag()) ) { builtin_error("second argument to sort() needs to be comparison function"); return rval; @@ -1472,13 +1472,13 @@ function order%(v: any, ...%) : index_vec %{ auto result_v = make_intrusive(lookup_type("index_vec")); - if ( v->Type()->Tag() != TYPE_VECTOR ) + if ( v->GetType()->Tag() != TYPE_VECTOR ) { builtin_error("order() requires vector"); return result_v; } - const auto& elt_type = v->Type()->Yield(); + const auto& elt_type = v->GetType()->Yield(); Func* comp = 0; if ( @ARG@.size() > 2 ) @@ -1487,7 +1487,7 @@ function order%(v: any, ...%) : index_vec if ( @ARG@.size() == 2 ) { Val* comp_val = @ARG@[1].get(); - if ( ! IsFunc(comp_val->Type()->Tag()) ) + if ( ! IsFunc(comp_val->GetType()->Tag()) ) { builtin_error("second argument to order() needs to be comparison function"); return IntrusivePtr{NewRef{}, v}; @@ -1603,7 +1603,7 @@ function cat_sep%(sep: string, def: string, ...%): string d.Add(sep->CheckString(), 0); Val* v = @ARG@[i].get(); - if ( v->Type()->Tag() == TYPE_STRING && ! v->AsString()->Len() ) + if ( v->GetType()->Tag() == TYPE_STRING && ! v->AsString()->Len() ) v = def; v->Describe(&d); @@ -1842,7 +1842,7 @@ function record_type_to_vector%(rt: string%): string_vec function type_name%(t: any%): string %{ ODesc d; - t->Type()->Describe(&d); + t->GetType()->Describe(&d); BroString* s = new BroString(1, d.TakeBytes(), d.Len()); s->SetUseFreeToDelete(true); @@ -1992,7 +1992,7 @@ function lookup_ID%(id: string%) : any ## Returns: A table that describes the fields of a record. function record_fields%(rec: any%): record_field_table %{ - if ( rec->Type()->Tag() == TYPE_STRING ) + if ( rec->GetType()->Tag() == TYPE_STRING ) { auto id = global_scope()->Lookup(rec->AsStringVal()->ToStdString()); @@ -2264,7 +2264,7 @@ function counts_to_addr%(v: index_vec%): addr ## Returns: The :zeek:type:`int` value that corresponds to the :zeek:type:`enum`. function enum_to_int%(e: any%): int %{ - if ( e->Type()->Tag() != TYPE_ENUM ) + if ( e->GetType()->Tag() != TYPE_ENUM ) { builtin_error("enum_to_int() requires enum value"); return val_mgr->Int(-1); From e3f7b388908e839c7690c649b973b45bc88edcb2 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 11 May 2020 13:09:01 -0700 Subject: [PATCH 040/151] Deprecate Expr::Type(), replace with GetType() --- src/Attr.cc | 18 +-- src/Expr.cc | 402 +++++++++++++++++++++++++--------------------------- src/Expr.h | 11 +- src/Func.cc | 2 +- src/Stmt.cc | 36 ++--- src/Type.cc | 16 +-- src/Val.cc | 10 +- src/parse.y | 6 +- 8 files changed, 248 insertions(+), 253 deletions(-) diff --git a/src/Attr.cc b/src/Attr.cc index 747994a396..d26fa443b5 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -94,10 +94,10 @@ void Attr::DescribeReST(ODesc* d, bool shorten) const d->Add("`"); } - else if ( expr->Type()->Tag() == TYPE_FUNC ) + else if ( expr->GetType()->Tag() == TYPE_FUNC ) { d->Add(":zeek:type:`"); - d->Add(expr->Type()->AsFuncType()->FlavorString()); + d->Add(expr->GetType()->AsFuncType()->FlavorString()); d->Add("`"); } @@ -262,7 +262,7 @@ void Attributes::CheckAttr(Attr* a) { bool is_add = a->Tag() == ATTR_ADD_FUNC; - BroType* at = a->AttrExpr()->Type(); + const auto& at = a->AttrExpr()->GetType(); if ( at->Tag() != TYPE_FUNC ) { a->AttrExpr()->Error( @@ -294,7 +294,7 @@ void Attributes::CheckAttr(Attr* a) break; } - BroType* atype = a->AttrExpr()->Type(); + BroType* atype = a->AttrExpr()->GetType().get(); if ( type->Tag() != TYPE_TABLE || (type->IsSet() && ! in_record) ) { @@ -448,10 +448,10 @@ void Attributes::CheckAttr(Attr* a) const Expr* expire_func = a->AttrExpr(); - if ( expire_func->Type()->Tag() != TYPE_FUNC ) + if ( expire_func->GetType()->Tag() != TYPE_FUNC ) Error("&expire_func attribute is not a function"); - const FuncType* e_ft = expire_func->Type()->AsFuncType(); + const FuncType* e_ft = expire_func->GetType()->AsFuncType(); if ( e_ft->Yield()->Tag() != TYPE_INTERVAL ) { @@ -495,10 +495,10 @@ void Attributes::CheckAttr(Attr* a) const Expr* change_func = a->AttrExpr(); - if ( change_func->Type()->Tag() != TYPE_FUNC || change_func->Type()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) + if ( change_func->GetType()->Tag() != TYPE_FUNC || change_func->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) Error("&on_change attribute is not a function"); - const FuncType* c_ft = change_func->Type()->AsFuncType(); + const FuncType* c_ft = change_func->GetType()->AsFuncType(); if ( c_ft->Yield()->Tag() != TYPE_VOID ) { @@ -588,7 +588,7 @@ void Attributes::CheckAttr(Attr* a) break; } - BroType* atype = a->AttrExpr()->Type(); + const auto& atype = a->AttrExpr()->GetType(); if ( atype->Tag() != TYPE_STRING ) { Error("type column needs to have a string argument"); diff --git a/src/Expr.cc b/src/Expr.cc index 85404a7991..4b794d606e 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -357,10 +357,10 @@ IntrusivePtr UnaryExpr::Eval(Frame* f) const VectorVal* v_op = v->AsVectorVal(); IntrusivePtr out_t; - if ( Type()->Tag() == TYPE_ANY ) + if ( GetType()->Tag() == TYPE_ANY ) out_t = v->GetType(); else - out_t = {NewRef{}, Type()->AsVectorType()}; + out_t = GetType(); auto result = make_intrusive(std::move(out_t)); @@ -421,7 +421,7 @@ void UnaryExpr::ExprDescribe(ODesc* d) const if ( d->IsReadable() && is_coerce ) { d->Add(" to "); - Type()->Describe(d); + GetType()->Describe(d); d->Add(")"); } } @@ -455,7 +455,7 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const return nullptr; } - auto v_result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + auto v_result = make_intrusive(GetType()); for ( unsigned int i = 0; i < v_op1->Size(); ++i ) { @@ -469,10 +469,10 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const return v_result; } - if ( IsVector(Type()->Tag()) && (is_vec1 || is_vec2) ) + if ( IsVector(GetType()->Tag()) && (is_vec1 || is_vec2) ) { // fold vector against scalar VectorVal* vv = (is_vec1 ? v1 : v2)->AsVectorVal(); - auto v_result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + auto v_result = make_intrusive(GetType()); for ( unsigned int i = 0; i < vv->Size(); ++i ) { @@ -674,10 +674,7 @@ IntrusivePtr BinaryExpr::Fold(Val* v1, Val* v2) const BadTag("BinaryExpr::Fold", expr_name(tag)); } - BroType* ret_type = Type(); - - if ( IsVector(ret_type->Tag()) ) - ret_type = ret_type->Yield().get(); + const auto& ret_type = IsVector(GetType()->Tag()) ? GetType()->Yield() : GetType(); if ( ret_type->Tag() == TYPE_INTERVAL ) return make_intrusive(d3, 1.0); @@ -857,16 +854,16 @@ void BinaryExpr::SwapOps() void BinaryExpr::PromoteOps(TypeTag t) { - TypeTag bt1 = op1->Type()->Tag(); - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); bool is_vec1 = IsVector(bt1); bool is_vec2 = IsVector(bt2); if ( is_vec1 ) - bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); + bt1 = op1->GetType()->AsVectorType()->Yield()->Tag(); if ( is_vec2 ) - bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); + bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); if ( (is_vec1 || is_vec2) && ! (is_vec1 && is_vec2) ) reporter->Warning("mixing vector and scalar operands is deprecated"); @@ -893,8 +890,7 @@ CloneExpr::CloneExpr(IntrusivePtr arg_op) if ( IsError() ) return; - BroType* t = op->Type(); - SetType({NewRef{}, t}); + SetType(op->GetType()); } IntrusivePtr CloneExpr::Eval(Frame* f) const @@ -919,7 +915,7 @@ IncrExpr::IncrExpr(BroExprTag arg_tag, IntrusivePtr arg_op) if ( IsError() ) return; - BroType* t = op->Type(); + const auto& t = op->GetType(); if ( IsVector(t->Tag()) ) { @@ -928,7 +924,7 @@ IncrExpr::IncrExpr(BroExprTag arg_tag, IntrusivePtr arg_op) else { reporter->Warning("increment/decrement operations for vectors deprecated"); - SetType({NewRef{}, t}); + SetType(t); } } else @@ -936,7 +932,7 @@ IncrExpr::IncrExpr(BroExprTag arg_tag, IntrusivePtr arg_op) if ( ! IsIntegral(t->Tag()) ) ExprError("requires an integral operand"); else - SetType({NewRef{}, t}); + SetType(t); } } @@ -955,9 +951,7 @@ IntrusivePtr IncrExpr::DoSingleEval(Frame* f, Val* v) const RuntimeError("count underflow"); } - BroType* ret_type = Type(); - if ( IsVector(ret_type->Tag()) ) - ret_type = Type()->Yield().get(); + const auto& ret_type = IsVector(GetType()->Tag()) ? GetType()->Yield() : GetType(); if ( ret_type->Tag() == TYPE_INT ) return val_mgr->Int(k); @@ -1009,7 +1003,7 @@ ComplementExpr::ComplementExpr(IntrusivePtr arg_op) if ( IsError() ) return; - BroType* t = op->Type(); + const auto& t = op->GetType(); TypeTag bt = t->Tag(); if ( bt != TYPE_COUNT ) @@ -1029,7 +1023,7 @@ NotExpr::NotExpr(IntrusivePtr arg_op) if ( IsError() ) return; - TypeTag bt = op->Type()->Tag(); + TypeTag bt = op->GetType()->Tag(); if ( ! IsIntegral(bt) && bt != TYPE_BOOL ) ExprError("requires an integral or boolean operand"); @@ -1048,10 +1042,7 @@ PosExpr::PosExpr(IntrusivePtr arg_op) if ( IsError() ) return; - BroType* t = op->Type(); - - if ( IsVector(t->Tag()) ) - t = t->AsVectorType()->Yield().get(); + const auto& t = IsVector(op->GetType()->Tag()) ? op->GetType()->Yield() : op->GetType(); TypeTag bt = t->Tag(); IntrusivePtr base_result_type; @@ -1060,7 +1051,7 @@ PosExpr::PosExpr(IntrusivePtr arg_op) // Promote count and counter to int. base_result_type = base_type(TYPE_INT); else if ( bt == TYPE_INTERVAL || bt == TYPE_DOUBLE ) - base_result_type = {NewRef{}, t}; + base_result_type = t; else ExprError("requires an integral or double operand"); @@ -1086,10 +1077,7 @@ NegExpr::NegExpr(IntrusivePtr arg_op) if ( IsError() ) return; - BroType* t = op->Type(); - - if ( IsVector(t->Tag()) ) - t = t->AsVectorType()->Yield().get(); + const auto& t = IsVector(op->GetType()->Tag()) ? op->GetType()->Yield() : op->GetType(); TypeTag bt = t->Tag(); IntrusivePtr base_result_type; @@ -1098,7 +1086,7 @@ NegExpr::NegExpr(IntrusivePtr arg_op) // Promote count and counter to int. base_result_type = base_type(TYPE_INT); else if ( bt == TYPE_INTERVAL || bt == TYPE_DOUBLE ) - base_result_type = {NewRef{}, t}; + base_result_type = t; else ExprError("requires an integral or double operand"); @@ -1124,7 +1112,7 @@ SizeExpr::SizeExpr(IntrusivePtr arg_op) if ( IsError() ) return; - if ( op->Type()->InternalType() == TYPE_INTERNAL_DOUBLE ) + if ( op->GetType()->InternalType() == TYPE_INTERNAL_DOUBLE ) SetType(base_type(TYPE_DOUBLE)); else SetType(base_type(TYPE_COUNT)); @@ -1151,15 +1139,15 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( IsError() ) return; - TypeTag bt1 = op1->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); + bt1 = op1->GetType()->AsVectorType()->Yield()->Tag(); - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); + bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); IntrusivePtr base_result_type; @@ -1186,8 +1174,8 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) void AddExpr::Canonicize() { if ( expr_greater(op2.get(), op1.get()) || - (op1->Type()->Tag() == TYPE_INTERVAL && - op2->Type()->Tag() == TYPE_TIME) || + (op1->GetType()->Tag() == TYPE_INTERVAL && + op2->GetType()->Tag() == TYPE_TIME) || (op2->IsConst() && ! is_vector(op2->ExprVal()) && ! op1->IsConst())) SwapOps(); } @@ -1200,8 +1188,8 @@ AddToExpr::AddToExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( IsError() ) return; - TypeTag bt1 = op1->Type()->Tag(); - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); if ( BothArithmetic(bt1, bt2) ) PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); @@ -1210,7 +1198,7 @@ AddToExpr::AddToExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) else if ( IsVector(bt1) ) { - bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); + bt1 = op1->GetType()->AsVectorType()->Yield()->Tag(); if ( IsArithmetic(bt1) ) { @@ -1219,7 +1207,7 @@ AddToExpr::AddToExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( bt2 != bt1 ) op2 = make_intrusive(std::move(op2), bt1); - SetType({NewRef{}, op1->Type()}); + SetType(op1->GetType()); } else @@ -1231,7 +1219,7 @@ AddToExpr::AddToExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) type_name(bt1), type_name(bt2))); else - SetType({NewRef{}, op1->Type()}); + SetType(op1->GetType()); } else @@ -1275,8 +1263,8 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( IsError() ) return; - const BroType* t1 = op1->Type(); - const BroType* t2 = op2->Type(); + const auto& t1 = op1->GetType(); + const auto& t2 = op2->GetType(); TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) @@ -1296,8 +1284,8 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) else if ( t1->IsSet() && t2->IsSet() ) { - if ( same_type(t1, t2) ) - SetType({NewRef{}, op1->Type()}); + if ( same_type(t1.get(), t2.get()) ) + SetType(op1->GetType()); else ExprError("incompatible \"set\" operands"); } @@ -1324,8 +1312,8 @@ RemoveFromExpr::RemoveFromExpr(IntrusivePtr arg_op1, if ( IsError() ) return; - TypeTag bt1 = op1->Type()->Tag(); - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); if ( BothArithmetic(bt1, bt2) ) PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); @@ -1364,15 +1352,15 @@ TimesExpr::TimesExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) Canonicize(); - TypeTag bt1 = op1->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); + bt1 = op1->GetType()->AsVectorType()->Yield()->Tag(); - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); + bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) { @@ -1389,7 +1377,7 @@ TimesExpr::TimesExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) void TimesExpr::Canonicize() { - if ( expr_greater(op2.get(), op1.get()) || op2->Type()->Tag() == TYPE_INTERVAL || + if ( expr_greater(op2.get(), op1.get()) || op2->GetType()->Tag() == TYPE_INTERVAL || (op2->IsConst() && ! is_vector(op2->ExprVal()) && ! op1->IsConst()) ) SwapOps(); } @@ -1401,15 +1389,15 @@ DivideExpr::DivideExpr(IntrusivePtr arg_op1, if ( IsError() ) return; - TypeTag bt1 = op1->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); + bt1 = op1->GetType()->AsVectorType()->Yield()->Tag(); - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); + bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) { @@ -1468,15 +1456,15 @@ ModExpr::ModExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( IsError() ) return; - TypeTag bt1 = op1->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); + bt1 = op1->GetType()->AsVectorType()->Yield()->Tag(); - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); + bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); if ( BothIntegral(bt1, bt2) ) PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); @@ -1491,15 +1479,15 @@ BoolExpr::BoolExpr(BroExprTag arg_tag, if ( IsError() ) return; - TypeTag bt1 = op1->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); + bt1 = op1->GetType()->AsVectorType()->Yield()->Tag(); - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); if ( IsVector(bt2) ) - bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); + bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); if ( BothBool(bt1, bt2) ) { @@ -1584,7 +1572,7 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const if ( scalar_v->IsZero() == is_and ) { - result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + result = make_intrusive(GetType()); result->Resize(vector_v->Size()); result->AssignRepeat(0, result->Size(), scalar_v.get()); } @@ -1609,7 +1597,7 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const return nullptr; } - auto result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + auto result = make_intrusive(GetType()); result->Resize(vec_v1->Size()); for ( unsigned int i = 0; i < vec_v1->Size(); ++i ) @@ -1638,8 +1626,8 @@ BitExpr::BitExpr(BroExprTag arg_tag, if ( IsError() ) return; - const BroType* t1 = op1->Type(); - const BroType* t2 = op2->Type(); + const auto& t1 = op1->GetType(); + const auto& t2 = op2->GetType(); TypeTag bt1 = t1->Tag(); @@ -1674,8 +1662,8 @@ BitExpr::BitExpr(BroExprTag arg_tag, else if ( t1->IsSet() && t2->IsSet() ) { - if ( same_type(t1, t2) ) - SetType({NewRef{}, op1->Type()}); + if ( same_type(t1.get(), t2.get()) ) + SetType(op1->GetType()); else ExprError("incompatible \"set\" operands"); } @@ -1693,8 +1681,8 @@ EqExpr::EqExpr(BroExprTag arg_tag, Canonicize(); - const BroType* t1 = op1->Type(); - const BroType* t2 = op2->Type(); + const auto& t1 = op1->GetType(); + const auto& t2 = op2->GetType(); TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) @@ -1732,14 +1720,14 @@ EqExpr::EqExpr(BroExprTag arg_tag, break; case TYPE_ENUM: - if ( ! same_type(t1, t2) ) + if ( ! same_type(t1.get(), t2.get()) ) ExprError("illegal enum comparison"); break; case TYPE_TABLE: if ( t1->IsSet() && t2->IsSet() ) { - if ( ! same_type(t1, t2) ) + if ( ! same_type(t1.get(), t2.get()) ) ExprError("incompatible sets in comparison"); break; } @@ -1760,10 +1748,10 @@ EqExpr::EqExpr(BroExprTag arg_tag, void EqExpr::Canonicize() { - if ( op2->Type()->Tag() == TYPE_PATTERN ) + if ( op2->GetType()->Tag() == TYPE_PATTERN ) SwapOps(); - else if ( op1->Type()->Tag() == TYPE_PATTERN ) + else if ( op1->GetType()->Tag() == TYPE_PATTERN ) ; else if ( expr_greater(op2.get(), op1.get()) ) @@ -1772,7 +1760,7 @@ void EqExpr::Canonicize() IntrusivePtr EqExpr::Fold(Val* v1, Val* v2) const { - if ( op1->Type()->Tag() == TYPE_PATTERN ) + if ( op1->GetType()->Tag() == TYPE_PATTERN ) { RE_Matcher* re = v1->AsPattern(); const BroString* s = v2->AsString(); @@ -1795,8 +1783,8 @@ RelExpr::RelExpr(BroExprTag arg_tag, Canonicize(); - const BroType* t1 = op1->Type(); - const BroType* t2 = op2->Type(); + const auto& t1 = op1->GetType(); + const auto& t2 = op2->GetType(); TypeTag bt1 = t1->Tag(); if ( IsVector(bt1) ) @@ -1816,7 +1804,7 @@ RelExpr::RelExpr(BroExprTag arg_tag, else if ( t1->IsSet() && t2->IsSet() ) { - if ( ! same_type(t1, t2) ) + if ( ! same_type(t1.get(), t2.get()) ) ExprError("incompatible sets in comparison"); } @@ -1849,10 +1837,10 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, : Expr(EXPR_COND), op1(std::move(arg_op1)), op2(std::move(arg_op2)), op3(std::move(arg_op3)) { - TypeTag bt1 = op1->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); if ( IsVector(bt1) ) - bt1 = op1->Type()->AsVectorType()->Yield()->Tag(); + bt1 = op1->GetType()->AsVectorType()->Yield()->Tag(); if ( op1->IsError() || op2->IsError() || op3->IsError() ) SetError(); @@ -1862,15 +1850,15 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, else { - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); if ( is_vector(op2.get()) ) - bt2 = op2->Type()->AsVectorType()->Yield()->Tag(); + bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); - TypeTag bt3 = op3->Type()->Tag(); + TypeTag bt3 = op3->GetType()->Tag(); if ( IsVector(bt3) ) - bt3 = op3->Type()->AsVectorType()->Yield()->Tag(); + bt3 = op3->GetType()->AsVectorType()->Yield()->Tag(); if ( is_vector(op1.get()) && ! (is_vector(op2.get()) && is_vector(op3.get())) ) { @@ -1898,10 +1886,10 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, else { if ( IsRecord(bt2) && IsRecord(bt3) && - ! same_type(op2->Type(), op3->Type()) ) + ! same_type(op2->GetType().get(), op3->GetType().get()) ) ExprError("operands must be of the same type"); else - SetType({NewRef{}, op2->Type()}); + SetType(op2->GetType()); } } } @@ -1941,7 +1929,7 @@ IntrusivePtr CondExpr::Eval(Frame* f) const return nullptr; } - auto result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + auto result = make_intrusive(GetType()); result->Resize(cond->Size()); for ( unsigned int i = 0; i < cond->Size(); ++i ) @@ -1998,10 +1986,10 @@ RefExpr::RefExpr(IntrusivePtr arg_op) if ( IsError() ) return; - if ( ! ::is_assignable(op->Type()) ) + if ( ! ::is_assignable(op->GetType().get()) ) ExprError("illegal assignment target"); else - SetType({NewRef{}, op->Type()}); + SetType(op->GetType()); } IntrusivePtr RefExpr::MakeLvalue() @@ -2030,7 +2018,7 @@ AssignExpr::AssignExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, if ( arg_val ) SetType(arg_val->GetType()); else - SetType({NewRef{}, op1->Type()}); + SetType(op1->GetType()); if ( is_init ) { @@ -2050,8 +2038,8 @@ AssignExpr::AssignExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, bool AssignExpr::TypeCheck(attr_list* attrs) { - TypeTag bt1 = op1->Type()->Tag(); - TypeTag bt2 = op2->Type()->Tag(); + TypeTag bt1 = op1->GetType()->Tag(); + TypeTag bt2 = op2->GetType()->Tag(); if ( bt1 == TYPE_LIST && bt2 == TYPE_ANY ) // This is ok because we cannot explicitly declare lists on @@ -2075,10 +2063,9 @@ bool AssignExpr::TypeCheck(attr_list* attrs) } if ( bt1 == TYPE_TABLE && bt2 == bt1 && - op2->Type()->AsTableType()->IsUnspecifiedTable() ) + op2->GetType()->AsTableType()->IsUnspecifiedTable() ) { - op2 = make_intrusive(std::move(op2), - IntrusivePtr{NewRef{}, op1->Type()->AsTableType()}); + op2 = make_intrusive(std::move(op2), op1->GetType()); return true; } @@ -2094,16 +2081,16 @@ bool AssignExpr::TypeCheck(attr_list* attrs) bool empty_list_assignment = (op2->AsListExpr()->Exprs().empty()); - if ( op1->Type()->IsSet() ) + if ( op1->GetType()->IsSet() ) op2 = make_intrusive( IntrusivePtr{NewRef{}, op2->AsListExpr()}, attr_copy); else op2 = make_intrusive( IntrusivePtr{NewRef{}, op2->AsListExpr()}, attr_copy); - if ( ! empty_list_assignment && ! same_type(op1->Type(), op2->Type()) ) + if ( ! empty_list_assignment && ! same_type(op1->GetType().get(), op2->GetType().get()) ) { - if ( op1->Type()->IsSet() ) + if ( op1->GetType()->IsSet() ) ExprError("set type mismatch in assignment"); else ExprError("table type mismatch in assignment"); @@ -2116,10 +2103,9 @@ bool AssignExpr::TypeCheck(attr_list* attrs) if ( bt1 == TYPE_VECTOR ) { - if ( bt2 == bt1 && op2->Type()->AsVectorType()->IsUnspecifiedVector() ) + if ( bt2 == bt1 && op2->GetType()->AsVectorType()->IsUnspecifiedVector() ) { - op2 = make_intrusive(std::move(op2), - IntrusivePtr{NewRef{}, op1->Type()->AsVectorType()}); + op2 = make_intrusive(std::move(op2), op1->GetType()); return true; } @@ -2127,18 +2113,18 @@ bool AssignExpr::TypeCheck(attr_list* attrs) { op2 = make_intrusive( IntrusivePtr{AdoptRef{}, op2.release()->AsListExpr()}, - IntrusivePtr{NewRef{}, op1->Type()}); + op1->GetType()); return true; } } - if ( op1->Type()->Tag() == TYPE_RECORD && - op2->Type()->Tag() == TYPE_RECORD ) + if ( op1->GetType()->Tag() == TYPE_RECORD && + op2->GetType()->Tag() == TYPE_RECORD ) { - if ( same_type(op1->Type(), op2->Type()) ) + if ( same_type(op1->GetType().get(), op2->GetType().get()) ) { - RecordType* rt1 = op1->Type()->AsRecordType(); - RecordType* rt2 = op2->Type()->AsRecordType(); + RecordType* rt1 = op1->GetType()->AsRecordType(); + RecordType* rt2 = op2->GetType()->AsRecordType(); // Make sure the attributes match as well. for ( int i = 0; i < rt1->NumFields(); ++i ) @@ -2153,12 +2139,11 @@ bool AssignExpr::TypeCheck(attr_list* attrs) } // Need to coerce. - op2 = make_intrusive(std::move(op2), - IntrusivePtr{NewRef{}, op1->Type()->AsRecordType()}); + op2 = make_intrusive(std::move(op2), op1->GetType()); return true; } - if ( ! same_type(op1->Type(), op2->Type()) ) + if ( ! same_type(op1->GetType().get(), op2->GetType().get()) ) { if ( bt1 == TYPE_TABLE && bt2 == TYPE_TABLE ) { @@ -2195,7 +2180,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs) int errors_before = reporter->Errors(); op2 = make_intrusive( IntrusivePtr{NewRef{}, ctor_list}, attr_copy, - IntrusivePtr{NewRef{}, op1->Type()}); + op1->GetType()); int errors_after = reporter->Errors(); if ( errors_after > errors_before ) @@ -2234,7 +2219,7 @@ bool AssignExpr::TypeCheckArithmetics(TypeTag bt1, TypeTag bt2) { Warn("dangerous assignment of double to integral"); op2 = make_intrusive(std::move(op2), bt1); - bt2 = op2->Type()->Tag(); + bt2 = op2->GetType()->Tag(); } if ( bt1 == TYPE_INT ) @@ -2285,12 +2270,12 @@ IntrusivePtr AssignExpr::InitType() const return nullptr; } - BroType* tl = op1->Type(); + const auto& tl = op1->GetType(); if ( tl->Tag() != TYPE_LIST ) Internal("inconsistent list expr in AssignExpr::InitType"); return make_intrusive(IntrusivePtr{NewRef{}, tl->AsTypeList()}, - IntrusivePtr{NewRef{}, op2->Type()}); + op2->GetType()); } void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const @@ -2427,7 +2412,7 @@ bool AssignExpr::IsRecordElement(TypeDecl* td) const if ( td ) { const NameExpr* n = (const NameExpr*) op1.get(); - td->type = {NewRef{}, op2->Type()}; + td->type = op2->GetType(); td->id = copy_string(n->Id()->Name()); } @@ -2472,11 +2457,11 @@ IndexExpr::IndexExpr(IntrusivePtr arg_op1, if ( is_slice ) { - if ( ! IsString(op1->Type()->Tag()) && ! IsVector(op1->Type()->Tag()) ) + if ( ! IsString(op1->GetType()->Tag()) && ! IsVector(op1->GetType()->Tag()) ) ExprError("slice notation indexing only supported for strings and vectors currently"); } - else if ( IsString(op1->Type()->Tag()) ) + else if ( IsString(op1->GetType()->Tag()) ) { if ( op2->AsListExpr()->Exprs().length() != 1 ) ExprError("invalid string index expression"); @@ -2485,19 +2470,19 @@ IndexExpr::IndexExpr(IntrusivePtr arg_op1, if ( IsError() ) return; - int match_type = op1->Type()->MatchesIndex(op2->AsListExpr()); + int match_type = op1->GetType()->MatchesIndex(op2->AsListExpr()); if ( match_type == DOES_NOT_MATCH_INDEX ) { std::string error_msg = fmt("expression with type '%s' is not a type that can be indexed", - type_name(op1->Type()->Tag())); + type_name(op1->GetType()->Tag())); SetError(error_msg.data()); } - else if ( ! op1->Type()->Yield() ) + else if ( ! op1->GetType()->Yield() ) { - if ( IsString(op1->Type()->Tag()) && match_type == MATCHES_INDEX_SCALAR ) + if ( IsString(op1->GetType()->Tag()) && match_type == MATCHES_INDEX_SCALAR ) SetType(base_type(TYPE_STRING)); else // It's a set - so indexing it yields void. We don't @@ -2508,10 +2493,10 @@ IndexExpr::IndexExpr(IntrusivePtr arg_op1, } else if ( match_type == MATCHES_INDEX_SCALAR ) - SetType(op1->Type()->Yield()); + SetType(op1->GetType()->Yield()); else if ( match_type == MATCHES_INDEX_VECTOR ) - SetType(make_intrusive(op1->Type()->Yield())); + SetType(make_intrusive(op1->GetType()->Yield())); else ExprError("Unknown MatchesIndex() return value"); @@ -2523,7 +2508,7 @@ bool IndexExpr::CanAdd() const return true; // avoid cascading the error report // "add" only allowed if our type is "set". - return op1->Type()->IsSet(); + return op1->GetType()->IsSet(); } bool IndexExpr::CanDel() const @@ -2531,7 +2516,7 @@ bool IndexExpr::CanDel() const if ( IsError() ) return true; // avoid cascading the error report - return op1->Type()->Tag() == TYPE_TABLE; + return op1->GetType()->Tag() == TYPE_TABLE; } void IndexExpr::Add(Frame* f) @@ -2572,7 +2557,7 @@ void IndexExpr::Delete(Frame* f) IntrusivePtr IndexExpr::MakeLvalue() { - if ( IsString(op1->Type()->Tag()) ) + if ( IsString(op1->GetType()->Tag()) ) ExprError("cannot assign to string index expression"); return make_intrusive(IntrusivePtr{NewRef{}, this}); @@ -2596,7 +2581,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const { VectorVal* v_v1 = v1->AsVectorVal(); VectorVal* v_v2 = indv->AsVectorVal(); - auto v_result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + auto v_result = make_intrusive(GetType()); // Booleans select each element (or not). if ( IsBool(v_v2->GetType()->Yield()->Tag()) ) @@ -2860,11 +2845,11 @@ FieldExpr::FieldExpr(IntrusivePtr arg_op, const char* arg_field_name) if ( IsError() ) return; - if ( ! IsRecord(op->Type()->Tag()) ) + if ( ! IsRecord(op->GetType()->Tag()) ) ExprError("not a record"); else { - RecordType* rt = op->Type()->AsRecordType(); + RecordType* rt = op->GetType()->AsRecordType(); field = rt->FieldOffset(field_name); if ( field < 0 ) @@ -2952,11 +2937,11 @@ HasFieldExpr::HasFieldExpr(IntrusivePtr arg_op, if ( IsError() ) return; - if ( ! IsRecord(op->Type()->Tag()) ) + if ( ! IsRecord(op->GetType()->Tag()) ) ExprError("not a record"); else { - RecordType* rt = op->Type()->AsRecordType(); + RecordType* rt = op->GetType()->AsRecordType(); field = rt->FieldOffset(field_name); if ( field < 0 ) @@ -3016,9 +3001,9 @@ RecordConstructorExpr::RecordConstructorExpr(IntrusivePtr constructor_ } FieldAssignExpr* field = (FieldAssignExpr*) e; - IntrusivePtr field_type{NewRef{}, field->Type()}; + const auto& field_type = field->GetType(); char* field_name = copy_string(field->FieldName()); - record_types->push_back(new TypeDecl(std::move(field_type), field_name)); + record_types->push_back(new TypeDecl(field_type, field_name)); } SetType(make_intrusive(record_types)); @@ -3153,7 +3138,7 @@ IntrusivePtr TableConstructorExpr::Eval(Frame* f) const if ( IsError() ) return nullptr; - auto aggr = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsTableType()}, + auto aggr = make_intrusive(GetType(), IntrusivePtr{NewRef{}, attrs}); const expr_list& exprs = op->AsListExpr()->Exprs(); @@ -3170,10 +3155,11 @@ IntrusivePtr TableConstructorExpr::InitVal(const BroType* t, IntrusivePtrAsTableType(); + auto tt = GetType(); + auto tval = aggr ? IntrusivePtr{AdoptRef{}, aggr.release()->AsTableVal()} : - make_intrusive(IntrusivePtr{NewRef{}, tt}, IntrusivePtr{NewRef{}, attrs}); + make_intrusive(std::move(tt), IntrusivePtr{NewRef{}, attrs}); const expr_list& exprs = op->AsListExpr()->Exprs(); for ( const auto& expr : exprs ) @@ -3281,10 +3267,10 @@ IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtrAsTableType()->Indices(); - TableType* tt = Type()->AsTableType(); + auto tt = GetType(); auto tval = aggr ? IntrusivePtr{AdoptRef{}, aggr.release()->AsTableVal()} : - make_intrusive(IntrusivePtr{NewRef{}, tt}, IntrusivePtr{NewRef{}, attrs}); + make_intrusive(std::move(tt), IntrusivePtr{NewRef{}, attrs}); const expr_list& exprs = op->AsListExpr()->Exprs(); for ( const auto& e : exprs ) @@ -3356,7 +3342,7 @@ IntrusivePtr VectorConstructorExpr::Eval(Frame* f) const if ( IsError() ) return nullptr; - auto vec = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + auto vec = make_intrusive(GetType()); const expr_list& exprs = op->AsListExpr()->Exprs(); loop_over_list(exprs, i) @@ -3378,10 +3364,10 @@ IntrusivePtr VectorConstructorExpr::InitVal(const BroType* t, IntrusivePtr< if ( IsError() ) return nullptr; - VectorType* vt = Type()->AsVectorType(); + auto vt = GetType(); auto vec = aggr ? IntrusivePtr{AdoptRef{}, aggr.release()->AsVectorVal()} : - make_intrusive(IntrusivePtr{NewRef{}, vt}); + make_intrusive(std::move(vt)); const expr_list& exprs = op->AsListExpr()->Exprs(); loop_over_list(exprs, i) @@ -3410,7 +3396,7 @@ FieldAssignExpr::FieldAssignExpr(const char* arg_field_name, IntrusivePtr value) : UnaryExpr(EXPR_FIELD_ASSIGN, std::move(value)), field_name(arg_field_name) { - SetType({NewRef{}, op->Type()}); + SetType(op->GetType()); } void FieldAssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) @@ -3438,7 +3424,7 @@ bool FieldAssignExpr::IsRecordElement(TypeDecl* td) const { if ( td ) { - td->type = {NewRef{}, op->Type()}; + td->type = op->GetType(); td->id = copy_string(field_name.c_str()); } @@ -3459,13 +3445,13 @@ ArithCoerceExpr::ArithCoerceExpr(IntrusivePtr arg_op, TypeTag t) if ( IsError() ) return; - TypeTag bt = op->Type()->Tag(); + TypeTag bt = op->GetType()->Tag(); TypeTag vbt = bt; if ( IsVector(bt) ) { SetType(make_intrusive(base_type(t))); - vbt = op->Type()->AsVectorType()->Yield()->Tag(); + vbt = op->GetType()->AsVectorType()->Yield()->Tag(); } else SetType(base_type(t)); @@ -3510,15 +3496,15 @@ IntrusivePtr ArithCoerceExpr::Fold(Val* v) const // invocation is being done per-element rather than on // the whole vector. Correct the type tag if necessary. if ( type->Tag() == TYPE_VECTOR ) - t = Type()->AsVectorType()->Yield()->InternalType(); + t = GetType()->AsVectorType()->Yield()->InternalType(); return FoldSingleVal(v, t); } - t = Type()->AsVectorType()->Yield()->InternalType(); + t = GetType()->AsVectorType()->Yield()->InternalType(); VectorVal* vv = v->AsVectorVal(); - auto result = make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + auto result = make_intrusive(GetType()); for ( unsigned int i = 0; i < vv->Size(); ++i ) { @@ -3541,16 +3527,16 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, SetType(std::move(r)); - if ( Type()->Tag() != TYPE_RECORD ) + if ( GetType()->Tag() != TYPE_RECORD ) ExprError("coercion to non-record"); - else if ( op->Type()->Tag() != TYPE_RECORD ) + else if ( op->GetType()->Tag() != TYPE_RECORD ) ExprError("coercion of non-record to record"); else { RecordType* t_r = type->AsRecordType(); - RecordType* sub_r = op->Type()->AsRecordType(); + RecordType* sub_r = op->GetType()->AsRecordType(); map_size = t_r->NumFields(); map = new int[map_size]; @@ -3659,7 +3645,7 @@ IntrusivePtr RecordCoerceExpr::InitVal(const BroType* t, IntrusivePtr IntrusivePtr RecordCoerceExpr::Fold(Val* v) const { - auto val = make_intrusive(Type()->AsRecordType()); + auto val = make_intrusive(GetType()->AsRecordType()); RecordType* val_type = val->GetType()->AsRecordType(); RecordVal* rv = v->AsRecordVal(); @@ -3679,7 +3665,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const rhs = def->AttrExpr()->Eval(nullptr); } - assert(rhs || Type()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_OPTIONAL)); + assert(rhs || GetType()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_OPTIONAL)); if ( ! rhs ) { @@ -3711,11 +3697,11 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const } else { - if ( const Attr* def = Type()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_DEFAULT) ) + if ( const Attr* def = GetType()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_DEFAULT) ) { auto def_val = def->AttrExpr()->Eval(nullptr); const auto& def_type = def_val->GetType(); - const auto& field_type = Type()->AsRecordType()->GetFieldType(i); + const auto& field_type = GetType()->AsRecordType()->GetFieldType(i); if ( def_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && @@ -3747,10 +3733,10 @@ TableCoerceExpr::TableCoerceExpr(IntrusivePtr arg_op, SetType(std::move(r)); - if ( Type()->Tag() != TYPE_TABLE ) + if ( GetType()->Tag() != TYPE_TABLE ) ExprError("coercion to non-table"); - else if ( op->Type()->Tag() != TYPE_TABLE ) + else if ( op->GetType()->Tag() != TYPE_TABLE ) ExprError("coercion of non-table/set to table/set"); } @@ -3766,7 +3752,7 @@ IntrusivePtr TableCoerceExpr::Fold(Val* v) const if ( tv->Size() > 0 ) RuntimeErrorWithCallStack("coercion of non-empty table/set"); - return make_intrusive(IntrusivePtr{NewRef{}, Type()->AsTableType()}, + return make_intrusive(GetType(), IntrusivePtr{NewRef{}, tv->Attrs()}); } @@ -3779,10 +3765,10 @@ VectorCoerceExpr::VectorCoerceExpr(IntrusivePtr arg_op, SetType(std::move(v)); - if ( Type()->Tag() != TYPE_VECTOR ) + if ( GetType()->Tag() != TYPE_VECTOR ) ExprError("coercion to non-vector"); - else if ( op->Type()->Tag() != TYPE_VECTOR ) + else if ( op->GetType()->Tag() != TYPE_VECTOR ) ExprError("coercion of non-vector to vector"); } @@ -3798,7 +3784,7 @@ IntrusivePtr VectorCoerceExpr::Fold(Val* v) const if ( vv->Size() > 0 ) RuntimeErrorWithCallStack("coercion of non-empty vector"); - return make_intrusive(IntrusivePtr{NewRef{}, Type()->AsVectorType()}); + return make_intrusive(GetType()); } FlattenExpr::FlattenExpr(IntrusivePtr arg_op) @@ -3807,7 +3793,7 @@ FlattenExpr::FlattenExpr(IntrusivePtr arg_op) if ( IsError() ) return; - BroType* t = op->Type(); + const auto& t = op->GetType(); if ( t->Tag() != TYPE_RECORD ) Internal("bad type in FlattenExpr::FlattenExpr"); @@ -3873,7 +3859,7 @@ ScheduleExpr::ScheduleExpr(IntrusivePtr arg_when, if ( IsError() || when->IsError() || event->IsError() ) return; - TypeTag bt = when->Type()->Tag(); + TypeTag bt = when->GetType()->Tag(); if ( bt != TYPE_TIME && bt != TYPE_INTERVAL ) ExprError("schedule expression requires a time or time interval"); @@ -3898,7 +3884,7 @@ IntrusivePtr ScheduleExpr::Eval(Frame* f) const double dt = when_val->InternalDouble(); - if ( when->Type()->Tag() == TYPE_INTERVAL ) + if ( when->GetType()->Tag() == TYPE_INTERVAL ) dt += network_time; auto args = eval_list(f, event->Args()); @@ -3950,34 +3936,34 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( IsError() ) return; - if ( op1->Type()->Tag() == TYPE_PATTERN ) + if ( op1->GetType()->Tag() == TYPE_PATTERN ) { - if ( op2->Type()->Tag() != TYPE_STRING ) + if ( op2->GetType()->Tag() != TYPE_STRING ) { - op2->Type()->Error("pattern requires string index", op1.get()); + op2->GetType()->Error("pattern requires string index", op1.get()); SetError(); } else SetType(base_type(TYPE_BOOL)); } - else if ( op1->Type()->Tag() == TYPE_RECORD ) + else if ( op1->GetType()->Tag() == TYPE_RECORD ) { - if ( op2->Type()->Tag() != TYPE_TABLE ) + if ( op2->GetType()->Tag() != TYPE_TABLE ) { - op2->Type()->Error("table/set required"); + op2->GetType()->Error("table/set required"); SetError(); } else { - const BroType* t1 = op1->Type(); + const auto& t1 = op1->GetType(); const TypeList* it = - op2->Type()->AsTableType()->Indices(); + op2->GetType()->AsTableType()->Indices(); - if ( ! same_type(t1, it) ) + if ( ! same_type(t1.get(), it) ) { - t1->Error("indexing mismatch", op2->Type()); + t1->Error("indexing mismatch", op2->GetType().get()); SetError(); } else @@ -3985,8 +3971,8 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) } } - else if ( op1->Type()->Tag() == TYPE_STRING && - op2->Type()->Tag() == TYPE_STRING ) + else if ( op1->GetType()->Tag() == TYPE_STRING && + op2->GetType()->Tag() == TYPE_STRING ) SetType(base_type(TYPE_BOOL)); else @@ -3994,16 +3980,16 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) // Check for: in // in set[subnet] // in table[subnet] of ... - if ( op1->Type()->Tag() == TYPE_ADDR ) + if ( op1->GetType()->Tag() == TYPE_ADDR ) { - if ( op2->Type()->Tag() == TYPE_SUBNET ) + if ( op2->GetType()->Tag() == TYPE_SUBNET ) { SetType(base_type(TYPE_BOOL)); return; } - if ( op2->Type()->Tag() == TYPE_TABLE && - op2->Type()->AsTableType()->IsSubNetIndex() ) + if ( op2->GetType()->Tag() == TYPE_TABLE && + op2->GetType()->AsTableType()->IsSubNetIndex() ) { SetType(base_type(TYPE_BOOL)); return; @@ -4015,7 +4001,7 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) ListExpr* lop1 = op1->AsListExpr(); - if ( ! op2->Type()->MatchesIndex(lop1) ) + if ( ! op2->GetType()->MatchesIndex(lop1) ) SetError("not an index type"); else SetType(base_type(TYPE_BOOL)); @@ -4066,7 +4052,7 @@ CallExpr::CallExpr(IntrusivePtr arg_func, return; } - BroType* func_type = func->Type(); + const auto& func_type = func->GetType(); if ( ! IsFunc(func_type->Tag()) ) { @@ -4455,7 +4441,7 @@ ListExpr::~ListExpr() void ListExpr::Append(IntrusivePtr e) { exprs.push_back(e.release()); - ((TypeList*) type.get())->Append({NewRef{}, exprs.back()->Type()}); + ((TypeList*) type.get())->Append(exprs.back()->GetType()); } bool ListExpr::IsPure() const @@ -4522,7 +4508,7 @@ IntrusivePtr ListExpr::InitType() const for ( const auto& e : exprs ) { - BroType* ti = e->Type(); + const auto& ti = e->GetType(); // Collapse any embedded sets or lists. if ( ti->IsSet() || ti->Tag() == TYPE_LIST ) @@ -4538,7 +4524,7 @@ IntrusivePtr ListExpr::InitType() const tl->Append(til->GetPureType()); } else - tl->Append({NewRef{}, ti}); + tl->Append(ti); } return tl; @@ -4702,10 +4688,10 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) { IntrusivePtr element; - if ( expr->Type()->IsSet() ) + if ( expr->GetType()->IsSet() ) // A set to flatten. element = expr->Eval(nullptr); - else if ( expr->Type()->Tag() == TYPE_LIST ) + else if ( expr->GetType()->Tag() == TYPE_LIST ) element = expr->InitVal(it, nullptr); else element = expr->InitVal(it->Types()[0].get(), nullptr); @@ -4727,7 +4713,7 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) continue; } - if ( expr->Type()->Tag() == TYPE_LIST ) + if ( expr->GetType()->Tag() == TYPE_LIST ) element = check_and_promote(std::move(element), it, true); else element = check_and_promote(std::move(element), it->Types()[0].get(), true); @@ -4795,7 +4781,7 @@ RecordAssignExpr::RecordAssignExpr(const IntrusivePtr& record, { const expr_list& inits = init_list->AsListExpr()->Exprs(); - RecordType* lhs = record->Type()->AsRecordType(); + RecordType* lhs = record->GetType()->AsRecordType(); // The inits have two forms: // 1) other records -- use all matching field names+types @@ -4804,9 +4790,9 @@ RecordAssignExpr::RecordAssignExpr(const IntrusivePtr& record, for ( const auto& init : inits ) { - if ( init->Type()->Tag() == TYPE_RECORD ) + if ( init->GetType()->Tag() == TYPE_RECORD ) { - RecordType* t = init->Type()->AsRecordType(); + RecordType* t = init->GetType()->AsRecordType(); for ( int j = 0; j < t->NumFields(); ++j ) { @@ -4855,11 +4841,11 @@ RecordAssignExpr::RecordAssignExpr(const IntrusivePtr& record, CastExpr::CastExpr(IntrusivePtr arg_op, IntrusivePtr t) : UnaryExpr(EXPR_CAST, std::move(arg_op)) { - auto stype = Op()->Type(); + auto stype = Op()->GetType(); SetType(std::move(t)); - if ( ! can_cast_value_to_type(stype, Type()) ) + if ( ! can_cast_value_to_type(stype.get(), GetType().get()) ) ExprError("cast not supported"); } @@ -4873,7 +4859,7 @@ IntrusivePtr CastExpr::Eval(Frame* f) const if ( ! v ) return nullptr; - auto nv = cast_value_to_type(v.get(), Type()); + auto nv = cast_value_to_type(v.get(), GetType().get()); if ( nv ) return nv; @@ -4882,7 +4868,7 @@ IntrusivePtr CastExpr::Eval(Frame* f) const d.Add("invalid cast of value with type '"); v->GetType()->Describe(&d); d.Add("' to type '"); - Type()->Describe(&d); + GetType()->Describe(&d); d.Add("'"); if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) && @@ -4897,7 +4883,7 @@ void CastExpr::ExprDescribe(ODesc* d) const { Op()->Describe(d); d->Add(" as "); - Type()->Describe(d); + GetType()->Describe(d); } IsExpr::IsExpr(IntrusivePtr arg_op, IntrusivePtr arg_t) @@ -4924,8 +4910,8 @@ void IsExpr::ExprDescribe(ODesc* d) const IntrusivePtr get_assign_expr(IntrusivePtr op1, IntrusivePtr op2, bool is_init) { - if ( op1->Type()->Tag() == TYPE_RECORD && - op2->Type()->Tag() == TYPE_LIST ) + if ( op1->GetType()->Tag() == TYPE_RECORD && + op2->GetType()->Tag() == TYPE_LIST ) return make_intrusive(std::move(op1), std::move(op2), is_init); @@ -4940,7 +4926,7 @@ IntrusivePtr get_assign_expr(IntrusivePtr op1, IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) { - BroType* et = e->Type(); + const auto& et = e->GetType(); TypeTag e_tag = et->Tag(); TypeTag t_tag = t->Tag(); @@ -4973,7 +4959,7 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) RecordType* t_r = t->AsRecordType(); RecordType* et_r = et->AsRecordType(); - if ( same_type(t, et) ) + if ( same_type(t, et.get()) ) { // Make sure the attributes match as well. for ( int i = 0; i < t_r->NumFields(); ++i ) @@ -4996,7 +4982,7 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) } - if ( ! same_type(t, et) ) + if ( ! same_type(t, et.get()) ) { if ( t->Tag() == TYPE_TABLE && et->Tag() == TYPE_TABLE && et->AsTableType()->IsUnspecifiedTable() ) diff --git a/src/Expr.h b/src/Expr.h index e540d45b2d..a00304009c 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -75,7 +75,16 @@ struct function_ingredients; class Expr : public BroObj { public: + [[deprecated("Remove in v4.1. Use GetType().")]] BroType* Type() const { return type.get(); } + + const IntrusivePtr& GetType() const + { return type; } + + template + IntrusivePtr GetType() const + { return cast_intrusive(type); } + BroExprTag Tag() const { return tag; } Expr* Ref() { ::Ref(this); return this; } @@ -946,4 +955,4 @@ std::optional>> eval_list(Frame* f, const ListExpr extern bool expr_greater(const Expr* e1, const Expr* e2); // True if the given Val* has a vector type -inline bool is_vector(Expr* e) { return e->Type()->Tag() == TYPE_VECTOR; } +inline bool is_vector(Expr* e) { return e->GetType()->Tag() == TYPE_VECTOR; } diff --git a/src/Func.cc b/src/Func.cc index ae0fd88809..b60df3f4a3 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -795,7 +795,7 @@ bool check_built_in_call(BuiltinFunc* f, CallExpr* call) } const Expr* fmt_str_arg = args[0]; - if ( fmt_str_arg->Type()->Tag() != TYPE_STRING ) + if ( fmt_str_arg->GetType()->Tag() != TYPE_STRING ) { call->Error("first argument to fmt() needs to be a format string"); return false; diff --git a/src/Stmt.cc b/src/Stmt.cc index f20e154d57..b5d927b2ef 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -136,7 +136,7 @@ ExprListStmt::ExprListStmt(BroStmtTag t, IntrusivePtr arg_l) const expr_list& e = l->Exprs(); for ( const auto& expr : e ) { - const BroType* t = expr->Type(); + const auto& t = expr->GetType(); if ( ! t || t->Tag() == TYPE_VOID ) Error("value of type void illegal"); } @@ -366,7 +366,7 @@ IfStmt::IfStmt(IntrusivePtr test, : ExprStmt(STMT_IF, std::move(test)), s1(std::move(arg_s1)), s2(std::move(arg_s2)) { - if ( ! e->IsError() && ! IsBool(e->Type()->Tag()) ) + if ( ! e->IsError() && ! IsBool(e->GetType()->Tag()) ) e->Error("conditional in test must be boolean"); const Location* loc1 = s1->GetLocationInfo(); @@ -580,7 +580,7 @@ static void int_del_func(void* v) void SwitchStmt::Init() { auto t = make_intrusive(); - t->Append({NewRef{}, e->Type()}); + t->Append(e->GetType()); comp_hash = new CompositeHash(std::move(t)); case_label_value_map.SetDeleteFunc(int_del_func); @@ -605,10 +605,10 @@ SwitchStmt::SwitchStmt(IntrusivePtr index, case_list* arg_cases) { have_exprs = true; - if ( ! is_atomic_type(e->Type()) ) + if ( ! is_atomic_type(e->GetType().get()) ) e->Error("switch expression must be of an atomic type when cases are expressions"); - if ( ! le->Type()->AsTypeList()->AllMatch(e->Type(), false) ) + if ( ! le->GetType()->AsTypeList()->AllMatch(e->GetType().get(), false) ) { le->Error("case expression type differs from switch type", e.get()); continue; @@ -679,7 +679,7 @@ SwitchStmt::SwitchStmt(IntrusivePtr index, case_list* arg_cases) { const auto& ct = t->GetType(); - if ( ! can_cast_value_to_type(e->Type(), ct.get()) ) + if ( ! can_cast_value_to_type(e->GetType().get(), ct.get()) ) { c->Error("cannot cast switch expression to case type"); continue; @@ -724,7 +724,7 @@ bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx) { reporter->PushLocation(e->GetLocationInfo()); reporter->InternalError("switch expression type mismatch (%s/%s)", - type_name(v->GetType()->Tag()), type_name(e->Type()->Tag())); + type_name(v->GetType()->Tag()), type_name(e->GetType()->Tag())); } int* label_idx = case_label_value_map.Lookup(hk); @@ -768,7 +768,7 @@ std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const { reporter->PushLocation(e->GetLocationInfo()); reporter->Error("switch expression type mismatch (%s/%s)", - type_name(v->GetType()->Tag()), type_name(e->Type()->Tag())); + type_name(v->GetType()->Tag()), type_name(e->GetType()->Tag())); return std::make_pair(-1, nullptr); } @@ -987,7 +987,7 @@ WhileStmt::WhileStmt(IntrusivePtr arg_loop_condition, : loop_condition(std::move(arg_loop_condition)), body(std::move(arg_body)) { if ( ! loop_condition->IsError() && - ! IsBool(loop_condition->Type()->Tag()) ) + ! IsBool(loop_condition->GetType()->Tag()) ) loop_condition->Error("while conditional must be boolean"); } @@ -1067,9 +1067,9 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) loop_vars = arg_loop_vars; body = nullptr; - if ( e->Type()->Tag() == TYPE_TABLE ) + if ( e->GetType()->Tag() == TYPE_TABLE ) { - const auto& indices = e->Type()->AsTableType()->IndexTypes(); + const auto& indices = e->GetType()->AsTableType()->IndexTypes(); if ( static_cast(indices.size()) != loop_vars->length() ) { @@ -1097,7 +1097,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) } } - else if ( e->Type()->Tag() == TYPE_VECTOR ) + else if ( e->GetType()->Tag() == TYPE_VECTOR ) { if ( loop_vars->length() != 1 ) { @@ -1118,7 +1118,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) } } - else if ( e->Type()->Tag() == TYPE_STRING ) + else if ( e->GetType()->Tag() == TYPE_STRING ) { if ( loop_vars->length() != 1 ) { @@ -1149,9 +1149,9 @@ ForStmt::ForStmt(id_list* arg_loop_vars, { value_var = std::move(val_var); - if ( e->Type()->IsTable() ) + if ( e->GetType()->IsTable() ) { - const auto& yield_type = e->Type()->AsTableType()->Yield(); + const auto& yield_type = e->GetType()->AsTableType()->Yield(); // Verify value_vars type if its already been defined if ( value_var->GetType() ) @@ -1432,7 +1432,7 @@ ReturnStmt::ReturnStmt(IntrusivePtr arg_e) { if ( e ) { - ft->SetYieldType({NewRef{}, e->Type()}); + ft->SetYieldType(e->GetType()); s->ScopeID()->SetInferReturnType(false); } } @@ -1752,7 +1752,7 @@ WhenStmt::WhenStmt(IntrusivePtr arg_cond, assert(cond); assert(s1); - if ( ! cond->IsError() && ! IsBool(cond->Type()->Tag()) ) + if ( ! cond->IsError() && ! IsBool(cond->GetType()->Tag()) ) cond->Error("conditional in test must be boolean"); if ( timeout ) @@ -1760,7 +1760,7 @@ WhenStmt::WhenStmt(IntrusivePtr arg_cond, if ( timeout->IsError() ) return; - TypeTag bt = timeout->Type()->Tag(); + TypeTag bt = timeout->GetType()->Tag(); if ( bt != TYPE_TIME && bt != TYPE_INTERVAL ) cond->Error("when timeout requires a time or time interval"); } diff --git a/src/Type.cc b/src/Type.cc index 122f5370cd..2826a741a4 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -228,7 +228,7 @@ int IndexType::MatchesIndex(ListExpr* const index) const const expr_list& exprs = index->Exprs(); if ( types.size() == 1 && types[0]->Tag() == TYPE_SUBNET && - exprs.length() == 1 && exprs[0]->Type()->Tag() == TYPE_ADDR ) + exprs.length() == 1 && exprs[0]->GetType()->Tag() == TYPE_ADDR ) return MATCHES_INDEX_SCALAR; return check_and_promote_exprs(index, Indices()) ? @@ -366,7 +366,7 @@ SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements } else { - TypeList* tl_type = elements->Type()->AsTypeList(); + TypeList* tl_type = elements->GetType()->AsTypeList(); const auto& tl = tl_type->Types(); if ( tl.size() < 1 ) @@ -1355,13 +1355,13 @@ int VectorType::MatchesIndex(ListExpr* const index) const if ( el.length() == 2 ) return MATCHES_INDEX_VECTOR; - else if ( el[0]->Type()->Tag() == TYPE_VECTOR ) - return (IsIntegral(el[0]->Type()->Yield()->Tag()) || - IsBool(el[0]->Type()->Yield()->Tag())) ? + else if ( el[0]->GetType()->Tag() == TYPE_VECTOR ) + return (IsIntegral(el[0]->GetType()->Yield()->Tag()) || + IsBool(el[0]->GetType()->Yield()->Tag())) ? MATCHES_INDEX_VECTOR : DOES_NOT_MATCH_INDEX; else - return (IsIntegral(el[0]->Type()->Tag()) || - IsBool(el[0]->Type()->Tag())) ? + return (IsIntegral(el[0]->GetType()->Tag()) || + IsBool(el[0]->GetType()->Tag())) ? MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX; } @@ -1955,7 +1955,7 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) IntrusivePtr merge_type_list(ListExpr* elements) { - TypeList* tl_type = elements->Type()->AsTypeList(); + TypeList* tl_type = elements->GetType()->AsTypeList(); const auto& tl = tl_type->Types(); if ( tl.size() < 1 ) diff --git a/src/Val.cc b/src/Val.cc index cd5b0c2934..e1e2dc77ec 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1483,7 +1483,7 @@ void TableVal::CheckExpireAttr(attr_tag at) { expire_time = {NewRef{}, a->AttrExpr()}; - if ( expire_time->Type()->Tag() != TYPE_INTERVAL ) + if ( expire_time->GetType()->Tag() != TYPE_INTERVAL ) { if ( ! expire_time->IsError() ) expire_time->SetError("expiration interval has wrong type"); @@ -1807,10 +1807,10 @@ IntrusivePtr TableVal::Default(Val* index) if ( ! def_val ) { const auto& ytype = GetType()->Yield(); - BroType* dtype = def_attr->AttrExpr()->Type(); + const auto& dtype = def_attr->AttrExpr()->GetType(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype, ytype.get()) && + ! same_type(dtype.get(), ytype.get()) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) { @@ -2303,10 +2303,10 @@ void TableVal::InitDefaultFunc(Frame* f) return; const auto& ytype = GetType()->Yield(); - BroType* dtype = def_attr->AttrExpr()->Type(); + const auto& dtype = def_attr->AttrExpr()->GetType(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype, ytype.get()) && + ! same_type(dtype.get(), ytype.get()) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) return; // TableVal::Default will handle this. diff --git a/src/parse.y b/src/parse.y index 645a64e399..5ed3aa4797 100644 --- a/src/parse.y +++ b/src/parse.y @@ -231,7 +231,7 @@ static bool expr_is_table_type_name(const Expr* expr) if ( expr->Tag() != EXPR_NAME ) return false; - BroType* type = expr->Type(); + const auto& type = expr->GetType(); if ( type->IsTable() ) return true; @@ -743,7 +743,7 @@ expr: set_location(@1, @3); IntrusivePtr e{AdoptRef{}, $2}; - if ( IsIntegral(e->Type()->Tag()) ) + if ( IsIntegral(e->GetType()->Tag()) ) e = make_intrusive(std::move(e), TYPE_INT); $$ = new SizeExpr(std::move(e)); @@ -1323,7 +1323,7 @@ index_slice: make_intrusive( IntrusivePtr{NewRef{}, $1}); - if ( ! IsIntegral(low->Type()->Tag()) || ! IsIntegral(high->Type()->Tag()) ) + if ( ! IsIntegral(low->GetType()->Tag()) || ! IsIntegral(high->GetType()->Tag()) ) reporter->Error("slice notation must have integral values as indexes"); auto le = make_intrusive(std::move(low)); From 6147804b361549a24dbdb680c1a176d723a15f16 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 11 May 2020 15:55:43 -0700 Subject: [PATCH 041/151] Add missing "vector_coerce" to expr_name() --- src/Expr.cc | 2 +- testing/btest/Baseline/plugins.hooks/output | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 4b794d606e..271cff9e80 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -36,7 +36,7 @@ const char* expr_name(BroExprTag t) "table()", "set()", "vector()", "$=", "in", "<<>>", "()", "function()", "event", "schedule", - "coerce", "record_coerce", "table_coerce", + "coerce", "record_coerce", "table_coerce", "vector_coerce", "sizeof", "flatten", "cast", "is", "[:]=" }; diff --git a/testing/btest/Baseline/plugins.hooks/output b/testing/btest/Baseline/plugins.hooks/output index 514820557f..620be2be0d 100644 --- a/testing/btest/Baseline/plugins.hooks/output +++ b/testing/btest/Baseline/plugins.hooks/output @@ -565,7 +565,7 @@ 0.000000 MetaHookPost CallFunction(SumStats::register_observe_plugin, , (SumStats::STD_DEV, lambda_<5704045257244168718>{ SumStats::calc_std_dev(SumStats::rv)})) -> 0.000000 MetaHookPost CallFunction(SumStats::register_observe_plugin, , (SumStats::SUM, lambda_<6958532551242393774>{ SumStats::rv$sum += SumStats::val})) -> 0.000000 MetaHookPost CallFunction(SumStats::register_observe_plugin, , (SumStats::TOPK, lambda_<2861372781530360365>{ topk_add(SumStats::rv$topk, SumStats::obs)})) -> -0.000000 MetaHookPost CallFunction(SumStats::register_observe_plugin, , (SumStats::UNIQUE, lambda_<535013331230430358>{ if (!SumStats::rv?$unique_vals) SumStats::rv$unique_vals = (coerce set() to set[SumStats::Observation])if (SumStats::r?$unique_max) SumStats::rv$unique_max = SumStats::r$unique_maxif (!SumStats::r?$unique_max || flattenSumStats::rv$unique_vals <= SumStats::r$unique_max) add SumStats::rv$unique_vals[SumStats::obs]SumStats::rv$unique = flattenSumStats::rv$unique_vals})) -> +0.000000 MetaHookPost CallFunction(SumStats::register_observe_plugin, , (SumStats::UNIQUE, lambda_<10387912117292132662>{ if (!SumStats::rv?$unique_vals) SumStats::rv$unique_vals = (coerce set() to set[SumStats::Observation])if (SumStats::r?$unique_max) SumStats::rv$unique_max = SumStats::r$unique_maxif (!SumStats::r?$unique_max || sizeofSumStats::rv$unique_vals <= SumStats::r$unique_max) add SumStats::rv$unique_vals[SumStats::obs]SumStats::rv$unique = sizeofSumStats::rv$unique_vals})) -> 0.000000 MetaHookPost CallFunction(SumStats::register_observe_plugin, , (SumStats::VARIANCE, lambda_<6557258612059469785>{ if (1 < SumStats::rv$num) SumStats::rv$var_s += ((SumStats::val - SumStats::rv$prev_avg) * (SumStats::val - SumStats::rv$average))SumStats::calc_variance(SumStats::rv)SumStats::rv$prev_avg = SumStats::rv$average})) -> 0.000000 MetaHookPost CallFunction(SumStats::register_observe_plugins, , ()) -> 0.000000 MetaHookPost CallFunction(current_time, , ()) -> @@ -1486,7 +1486,7 @@ 0.000000 MetaHookPre CallFunction(SumStats::register_observe_plugin, , (SumStats::STD_DEV, lambda_<5704045257244168718>{ SumStats::calc_std_dev(SumStats::rv)})) 0.000000 MetaHookPre CallFunction(SumStats::register_observe_plugin, , (SumStats::SUM, lambda_<6958532551242393774>{ SumStats::rv$sum += SumStats::val})) 0.000000 MetaHookPre CallFunction(SumStats::register_observe_plugin, , (SumStats::TOPK, lambda_<2861372781530360365>{ topk_add(SumStats::rv$topk, SumStats::obs)})) -0.000000 MetaHookPre CallFunction(SumStats::register_observe_plugin, , (SumStats::UNIQUE, lambda_<535013331230430358>{ if (!SumStats::rv?$unique_vals) SumStats::rv$unique_vals = (coerce set() to set[SumStats::Observation])if (SumStats::r?$unique_max) SumStats::rv$unique_max = SumStats::r$unique_maxif (!SumStats::r?$unique_max || flattenSumStats::rv$unique_vals <= SumStats::r$unique_max) add SumStats::rv$unique_vals[SumStats::obs]SumStats::rv$unique = flattenSumStats::rv$unique_vals})) +0.000000 MetaHookPre CallFunction(SumStats::register_observe_plugin, , (SumStats::UNIQUE, lambda_<10387912117292132662>{ if (!SumStats::rv?$unique_vals) SumStats::rv$unique_vals = (coerce set() to set[SumStats::Observation])if (SumStats::r?$unique_max) SumStats::rv$unique_max = SumStats::r$unique_maxif (!SumStats::r?$unique_max || sizeofSumStats::rv$unique_vals <= SumStats::r$unique_max) add SumStats::rv$unique_vals[SumStats::obs]SumStats::rv$unique = sizeofSumStats::rv$unique_vals})) 0.000000 MetaHookPre CallFunction(SumStats::register_observe_plugin, , (SumStats::VARIANCE, lambda_<6557258612059469785>{ if (1 < SumStats::rv$num) SumStats::rv$var_s += ((SumStats::val - SumStats::rv$prev_avg) * (SumStats::val - SumStats::rv$average))SumStats::calc_variance(SumStats::rv)SumStats::rv$prev_avg = SumStats::rv$average})) 0.000000 MetaHookPre CallFunction(SumStats::register_observe_plugins, , ()) 0.000000 MetaHookPre CallFunction(current_time, , ()) @@ -2406,7 +2406,7 @@ 0.000000 | HookCallFunction SumStats::register_observe_plugin(SumStats::STD_DEV, lambda_<5704045257244168718>{ SumStats::calc_std_dev(SumStats::rv)}) 0.000000 | HookCallFunction SumStats::register_observe_plugin(SumStats::SUM, lambda_<6958532551242393774>{ SumStats::rv$sum += SumStats::val}) 0.000000 | HookCallFunction SumStats::register_observe_plugin(SumStats::TOPK, lambda_<2861372781530360365>{ topk_add(SumStats::rv$topk, SumStats::obs)}) -0.000000 | HookCallFunction SumStats::register_observe_plugin(SumStats::UNIQUE, lambda_<535013331230430358>{ if (!SumStats::rv?$unique_vals) SumStats::rv$unique_vals = (coerce set() to set[SumStats::Observation])if (SumStats::r?$unique_max) SumStats::rv$unique_max = SumStats::r$unique_maxif (!SumStats::r?$unique_max || flattenSumStats::rv$unique_vals <= SumStats::r$unique_max) add SumStats::rv$unique_vals[SumStats::obs]SumStats::rv$unique = flattenSumStats::rv$unique_vals}) +0.000000 | HookCallFunction SumStats::register_observe_plugin(SumStats::UNIQUE, lambda_<10387912117292132662>{ if (!SumStats::rv?$unique_vals) SumStats::rv$unique_vals = (coerce set() to set[SumStats::Observation])if (SumStats::r?$unique_max) SumStats::rv$unique_max = SumStats::r$unique_maxif (!SumStats::r?$unique_max || sizeofSumStats::rv$unique_vals <= SumStats::r$unique_max) add SumStats::rv$unique_vals[SumStats::obs]SumStats::rv$unique = sizeofSumStats::rv$unique_vals}) 0.000000 | HookCallFunction SumStats::register_observe_plugin(SumStats::VARIANCE, lambda_<6557258612059469785>{ if (1 < SumStats::rv$num) SumStats::rv$var_s += ((SumStats::val - SumStats::rv$prev_avg) * (SumStats::val - SumStats::rv$average))SumStats::calc_variance(SumStats::rv)SumStats::rv$prev_avg = SumStats::rv$average}) 0.000000 | HookCallFunction SumStats::register_observe_plugins() 0.000000 | HookCallFunction current_time() From 40ee59f0c302b7911b11f2e4be92bf34a825fef4 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 11 May 2020 15:59:15 -0700 Subject: [PATCH 042/151] Remove unused FlattenExpr --- src/Expr.cc | 51 +-------------------------------------------------- src/Expr.h | 13 ------------- 2 files changed, 1 insertion(+), 63 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 271cff9e80..9a8bec21e1 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -37,7 +37,7 @@ const char* expr_name(BroExprTag t) "$=", "in", "<<>>", "()", "function()", "event", "schedule", "coerce", "record_coerce", "table_coerce", "vector_coerce", - "sizeof", "flatten", "cast", "is", "[:]=" + "sizeof", "cast", "is", "[:]=" }; if ( int(t) >= NUM_EXPRS ) @@ -410,8 +410,6 @@ void UnaryExpr::ExprDescribe(ODesc* d) const { if ( is_coerce ) d->Add("(coerce "); - else if ( Tag() == EXPR_FLATTEN ) - d->Add("flatten "); else if ( Tag() != EXPR_REF ) d->Add(expr_name(Tag())); } @@ -3787,53 +3785,6 @@ IntrusivePtr VectorCoerceExpr::Fold(Val* v) const return make_intrusive(GetType()); } -FlattenExpr::FlattenExpr(IntrusivePtr arg_op) - : UnaryExpr(EXPR_FLATTEN, std::move(arg_op)) - { - if ( IsError() ) - return; - - const auto& t = op->GetType(); - - if ( t->Tag() != TYPE_RECORD ) - Internal("bad type in FlattenExpr::FlattenExpr"); - - RecordType* rt = t->AsRecordType(); - num_fields = rt->NumFields(); - - auto tl = make_intrusive(); - - for ( int i = 0; i < num_fields; ++i ) - tl->Append(rt->GetFieldType(i)); - - Unref(rt); - SetType(std::move(tl)); - } - -IntrusivePtr FlattenExpr::Fold(Val* v) const - { - RecordVal* rv = v->AsRecordVal(); - auto l = make_intrusive(TYPE_ANY); - - for ( int i = 0; i < num_fields; ++i ) - { - if ( Val* fv = rv->Lookup(i) ) - { - l->Append({NewRef{}, fv}); - continue; - } - - const RecordType* rv_t = rv->GetType()->AsRecordType(); - if ( const Attr* fa = rv_t->FieldDecl(i)->FindAttr(ATTR_DEFAULT) ) - l->Append(fa->AttrExpr()->Eval(nullptr)); - - else - RuntimeError("missing field value"); - } - - return l; - } - ScheduleTimer::ScheduleTimer(const EventHandlerPtr& arg_event, zeek::Args arg_args, double t) : Timer(t, TIMER_SCHEDULE), diff --git a/src/Expr.h b/src/Expr.h index a00304009c..79ee9d9bd1 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -50,7 +50,6 @@ enum BroExprTag : int { EXPR_TABLE_COERCE, EXPR_VECTOR_COERCE, EXPR_SIZE, - EXPR_FLATTEN, EXPR_CAST, EXPR_IS, EXPR_INDEX_SLICE_ASSIGN, @@ -735,18 +734,6 @@ protected: IntrusivePtr Fold(Val* v) const override; }; -// An internal operator for flattening array indices that are records -// into a list of individual values. -class FlattenExpr final : public UnaryExpr { -public: - explicit FlattenExpr(IntrusivePtr op); - -protected: - IntrusivePtr Fold(Val* v) const override; - - int num_fields; -}; - class ScheduleTimer final : public Timer { public: ScheduleTimer(const EventHandlerPtr& event, zeek::Args args, double t); From 4351a2671075c78e1a06a7a0ff0e2feb354cb628 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 11 May 2020 17:30:51 -0700 Subject: [PATCH 043/151] Add RecordVal ctor that takes IntrusivePtr --- src/Val.cc | 15 ++++++++++----- src/Val.h | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index e1e2dc77ec..53e603bbfa 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2649,14 +2649,19 @@ TableVal::TableRecordDependencies TableVal::parse_time_table_record_dependencies RecordVal::RecordTypeValMap RecordVal::parse_time_records; -RecordVal::RecordVal(RecordType* t, bool init_fields) : Val(IntrusivePtr{NewRef{}, t}) +RecordVal::RecordVal(RecordType* t, bool init_fields) + : RecordVal({NewRef{}, t}, init_fields) + {} + +RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::move(t)) { origin = nullptr; - int n = t->NumFields(); + auto rt = GetType()->AsRecordType(); + int n = rt->NumFields(); val_list* vl = val.val_list_val = new val_list(n); if ( is_parsing ) - parse_time_records[t].emplace_back(NewRef{}, this); + parse_time_records[rt].emplace_back(NewRef{}, this); if ( ! init_fields ) return; @@ -2665,10 +2670,10 @@ RecordVal::RecordVal(RecordType* t, bool init_fields) : Val(IntrusivePtr{NewRef{ // by default). for ( int i = 0; i < n; ++i ) { - Attributes* a = t->FieldDecl(i)->attrs.get(); + Attributes* a = rt->FieldDecl(i)->attrs.get(); Attr* def_attr = a ? a->FindAttr(ATTR_DEFAULT) : nullptr; auto def = def_attr ? def_attr->AttrExpr()->Eval(nullptr) : nullptr; - const auto& type = t->FieldDecl(i)->type; + const auto& type = rt->FieldDecl(i)->type; if ( def && type->Tag() == TYPE_RECORD && def->GetType()->Tag() == TYPE_RECORD && diff --git a/src/Val.h b/src/Val.h index e523882f2e..92c2194277 100644 --- a/src/Val.h +++ b/src/Val.h @@ -931,6 +931,8 @@ protected: class RecordVal final : public Val, public notifier::Modifiable { public: explicit RecordVal(RecordType* t, bool init_fields = true); + explicit RecordVal(IntrusivePtr t, bool init_fields = true); + ~RecordVal() override; IntrusivePtr SizeVal() const override; From c0986f0739ecc7bb6899fc07bf6cf98d7d4dea49 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 11 May 2020 19:22:49 -0700 Subject: [PATCH 044/151] Deprecate global type pointers in NetVar.h There's analogous IntrusivePtrs in zeek::vars --- NEWS | 3 + src/BroString.cc | 4 +- src/CMakeLists.txt | 4 + src/Conn.cc | 10 +- src/EventHandler.cc | 4 +- src/File.cc | 2 +- src/NetVar.cc | 60 +------ src/NetVar.h | 51 ++++++ src/OpaqueVal.cc | 2 +- src/RuleCondition.cc | 3 +- src/RuleMatcher.cc | 2 +- src/Sessions.cc | 2 +- src/Stmt.cc | 2 +- src/TunnelEncapsulation.cc | 2 +- src/ZeekVars.cc | 165 ++++++++++++++++++ src/ZeekVars.h | 67 +++++++ src/analyzer/protocol/conn-size/ConnSize.cc | 4 +- src/analyzer/protocol/dhcp/dhcp-analyzer.pac | 2 +- src/analyzer/protocol/dhcp/dhcp-options.pac | 2 +- src/analyzer/protocol/dns/DNS.cc | 26 +-- src/analyzer/protocol/http/HTTP.cc | 4 +- src/analyzer/protocol/icmp/ICMP.cc | 10 +- src/analyzer/protocol/imap/imap-analyzer.pac | 2 +- src/analyzer/protocol/irc/IRC.cc | 14 +- src/analyzer/protocol/krb/krb-types.pac | 2 +- src/analyzer/protocol/mime/MIME.cc | 4 +- .../protocol/mqtt/commands/subscribe.pac | 4 +- .../protocol/mqtt/commands/unsubscribe.pac | 2 +- .../protocol/mysql/mysql-analyzer.pac | 2 +- src/analyzer/protocol/rpc/MOUNT.cc | 2 +- src/analyzer/protocol/rpc/NFS.cc | 2 +- src/analyzer/protocol/rpc/Portmap.cc | 8 +- src/analyzer/protocol/sip/sip-analyzer.pac | 4 +- .../protocol/smb/smb1-com-negotiate.pac | 2 +- .../protocol/smb/smb2-com-negotiate.pac | 2 +- src/analyzer/protocol/smb/smb2-protocol.pac | 6 +- .../protocol/socks/socks-analyzer.pac | 8 +- src/analyzer/protocol/ssh/ssh-analyzer.pac | 2 +- .../protocol/ssl/proc-client-hello.pac | 4 +- .../protocol/ssl/tls-handshake-analyzer.pac | 22 +-- src/analyzer/protocol/tcp/TCP.cc | 6 +- src/file_analysis/File.cc | 58 +++--- src/file_analysis/File.h | 2 + src/file_analysis/Manager.cc | 4 +- src/file_analysis/analyzer/entropy/Entropy.cc | 2 +- src/file_analysis/analyzer/pe/pe-analyzer.pac | 4 +- src/file_analysis/analyzer/x509/X509.cc | 6 +- src/iosource/Packet.cc | 4 +- src/reporter.bif | 2 +- src/strings.bif | 7 +- src/zeek.bif | 57 +++--- 51 files changed, 451 insertions(+), 224 deletions(-) create mode 100644 src/ZeekVars.cc create mode 100644 src/ZeekVars.h diff --git a/NEWS b/NEWS index 0c9339663b..5c80a4f295 100644 --- a/NEWS +++ b/NEWS @@ -171,6 +171,9 @@ Deprecated Functionality - ``Val::Type()`` is deprecated, use ``Val::GetType``. +- Most global type/value pointers in NetVar.h are deprecated, but there's + analogous ``IntrusivePtr`` in ``zeek::vars``. + Zeek 3.1.0 ========== diff --git a/src/BroString.cc b/src/BroString.cc index b72ead7572..6e5465160e 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -11,6 +11,7 @@ #include "Var.h" #include "Reporter.h" #include "util.h" +#include "ZeekVars.h" #ifdef DEBUG #define DEBUG_STR(msg) DBG_LOG(DBG_STRING, msg) @@ -340,8 +341,7 @@ BroString::Vec* BroString::Split(const BroString::IdxVec& indices) const VectorVal* BroString:: VecToPolicy(Vec* vec) { - auto result = - make_intrusive(zeek::lookup_type("string_vec")); + auto result = make_intrusive(zeek::vars::string_vec); for ( unsigned int i = 0; i < vec->size(); ++i ) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bc2ea56555..5526ab35ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -205,6 +205,9 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DebugCmdConstants.h set_source_files_properties(nb_dns.c PROPERTIES COMPILE_FLAGS -fno-strict-aliasing) +set_source_files_properties(ZeekVars.cc PROPERTIES COMPILE_FLAGS + -Wno-deprecated-declarations) + set(MAIN_SRCS digest.cc net_util.cc @@ -286,6 +289,7 @@ set(MAIN_SRCS Var.cc WeirdState.cc ZeekArgs.cc + ZeekVars.cc bsd-getopt-long.c bro_inet_ntop.c patricia.c diff --git a/src/Conn.cc b/src/Conn.cc index dc8b63bb9c..7146191cb0 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -346,17 +346,17 @@ const IntrusivePtr& Connection::ConnVal() { if ( ! conn_val ) { - conn_val = make_intrusive(connection_type); + conn_val = make_intrusive(zeek::vars::connection_type); TransportProto prot_type = ConnTransport(); - auto id_val = make_intrusive(conn_id); + auto id_val = make_intrusive(zeek::vars::conn_id); id_val->Assign(0, make_intrusive(orig_addr)); id_val->Assign(1, val_mgr->Port(ntohs(orig_port), prot_type)); id_val->Assign(2, make_intrusive(resp_addr)); id_val->Assign(3, val_mgr->Port(ntohs(resp_port), prot_type)); - auto orig_endp = make_intrusive(endpoint); + auto orig_endp = make_intrusive(zeek::vars::endpoint); orig_endp->Assign(0, val_mgr->Count(0)); orig_endp->Assign(1, val_mgr->Count(0)); orig_endp->Assign(4, val_mgr->Count(orig_flow_label)); @@ -367,7 +367,7 @@ const IntrusivePtr& Connection::ConnVal() if ( memcmp(&orig_l2_addr, &null, l2_len) != 0 ) orig_endp->Assign(5, make_intrusive(fmt_mac(orig_l2_addr, l2_len))); - auto resp_endp = make_intrusive(endpoint); + auto resp_endp = make_intrusive(zeek::vars::endpoint); resp_endp->Assign(0, val_mgr->Count(0)); resp_endp->Assign(1, val_mgr->Count(0)); resp_endp->Assign(4, val_mgr->Count(resp_flow_label)); @@ -379,7 +379,7 @@ const IntrusivePtr& Connection::ConnVal() conn_val->Assign(1, std::move(orig_endp)); conn_val->Assign(2, std::move(resp_endp)); // 3 and 4 are set below. - conn_val->Assign(5, make_intrusive(IntrusivePtr{NewRef{}, string_set})); // service + conn_val->Assign(5, make_intrusive(zeek::vars::string_set)); // service conn_val->Assign(6, val_mgr->EmptyString()); // history if ( ! uid ) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 5c114d99ba..95b36e6b48 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -127,7 +127,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) return; RecordType* args = FType()->Args(); - auto vargs = make_intrusive(IntrusivePtr{NewRef{}, call_argument_vector}); + auto vargs = make_intrusive(zeek::vars::call_argument_vector); for ( int i = 0; i < args->NumFields(); i++ ) { @@ -135,7 +135,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) const auto& ftype = args->GetFieldType(i); auto fdefault = args->FieldDefault(i); - auto rec = make_intrusive(call_argument); + auto rec = make_intrusive(zeek::vars::call_argument); rec->Assign(0, make_intrusive(fname)); ODesc d; diff --git a/src/File.cc b/src/File.cc index 7581b9fb3b..7cefb2f9fd 100644 --- a/src/File.cc +++ b/src/File.cc @@ -277,7 +277,7 @@ RecordVal* BroFile::Rotate() if ( f == stdin || f == stdout || f == stderr ) return nullptr; - RecordVal* info = new RecordVal(rotate_info); + RecordVal* info = new RecordVal(zeek::vars::rotate_info); FILE* newf = rotate_file(name, info); if ( ! newf ) diff --git a/src/NetVar.cc b/src/NetVar.cc index 74cc7ca2df..18b0f9f6d5 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -7,8 +7,6 @@ #include "EventHandler.h" #include "Val.h" -using namespace zeek; - RecordType* conn_id; RecordType* endpoint; RecordType* endpoint_stats; @@ -207,7 +205,6 @@ void init_general_global_var() table_expire_delay = opt_internal_double("table_expire_delay"); table_incremental_step = opt_internal_int("table_incremental_step"); - rotate_info = lookup_type("rotate_info")->AsRecordType(); log_rotate_base_time = opt_internal_string("log_rotate_base_time"); peer_description = @@ -241,26 +238,7 @@ void init_net_var() #include "reporter.bif.netvar_init" #include "supervisor.bif.netvar_init" - conn_id = lookup_type("conn_id")->AsRecordType(); - endpoint = lookup_type("endpoint")->AsRecordType(); - endpoint_stats = lookup_type("endpoint_stats")->AsRecordType(); - connection_type = lookup_type("connection")->AsRecordType(); - fa_file_type = lookup_type("fa_file")->AsRecordType(); - fa_metadata_type = lookup_type("fa_metadata")->AsRecordType(); - icmp_conn = lookup_type("icmp_conn")->AsRecordType(); - icmp_context = lookup_type("icmp_context")->AsRecordType(); - signature_state = lookup_type("signature_state")->AsRecordType(); - SYN_packet = lookup_type("SYN_packet")->AsRecordType(); - pcap_packet = lookup_type("pcap_packet")->AsRecordType(); - raw_pkt_hdr_type = lookup_type("raw_pkt_hdr")->AsRecordType(); - l2_hdr_type = lookup_type("l2_hdr")->AsRecordType(); - transport_proto = lookup_type("transport_proto")->AsEnumType(); - string_set = lookup_type("string_set")->AsTableType(); - string_array = lookup_type("string_array")->AsTableType(); - string_vec = lookup_type("string_vec")->AsVectorType(); - index_vec = lookup_type("index_vec")->AsVectorType(); - mime_match = lookup_type("mime_match")->AsRecordType(); - mime_matches = lookup_type("mime_matches")->AsVectorType(); + zeek::vars::detail::Init(); ignore_checksums = opt_internal_int("ignore_checksums"); partial_connection_ok = opt_internal_int("partial_connection_ok"); @@ -286,8 +264,6 @@ void init_net_var() opt_internal_int("tcp_excessive_data_without_further_acks"); tcp_max_old_segments = opt_internal_int("tcp_max_old_segments"); - socks_address = lookup_type("SOCKS::Address")->AsRecordType(); - non_analyzed_lifetime = opt_internal_double("non_analyzed_lifetime"); tcp_inactivity_timeout = opt_internal_double("tcp_inactivity_timeout"); udp_inactivity_timeout = opt_internal_double("udp_inactivity_timeout"); @@ -333,34 +309,10 @@ void init_net_var() mime_segment_length = opt_internal_int("mime_segment_length"); mime_segment_overlap_length = opt_internal_int("mime_segment_overlap_length"); - mime_header_rec = lookup_type("mime_header_rec")->AsRecordType(); - mime_header_list = lookup_type("mime_header_list")->AsTableType(); http_entity_data_delivery_size = opt_internal_int("http_entity_data_delivery_size"); - http_stats_rec = lookup_type("http_stats_rec")->AsRecordType(); - http_message_stat = lookup_type("http_message_stat")->AsRecordType(); truncate_http_URI = opt_internal_int("truncate_http_URI"); - pm_mapping = lookup_type("pm_mapping")->AsRecordType(); - pm_mappings = lookup_type("pm_mappings")->AsTableType(); - pm_port_request = lookup_type("pm_port_request")->AsRecordType(); - pm_callit_request = lookup_type("pm_callit_request")->AsRecordType(); - - geo_location = lookup_type("geo_location")->AsRecordType(); - - entropy_test_result = lookup_type("entropy_test_result")->AsRecordType(); - - dns_msg = lookup_type("dns_msg")->AsRecordType(); - dns_answer = lookup_type("dns_answer")->AsRecordType(); - dns_soa = lookup_type("dns_soa")->AsRecordType(); - dns_edns_additional = - lookup_type("dns_edns_additional")->AsRecordType(); - dns_tsig_additional = - lookup_type("dns_tsig_additional")->AsRecordType(); - dns_rrsig_rr = lookup_type("dns_rrsig_rr")->AsRecordType(); - dns_dnskey_rr = lookup_type("dns_dnskey_rr")->AsRecordType(); - dns_nsec3_rr = lookup_type("dns_nsec3_rr")->AsRecordType(); - dns_ds_rr = lookup_type("dns_ds_rr")->AsRecordType(); dns_skip_auth = zeek::lookup_val("dns_skip_auth")->AsTableVal(); dns_skip_addl = zeek::lookup_val("dns_skip_addl")->AsTableVal(); dns_skip_all_auth = opt_internal_int("dns_skip_all_auth"); @@ -396,9 +348,6 @@ void init_net_var() gap_report_freq = opt_internal_double("gap_report_freq"); - irc_join_info = lookup_type("irc_join_info")->AsRecordType(); - irc_join_list = lookup_type("irc_join_list")->AsTableType(); - dpd_reassemble_first_packets = opt_internal_int("dpd_reassemble_first_packets"); dpd_buffer_size = opt_internal_int("dpd_buffer_size"); @@ -410,11 +359,4 @@ void init_net_var() timer_mgr_inactivity_timeout = opt_internal_double("timer_mgr_inactivity_timeout"); - - script_id = lookup_type("script_id")->AsRecordType(); - id_table = lookup_type("id_table")->AsTableType(); - record_field = lookup_type("record_field")->AsRecordType(); - record_field_table = lookup_type("record_field_table")->AsTableType(); - call_argument_vector = lookup_type("call_argument_vector")->AsVectorType(); - call_argument = lookup_type("call_argument")->AsRecordType(); } diff --git a/src/NetVar.h b/src/NetVar.h index fa76529197..dbf6b31c1d 100644 --- a/src/NetVar.h +++ b/src/NetVar.h @@ -6,27 +6,49 @@ #include "Func.h" #include "EventRegistry.h" #include "Stats.h" +#include "ZeekVars.h" +[[deprecated("Remove in v4.1. Use zeek::vars::conn_id.")]] extern RecordType* conn_id; +[[deprecated("Remove in v4.1. Use zeek::vars::endpoint.")]] extern RecordType* endpoint; +[[deprecated("Remove in v4.1. Use zeek::vars::endpoint_stats.")]] extern RecordType* endpoint_stats; +[[deprecated("Remove in v4.1. Use zeek::vars::connection_type.")]] extern RecordType* connection_type; +[[deprecated("Remove in v4.1. Use zeek::vars::fa_file_type.")]] extern RecordType* fa_file_type; +[[deprecated("Remove in v4.1. Use zeek::vars::fa_metadata_type.")]] extern RecordType* fa_metadata_type; +[[deprecated("Remove in v4.1. Use zeek::vars::icmp_conn.")]] extern RecordType* icmp_conn; +[[deprecated("Remove in v4.1. Use zeek::vars::icmp_context.")]] extern RecordType* icmp_context; +[[deprecated("Remove in v4.1. Use zeek::vars::signature_state.")]] extern RecordType* signature_state; +[[deprecated("Remove in v4.1. Use zeek::vars::SYN_packet.")]] extern RecordType* SYN_packet; +[[deprecated("Remove in v4.1. Use zeek::vars::pcap_packet.")]] extern RecordType* pcap_packet; +[[deprecated("Remove in v4.1. Use zeek::vars::raw_pkt_hdr_type.")]] extern RecordType* raw_pkt_hdr_type; +[[deprecated("Remove in v4.1. Use zeek::vars::l2_hdr_type.")]] extern RecordType* l2_hdr_type; +[[deprecated("Remove in v4.1. Use zeek::vars::transport_proto.")]] extern EnumType* transport_proto; +[[deprecated("Remove in v4.1. Use zeek::vars::string_set.")]] extern TableType* string_set; +[[deprecated("Remove in v4.1. Use zeek::vars::string_array.")]] extern TableType* string_array; +[[deprecated("Remove in v4.1. Use zeek::vars::count_set.")]] extern TableType* count_set; +[[deprecated("Remove in v4.1. Use zeek::vars::string_vec.")]] extern VectorType* string_vec; +[[deprecated("Remove in v4.1. Use zeek::vars::index_vec.")]] extern VectorType* index_vec; +[[deprecated("Remove in v4.1. Use zeek::vars::mime_matches.")]] extern VectorType* mime_matches; +[[deprecated("Remove in v4.1. Use zeek::vars::mime_match.")]] extern RecordType* mime_match; extern int watchdog_interval; @@ -55,6 +77,7 @@ extern int tcp_max_above_hole_without_any_acks; extern int tcp_excessive_data_without_further_acks; extern int tcp_max_old_segments; +[[deprecated("Remove in v4.1. Use zeek::vars::socks_address.")]] extern RecordType* socks_address; extern double non_analyzed_lifetime; @@ -85,31 +108,50 @@ extern double rpc_timeout; extern int mime_segment_length; extern int mime_segment_overlap_length; +[[deprecated("Remove in v4.1. Use zeek::vars::mime_header_rec.")]] extern RecordType* mime_header_rec; +[[deprecated("Remove in v4.1. Use zeek::vars::mime_header_list.")]] extern TableType* mime_header_list; extern int http_entity_data_delivery_size; +[[deprecated("Remove in v4.1. Use zeek::vars::http_stats_rec.")]] extern RecordType* http_stats_rec; +[[deprecated("Remove in v4.1. Use zeek::vars::http_message_stat.")]] extern RecordType* http_message_stat; extern int truncate_http_URI; +[[deprecated("Remove in v4.1. Use zeek::vars::pm_mapping.")]] extern RecordType* pm_mapping; +[[deprecated("Remove in v4.1. Use zeek::vars::pm_mappings.")]] extern TableType* pm_mappings; +[[deprecated("Remove in v4.1. Use zeek::vars::pm_port_request.")]] extern RecordType* pm_port_request; +[[deprecated("Remove in v4.1. Use zeek::vars::pm_callit_request.")]] extern RecordType* pm_callit_request; +[[deprecated("Remove in v4.1. Use zeek::vars::geo_location.")]] extern RecordType* geo_location; +[[deprecated("Remove in v4.1. Use zeek::vars::entropy_test_result.")]] extern RecordType* entropy_test_result; +[[deprecated("Remove in v4.1. Use zeek::vars::dns_msg.")]] extern RecordType* dns_msg; +[[deprecated("Remove in v4.1. Use zeek::vars::dns_answer.")]] extern RecordType* dns_answer; +[[deprecated("Remove in v4.1. Use zeek::vars::dns_soa.")]] extern RecordType* dns_soa; +[[deprecated("Remove in v4.1. Use zeek::vars::dns_edns_additional.")]] extern RecordType* dns_edns_additional; +[[deprecated("Remove in v4.1. Use zeek::vars::dns_tsig_additional.")]] extern RecordType* dns_tsig_additional; +[[deprecated("Remove in v4.1. Use zeek::vars::dns_rrsig_rr.")]] extern RecordType* dns_rrsig_rr; +[[deprecated("Remove in v4.1. Use zeek::vars::dns_dnskey_rr.")]] extern RecordType* dns_dnskey_rr; +[[deprecated("Remove in v4.1. Use zeek::vars::dns_nsec3_rr.")]] extern RecordType* dns_nsec3_rr; +[[deprecated("Remove in v4.1. Use zeek::vars::dns_ds_rr.")]] extern RecordType* dns_ds_rr; extern TableVal* dns_skip_auth; extern TableVal* dns_skip_addl; @@ -133,6 +175,7 @@ extern TableVal* preserve_other_addr; extern double connection_status_update_interval; +[[deprecated("Remove in v4.1. Use zeek::vars::rotate_info.")]] extern RecordType* rotate_info; extern StringVal* log_rotate_base_time; @@ -153,7 +196,9 @@ extern int packet_filter_default; extern int sig_max_group_size; +[[deprecated("Remove in v4.1. Use zeek::vars::irc_join_list.")]] extern TableType* irc_join_list; +[[deprecated("Remove in v4.1. Use zeek::vars::irc_join_info.")]] extern RecordType* irc_join_info; extern int dpd_reassemble_first_packets; @@ -174,11 +219,17 @@ extern StringVal* trace_output_file; extern int record_all_packets; +[[deprecated("Remove in v4.1. Use zeek::vars::script_id.")]] extern RecordType* script_id; +[[deprecated("Remove in v4.1. Use zeek::vars::id_table.")]] extern TableType* id_table; +[[deprecated("Remove in v4.1. Use zeek::vars::record_field.")]] extern RecordType* record_field; +[[deprecated("Remove in v4.1. Use zeek::vars::record_field_table.")]] extern TableType* record_field_table; +[[deprecated("Remove in v4.1. Use zeek::vars::call_argument.")]] extern RecordType* call_argument; +[[deprecated("Remove in v4.1. Use zeek::vars::call_argument_vector.")]] extern VectorType* call_argument_vector; extern StringVal* cmd_line_bpf_filter; diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index ac2ae55711..ff236fb894 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -981,7 +981,7 @@ ParaglobVal::ParaglobVal(std::unique_ptr p) IntrusivePtr ParaglobVal::Get(StringVal* &pattern) { - auto rval = make_intrusive(zeek::lookup_type("string_vec")); + auto rval = make_intrusive(zeek::vars::string_vec); std::string string_pattern (reinterpret_cast(pattern->Bytes()), pattern->Len()); std::vector matches = this->internal_paraglob->get(string_pattern); diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index a9f878390a..b3434088dd 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -8,6 +8,7 @@ #include "Func.h" #include "Val.h" #include "Var.h" +#include "ZeekVars.h" static inline bool is_established(const analyzer::tcp::TCP_Endpoint* e) { @@ -145,7 +146,7 @@ RuleConditionEval::RuleConditionEval(const char* func) rules_error("eval function type must yield a 'bool'", func); TypeList tl; - tl.Append(zeek::lookup_type("signature_state")); + tl.Append(zeek::vars::signature_state); tl.Append(base_type(TYPE_STRING)); if ( ! f->CheckArgs(tl.Types()) ) diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index 1341cc9c2b..fdc9af6471 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -79,7 +79,7 @@ RuleHdrTest::RuleHdrTest(Prot arg_prot, Comp arg_comp, vector arg_v) Val* RuleMatcher::BuildRuleStateValue(const Rule* rule, const RuleEndpointState* state) const { - RecordVal* val = new RecordVal(signature_state); + RecordVal* val = new RecordVal(zeek::vars::signature_state); val->Assign(0, make_intrusive(rule->ID())); val->Assign(1, state->GetAnalyzer()->ConnVal()); val->Assign(2, val_mgr->Bool(state->is_orig)); diff --git a/src/Sessions.cc b/src/Sessions.cc index afdddbdf1c..3c58a4427e 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -914,7 +914,7 @@ Connection* NetSessions::FindConnection(Val* v) int orig_h, orig_p; // indices into record's value list int resp_h, resp_p; - if ( vr == conn_id ) + if ( vr == zeek::vars::conn_id ) { orig_h = 0; orig_p = 1; diff --git a/src/Stmt.cc b/src/Stmt.cc index b5d927b2ef..1575e874eb 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -202,7 +202,7 @@ static void print_log(const std::vector>& vals) { auto plval = lookup_enum_val("Log", "PRINTLOG"); auto record = make_intrusive(zeek::lookup_type("Log::PrintLogInfo")->AsRecordType()); - auto vec = make_intrusive(zeek::lookup_type("string_vec")); + auto vec = make_intrusive(zeek::vars::string_vec); for ( const auto& val : vals ) { diff --git a/src/TunnelEncapsulation.cc b/src/TunnelEncapsulation.cc index 2f58df3bd0..ad3461f8bb 100644 --- a/src/TunnelEncapsulation.cc +++ b/src/TunnelEncapsulation.cc @@ -20,7 +20,7 @@ IntrusivePtr EncapsulatingConn::ToVal() const { auto rv = make_intrusive(BifType::Record::Tunnel::EncapsulatingConn); - auto id_val = make_intrusive(conn_id); + auto id_val = make_intrusive(zeek::vars::conn_id); id_val->Assign(0, make_intrusive(src_addr)); id_val->Assign(1, val_mgr->Port(ntohs(src_port), proto)); id_val->Assign(2, make_intrusive(dst_addr)); diff --git a/src/ZeekVars.cc b/src/ZeekVars.cc new file mode 100644 index 0000000000..317c265dbc --- /dev/null +++ b/src/ZeekVars.cc @@ -0,0 +1,165 @@ +// See the file "COPYING" in the main distribution directory for copyright. + +#include "ZeekVars.h" +#include "Var.h" +#include "NetVar.h" + +IntrusivePtr zeek::vars::conn_id; +IntrusivePtr zeek::vars::endpoint; +IntrusivePtr zeek::vars::endpoint_stats; +IntrusivePtr zeek::vars::connection_type; +IntrusivePtr zeek::vars::fa_file_type; +IntrusivePtr zeek::vars::fa_metadata_type; +IntrusivePtr zeek::vars::icmp_conn; +IntrusivePtr zeek::vars::icmp_context; +IntrusivePtr zeek::vars::signature_state; +IntrusivePtr zeek::vars::SYN_packet; +IntrusivePtr zeek::vars::pcap_packet; +IntrusivePtr zeek::vars::raw_pkt_hdr_type; +IntrusivePtr zeek::vars::l2_hdr_type; +IntrusivePtr zeek::vars::transport_proto; +IntrusivePtr zeek::vars::string_set; +IntrusivePtr zeek::vars::string_array; +IntrusivePtr zeek::vars::count_set; +IntrusivePtr zeek::vars::string_vec; +IntrusivePtr zeek::vars::index_vec; +IntrusivePtr zeek::vars::mime_matches; +IntrusivePtr zeek::vars::mime_match; +IntrusivePtr zeek::vars::socks_address; +IntrusivePtr zeek::vars::mime_header_rec; +IntrusivePtr zeek::vars::mime_header_list; +IntrusivePtr zeek::vars::http_stats_rec; +IntrusivePtr zeek::vars::http_message_stat; +IntrusivePtr zeek::vars::pm_mapping; +IntrusivePtr zeek::vars::pm_mappings; +IntrusivePtr zeek::vars::pm_port_request; +IntrusivePtr zeek::vars::pm_callit_request; +IntrusivePtr zeek::vars::geo_location; +IntrusivePtr zeek::vars::entropy_test_result; +IntrusivePtr zeek::vars::dns_msg; +IntrusivePtr zeek::vars::dns_answer; +IntrusivePtr zeek::vars::dns_soa; +IntrusivePtr zeek::vars::dns_edns_additional; +IntrusivePtr zeek::vars::dns_tsig_additional; +IntrusivePtr zeek::vars::dns_rrsig_rr; +IntrusivePtr zeek::vars::dns_dnskey_rr; +IntrusivePtr zeek::vars::dns_nsec3_rr; +IntrusivePtr zeek::vars::dns_ds_rr; +IntrusivePtr zeek::vars::rotate_info; +IntrusivePtr zeek::vars::irc_join_list; +IntrusivePtr zeek::vars::irc_join_info; +IntrusivePtr zeek::vars::script_id; +IntrusivePtr zeek::vars::id_table; +IntrusivePtr zeek::vars::record_field; +IntrusivePtr zeek::vars::record_field_table; +IntrusivePtr zeek::vars::call_argument; +IntrusivePtr zeek::vars::call_argument_vector; + +void zeek::vars::detail::Init() + { + // Types + conn_id = zeek::lookup_type("conn_id"); + endpoint = zeek::lookup_type("endpoint"); + endpoint_stats = zeek::lookup_type("endpoint_stats"); + connection_type = zeek::lookup_type("connection"); + fa_file_type = zeek::lookup_type("fa_file"); + fa_metadata_type = zeek::lookup_type("fa_metadata"); + icmp_conn = zeek::lookup_type("icmp_conn"); + icmp_context = zeek::lookup_type("icmp_context"); + signature_state = zeek::lookup_type("signature_state"); + SYN_packet = zeek::lookup_type("SYN_packet"); + pcap_packet = zeek::lookup_type("pcap_packet"); + raw_pkt_hdr_type = zeek::lookup_type("raw_pkt_hdr"); + l2_hdr_type = zeek::lookup_type("l2_hdr"); + transport_proto = zeek::lookup_type("transport_proto"); + string_set = zeek::lookup_type("string_set"); + string_array = zeek::lookup_type("string_array"); + count_set = zeek::lookup_type("count_set"); + string_vec = zeek::lookup_type("string_vec"); + index_vec = zeek::lookup_type("index_vec"); + mime_matches = zeek::lookup_type("mime_matches"); + mime_match = zeek::lookup_type("mime_match"); + socks_address = zeek::lookup_type("SOCKS::Address"); + mime_header_rec = zeek::lookup_type("mime_header_rec"); + mime_header_list = zeek::lookup_type("mime_header_list"); + http_stats_rec = zeek::lookup_type("http_stats_rec"); + http_message_stat = zeek::lookup_type("http_message_stat"); + pm_mapping = zeek::lookup_type("pm_mapping"); + pm_mappings = zeek::lookup_type("pm_mappings"); + pm_port_request = zeek::lookup_type("pm_port_request"); + pm_callit_request = zeek::lookup_type("pm_callit_request"); + geo_location = zeek::lookup_type("geo_location"); + entropy_test_result = zeek::lookup_type("entropy_test_result"); + dns_msg = zeek::lookup_type("dns_msg"); + dns_answer = zeek::lookup_type("dns_answer"); + dns_soa = zeek::lookup_type("dns_soa"); + dns_edns_additional = zeek::lookup_type("dns_edns_additional"); + dns_tsig_additional = zeek::lookup_type("dns_tsig_additional"); + dns_rrsig_rr = zeek::lookup_type("dns_rrsig_rr"); + dns_dnskey_rr = zeek::lookup_type("dns_dnskey_rr"); + dns_nsec3_rr = zeek::lookup_type("dns_nsec3_rr"); + dns_ds_rr = zeek::lookup_type("dns_ds_rr"); + rotate_info = zeek::lookup_type("rotate_info"); + irc_join_list = zeek::lookup_type("irc_join_list"); + irc_join_info = zeek::lookup_type("irc_join_info"); + script_id = zeek::lookup_type("script_id"); + id_table = zeek::lookup_type("id_table"); + record_field = zeek::lookup_type("record_field"); + record_field_table = zeek::lookup_type("record_field_table"); + call_argument = zeek::lookup_type("call_argument"); + call_argument_vector = zeek::lookup_type("call_argument_vector"); + + // Note: to bypass deprecation warnings on setting the legacy globals, + // CMake was told to compile this file with -Wno-deprecated-declarations. + // Once the legacy globals are removed, that compile flag can go also. + ::conn_id = conn_id.get(); + ::endpoint = endpoint.get(); + ::endpoint_stats = endpoint_stats.get(); + ::connection_type = connection_type.get(); + ::fa_file_type = fa_file_type.get(); + ::fa_metadata_type = fa_metadata_type.get(); + ::icmp_conn = icmp_conn.get(); + ::icmp_context = icmp_context.get(); + ::signature_state = signature_state.get(); + ::SYN_packet = SYN_packet.get(); + ::pcap_packet = pcap_packet.get(); + ::raw_pkt_hdr_type = raw_pkt_hdr_type.get(); + ::l2_hdr_type = l2_hdr_type.get(); + ::transport_proto = transport_proto.get(); + ::string_set = string_set.get(); + ::string_array = string_array.get(); + ::count_set = count_set.get(); + ::string_vec = string_vec.get(); + ::index_vec = index_vec.get(); + ::mime_matches = mime_matches.get(); + ::mime_match = mime_match.get(); + ::socks_address = socks_address.get(); + ::mime_header_rec = mime_header_rec.get(); + ::mime_header_list = mime_header_list.get(); + ::http_stats_rec = http_stats_rec.get(); + ::http_message_stat = http_message_stat.get(); + ::pm_mapping = pm_mapping.get(); + ::pm_mappings = pm_mappings.get(); + ::pm_port_request = pm_port_request.get(); + ::pm_callit_request = pm_callit_request.get(); + ::geo_location = geo_location.get(); + ::entropy_test_result = entropy_test_result.get(); + ::dns_msg = dns_msg.get(); + ::dns_answer = dns_answer.get(); + ::dns_soa = dns_soa.get(); + ::dns_edns_additional = dns_edns_additional.get(); + ::dns_tsig_additional = dns_tsig_additional.get(); + ::dns_rrsig_rr = dns_rrsig_rr.get(); + ::dns_dnskey_rr = dns_dnskey_rr.get(); + ::dns_nsec3_rr = dns_nsec3_rr.get(); + ::dns_ds_rr = dns_ds_rr.get(); + ::rotate_info = rotate_info.get(); + ::irc_join_list = irc_join_list.get(); + ::irc_join_info = irc_join_info.get(); + ::script_id = script_id.get(); + ::id_table = id_table.get(); + ::record_field = record_field.get(); + ::record_field_table = record_field_table.get(); + ::call_argument = call_argument.get(); + ::call_argument_vector = call_argument_vector.get(); + } diff --git a/src/ZeekVars.h b/src/ZeekVars.h new file mode 100644 index 0000000000..9c55af833f --- /dev/null +++ b/src/ZeekVars.h @@ -0,0 +1,67 @@ +// See the file "COPYING" in the main distribution directory for copyright. + +#pragma once + +#include "Val.h" +#include "Type.h" +#include "IntrusivePtr.h" + +namespace zeek { namespace vars { namespace detail { +void Init(); +}}} + +namespace zeek { namespace vars { + +// Types +extern IntrusivePtr conn_id; +extern IntrusivePtr endpoint; +extern IntrusivePtr endpoint_stats; +extern IntrusivePtr connection_type; +extern IntrusivePtr fa_file_type; +extern IntrusivePtr fa_metadata_type; +extern IntrusivePtr icmp_conn; +extern IntrusivePtr icmp_context; +extern IntrusivePtr signature_state; +extern IntrusivePtr SYN_packet; +extern IntrusivePtr pcap_packet; +extern IntrusivePtr raw_pkt_hdr_type; +extern IntrusivePtr l2_hdr_type; +extern IntrusivePtr transport_proto; +extern IntrusivePtr string_set; +extern IntrusivePtr string_array; +extern IntrusivePtr count_set; +extern IntrusivePtr string_vec; +extern IntrusivePtr index_vec; +extern IntrusivePtr mime_matches; +extern IntrusivePtr mime_match; +extern IntrusivePtr socks_address; +extern IntrusivePtr mime_header_rec; +extern IntrusivePtr mime_header_list; +extern IntrusivePtr http_stats_rec; +extern IntrusivePtr http_message_stat; +extern IntrusivePtr pm_mapping; +extern IntrusivePtr pm_mappings; +extern IntrusivePtr pm_port_request; +extern IntrusivePtr pm_callit_request; +extern IntrusivePtr geo_location; +extern IntrusivePtr entropy_test_result; +extern IntrusivePtr dns_msg; +extern IntrusivePtr dns_answer; +extern IntrusivePtr dns_soa; +extern IntrusivePtr dns_edns_additional; +extern IntrusivePtr dns_tsig_additional; +extern IntrusivePtr dns_rrsig_rr; +extern IntrusivePtr dns_dnskey_rr; +extern IntrusivePtr dns_nsec3_rr; +extern IntrusivePtr dns_ds_rr; +extern IntrusivePtr rotate_info; +extern IntrusivePtr irc_join_list; +extern IntrusivePtr irc_join_info; +extern IntrusivePtr script_id; +extern IntrusivePtr id_table; +extern IntrusivePtr record_field; +extern IntrusivePtr record_field_table; +extern IntrusivePtr call_argument; +extern IntrusivePtr call_argument_vector; + +}} // namespace zeek::vars diff --git a/src/analyzer/protocol/conn-size/ConnSize.cc b/src/analyzer/protocol/conn-size/ConnSize.cc index 58c186a06a..4742f6f50f 100644 --- a/src/analyzer/protocol/conn-size/ConnSize.cc +++ b/src/analyzer/protocol/conn-size/ConnSize.cc @@ -174,8 +174,8 @@ void ConnSize_Analyzer::UpdateConnVal(RecordVal *conn_val) RecordVal *resp_endp = conn_val->Lookup("resp")->AsRecordVal(); // endpoint is the RecordType from NetVar.h - int pktidx = endpoint->FieldOffset("num_pkts"); - int bytesidx = endpoint->FieldOffset("num_bytes_ip"); + int pktidx = zeek::vars::endpoint->FieldOffset("num_pkts"); + int bytesidx = zeek::vars::endpoint->FieldOffset("num_bytes_ip"); if ( pktidx < 0 ) reporter->InternalError("'endpoint' record missing 'num_pkts' field"); diff --git a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac index 1164cd4677..53233069d9 100644 --- a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac +++ b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac @@ -20,7 +20,7 @@ refine flow DHCP_Flow += { if ( ! options ) { options = make_intrusive(BifType::Record::DHCP::Options); - all_options = make_intrusive(IntrusivePtr{NewRef{}, index_vec}); + all_options = make_intrusive(zeek::vars::index_vec); options->Assign(0, all_options); } diff --git a/src/analyzer/protocol/dhcp/dhcp-options.pac b/src/analyzer/protocol/dhcp/dhcp-options.pac index d6f917cf7f..5d319826ab 100644 --- a/src/analyzer/protocol/dhcp/dhcp-options.pac +++ b/src/analyzer/protocol/dhcp/dhcp-options.pac @@ -462,7 +462,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_par_req_list_option(v: OptionValue): bool %{ - auto params = make_intrusive(IntrusivePtr{NewRef{}, index_vec}); + auto params = make_intrusive(zeek::vars::index_vec); int num_parms = ${v.par_req_list}->size(); vector* plist = ${v.par_req_list}; diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 6db7fa1183..47d4f8dc27 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -592,7 +592,7 @@ bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, if ( dns_SOA_reply && ! msg->skip_event ) { - auto r = make_intrusive(dns_soa); + auto r = make_intrusive(zeek::vars::dns_soa); r->Assign(0, make_intrusive(new BroString(mname, mname_end - mname, true))); r->Assign(1, make_intrusive(new BroString(rname, rname_end - rname, true))); r->Assign(2, val_mgr->Count(serial)); @@ -998,7 +998,7 @@ bool DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, int typebitmaps_len = rdlength - (data - data_start); - auto char_strings = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); + auto char_strings = make_intrusive(zeek::vars::string_vec); while ( typebitmaps_len > 0 && len > 0 ) { @@ -1073,7 +1073,7 @@ bool DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, int typebitmaps_len = rdlength - (data - data_start); - auto char_strings = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); + auto char_strings = make_intrusive(zeek::vars::string_vec); while ( typebitmaps_len > 0 && len > 0 ) { @@ -1288,7 +1288,7 @@ bool DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, return true; } - auto char_strings = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); + auto char_strings = make_intrusive(zeek::vars::string_vec); IntrusivePtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) @@ -1316,7 +1316,7 @@ bool DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, return true; } - auto char_strings = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); + auto char_strings = make_intrusive(zeek::vars::string_vec); IntrusivePtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) @@ -1435,7 +1435,7 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query) IntrusivePtr DNS_MsgInfo::BuildHdrVal() { - auto r = make_intrusive(dns_msg); + auto r = make_intrusive(zeek::vars::dns_msg); r->Assign(0, val_mgr->Count(id)); r->Assign(1, val_mgr->Count(opcode)); @@ -1456,7 +1456,7 @@ IntrusivePtr DNS_MsgInfo::BuildHdrVal() IntrusivePtr DNS_MsgInfo::BuildAnswerVal() { - auto r = make_intrusive(dns_answer); + auto r = make_intrusive(zeek::vars::dns_answer); r->Assign(0, val_mgr->Count(int(answer_type))); r->Assign(1, query_name); @@ -1471,7 +1471,7 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() { // We have to treat the additional record type in EDNS differently // than a regular resource record. - auto r = make_intrusive(dns_edns_additional); + auto r = make_intrusive(zeek::vars::dns_edns_additional); r->Assign(0, val_mgr->Count(int(answer_type))); r->Assign(1, query_name); @@ -1504,7 +1504,7 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) { - auto r = make_intrusive(dns_tsig_additional); + auto r = make_intrusive(zeek::vars::dns_tsig_additional); double rtime = tsig->time_s + tsig->time_ms / 1000.0; // r->Assign(0, val_mgr->Count(int(answer_type))); @@ -1523,7 +1523,7 @@ IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) { - auto r = make_intrusive(dns_rrsig_rr); + auto r = make_intrusive(zeek::vars::dns_rrsig_rr); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); @@ -1543,7 +1543,7 @@ IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) { - auto r = make_intrusive(dns_dnskey_rr); + auto r = make_intrusive(zeek::vars::dns_dnskey_rr); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); @@ -1558,7 +1558,7 @@ IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) { - auto r = make_intrusive(dns_nsec3_rr); + auto r = make_intrusive(zeek::vars::dns_nsec3_rr); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); @@ -1577,7 +1577,7 @@ IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) IntrusivePtr DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) { - auto r = make_intrusive(dns_ds_rr); + auto r = make_intrusive(zeek::vars::dns_ds_rr); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index 77c9071ed2..daf928941c 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -615,7 +615,7 @@ HTTP_Message::~HTTP_Message() IntrusivePtr HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) { - auto stat = make_intrusive(http_message_stat); + auto stat = make_intrusive(zeek::vars::http_message_stat); int field = 0; stat->Assign(field++, make_intrusive(start_time, TYPE_TIME)); stat->Assign(field++, val_mgr->Bool(interrupted)); @@ -1151,7 +1151,7 @@ void HTTP_Analyzer::GenStats() { if ( http_stats ) { - auto r = make_intrusive(http_stats_rec); + auto r = make_intrusive(zeek::vars::http_stats_rec); r->Assign(0, val_mgr->Count(num_requests)); r->Assign(1, val_mgr->Count(num_replies)); r->Assign(2, make_intrusive(request_version.ToDouble(), TYPE_DOUBLE)); diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 84a2fc2351..33c730d63f 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -225,7 +225,7 @@ ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, { if ( ! icmp_conn_val ) { - icmp_conn_val = make_intrusive(icmp_conn); + icmp_conn_val = make_intrusive(zeek::vars::icmp_conn); icmp_conn_val->Assign(0, make_intrusive(Conn()->OrigAddr())); icmp_conn_val->Assign(1, make_intrusive(Conn()->RespAddr())); @@ -350,8 +350,8 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP4Context(int len, const u_char } } - auto iprec = make_intrusive(icmp_context); - auto id_val = make_intrusive(conn_id); + auto iprec = make_intrusive(zeek::vars::icmp_context); + auto id_val = make_intrusive(zeek::vars::conn_id); id_val->Assign(0, make_intrusive(src_addr)); id_val->Assign(1, val_mgr->Port(src_port, proto)); @@ -409,8 +409,8 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP6Context(int len, const u_char } } - auto iprec = make_intrusive(icmp_context); - auto id_val = make_intrusive(conn_id); + auto iprec = make_intrusive(zeek::vars::icmp_context); + auto id_val = make_intrusive(zeek::vars::conn_id); id_val->Assign(0, make_intrusive(src_addr)); id_val->Assign(1, val_mgr->Port(src_port, proto)); diff --git a/src/analyzer/protocol/imap/imap-analyzer.pac b/src/analyzer/protocol/imap/imap-analyzer.pac index 5b587f77c0..c6c6ffe87a 100644 --- a/src/analyzer/protocol/imap/imap-analyzer.pac +++ b/src/analyzer/protocol/imap/imap-analyzer.pac @@ -59,7 +59,7 @@ refine connection IMAP_Conn += { if ( ! imap_capabilities ) return true; - auto capv = make_intrusive(zeek::lookup_type("string_vec")); + auto capv = make_intrusive(zeek::vars::string_vec); for ( unsigned int i = 0; i< capabilities->size(); i++ ) { diff --git a/src/analyzer/protocol/irc/IRC.cc b/src/analyzer/protocol/irc/IRC.cc index e844e7e21b..6d7f2f0d82 100644 --- a/src/analyzer/protocol/irc/IRC.cc +++ b/src/analyzer/protocol/irc/IRC.cc @@ -271,7 +271,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) if ( parts.size() > 0 && parts[0][0] == ':' ) parts[0] = parts[0].substr(1); - auto set = make_intrusive(IntrusivePtr{NewRef{}, string_set}); + auto set = make_intrusive(zeek::vars::string_set); for ( unsigned int i = 0; i < parts.size(); ++i ) { @@ -464,7 +464,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) if ( parts.size() > 0 && parts[0][0] == ':' ) parts[0] = parts[0].substr(1); - auto set = make_intrusive(IntrusivePtr{NewRef{}, string_set}); + auto set = make_intrusive(zeek::vars::string_set); for ( unsigned int i = 0; i < parts.size(); ++i ) { @@ -836,7 +836,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) nickname = prefix.substr(0, pos); } - auto list = make_intrusive(IntrusivePtr{NewRef{}, irc_join_list}); + auto list = make_intrusive(zeek::vars::irc_join_list); vector channels = SplitWords(parts[0], ','); vector passwords; @@ -847,7 +847,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) string empty_string = ""; for ( unsigned int i = 0; i < channels.size(); ++i ) { - RecordVal* info = new RecordVal(irc_join_info); + RecordVal* info = new RecordVal(zeek::vars::irc_join_info); info->Assign(0, make_intrusive(nickname.c_str())); info->Assign(1, make_intrusive(channels[i].c_str())); if ( i < passwords.size() ) @@ -881,13 +881,13 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) parts[1] = parts[1].substr(1); vector users = SplitWords(parts[1], ','); - auto list = make_intrusive(IntrusivePtr{NewRef{}, irc_join_list}); + auto list = make_intrusive(zeek::vars::irc_join_list); string empty_string = ""; for ( unsigned int i = 0; i < users.size(); ++i ) { - auto info = make_intrusive(irc_join_info); + auto info = make_intrusive(zeek::vars::irc_join_info); string nick = users[i]; string mode = "none"; @@ -951,7 +951,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) nick = nick.substr(0, pos); vector channelList = SplitWords(channels, ','); - auto set = make_intrusive(IntrusivePtr{NewRef{}, string_set}); + auto set = make_intrusive(zeek::vars::string_set); for ( unsigned int i = 0; i < channelList.size(); ++i ) { diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index cbe588b38e..560a2b5b93 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -27,7 +27,7 @@ IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pname) VectorVal* proc_cipher_list(const Array* list) { - auto ciphers = make_intrusive(zeek::lookup_type("index_vec")); + auto ciphers = make_intrusive(zeek::vars::index_vec); for ( uint i = 0; i < list->data()->size(); ++i ) ciphers->Assign(ciphers->Size(), asn1_integer_to_val((*list->data())[i], TYPE_COUNT)); return ciphers.release(); diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index dab28cc608..b994407933 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -1289,7 +1289,7 @@ void MIME_Entity::DebugPrintHeaders() IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) { - auto header_record = make_intrusive(mime_header_rec); + auto header_record = make_intrusive(zeek::vars::mime_header_rec); header_record->Assign(0, new_string_val(h->get_name())); auto upper_hn = new_string_val(h->get_name()); upper_hn->ToUpper(); @@ -1300,7 +1300,7 @@ IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) IntrusivePtr MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) { - auto t = make_intrusive(IntrusivePtr{NewRef{}, mime_header_list}); + auto t = make_intrusive(zeek::vars::mime_header_list); for ( unsigned int i = 0; i < hlist.size(); ++i ) { diff --git a/src/analyzer/protocol/mqtt/commands/subscribe.pac b/src/analyzer/protocol/mqtt/commands/subscribe.pac index 496f9953df..a2bca0c0cd 100644 --- a/src/analyzer/protocol/mqtt/commands/subscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/subscribe.pac @@ -19,8 +19,8 @@ refine flow MQTT_Flow += { %{ if ( mqtt_subscribe ) { - auto topics = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); - auto qos_levels = make_intrusive(IntrusivePtr{NewRef{}, index_vec}); + auto topics = make_intrusive(zeek::vars::string_vec); + auto qos_levels = make_intrusive(zeek::vars::index_vec); for ( auto topic: *${msg.topics} ) { diff --git a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac index f7abcf68ae..cb0b747313 100644 --- a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac @@ -14,7 +14,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_unsubscribe ) { - auto topics = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); + auto topics = make_intrusive(zeek::vars::string_vec); for ( auto topic: *${msg.topics} ) { diff --git a/src/analyzer/protocol/mysql/mysql-analyzer.pac b/src/analyzer/protocol/mysql/mysql-analyzer.pac index b9ea38e3bf..9d0f13ecb6 100644 --- a/src/analyzer/protocol/mysql/mysql-analyzer.pac +++ b/src/analyzer/protocol/mysql/mysql-analyzer.pac @@ -82,7 +82,7 @@ refine flow MySQL_Flow += { if ( ! mysql_result_row ) return true; - auto vt = zeek::lookup_type("string_vec"); + auto vt = zeek::vars::string_vec; auto vv = make_intrusive(std::move(vt)); auto& bstring = ${msg.row.first_field.val}; diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index 1569279e7d..edbd34c57d 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -192,7 +192,7 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(zeek::lookup_type("index_vec")); + auto auxgids = make_intrusive(zeek::vars::index_vec); for (size_t i = 0; i < c->AuxGIDs().size(); ++i) { diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index 0ecce74ff1..0789fb806b 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -328,7 +328,7 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_ zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(zeek::lookup_type("index_vec")); + auto auxgids = make_intrusive(zeek::vars::index_vec); for ( size_t i = 0; i < c->AuxGIDs().size(); ++i ) auxgids->Assign(i, val_mgr->Count(c->AuxGIDs()[i])); diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index d3f878f8f0..91a0becb04 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -138,7 +138,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu event = success ? pm_request_dump : pm_attempt_dump; if ( success ) { - TableVal* mappings = new TableVal({NewRef{}, pm_mappings}); + TableVal* mappings = new TableVal(zeek::vars::pm_mappings); uint32_t nmap = 0; // Each call in the loop test pulls the next "opted" @@ -193,7 +193,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) { - RecordVal* mapping = new RecordVal(pm_mapping); + RecordVal* mapping = new RecordVal(zeek::vars::pm_mapping); mapping->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); mapping->Assign(1, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -213,7 +213,7 @@ Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) { - RecordVal* pr = new RecordVal(pm_port_request); + RecordVal* pr = new RecordVal(zeek::vars::pm_port_request); pr->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); pr->Assign(1, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -233,7 +233,7 @@ Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) Val* PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) { - RecordVal* c = new RecordVal(pm_callit_request); + RecordVal* c = new RecordVal(zeek::vars::pm_callit_request); c->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); c->Assign(1, val_mgr->Count(extract_XDR_uint32(buf, len))); diff --git a/src/analyzer/protocol/sip/sip-analyzer.pac b/src/analyzer/protocol/sip/sip-analyzer.pac index 37e036739d..dab40b4e26 100644 --- a/src/analyzer/protocol/sip/sip-analyzer.pac +++ b/src/analyzer/protocol/sip/sip-analyzer.pac @@ -67,7 +67,7 @@ refine flow SIP_Flow += { function build_sip_headers_val(): BroVal %{ - TableVal* t = new TableVal({NewRef{}, mime_header_list}); + TableVal* t = new TableVal(zeek::vars::mime_header_list); for ( unsigned int i = 0; i < headers.size(); ++i ) { // index starting from 1 @@ -101,7 +101,7 @@ refine flow SIP_Flow += { function build_sip_header_val(name: const_bytestring, value: const_bytestring): BroVal %{ - RecordVal* header_record = new RecordVal(mime_header_rec); + RecordVal* header_record = new RecordVal(zeek::vars::mime_header_rec); IntrusivePtr name_val; if ( name.length() > 0 ) diff --git a/src/analyzer/protocol/smb/smb1-com-negotiate.pac b/src/analyzer/protocol/smb/smb1-com-negotiate.pac index f225cf9df5..38dc341a7a 100644 --- a/src/analyzer/protocol/smb/smb1-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb1-com-negotiate.pac @@ -15,7 +15,7 @@ refine connection SMB_Conn += { %{ if ( smb1_negotiate_request ) { - auto dialects = make_intrusive(IntrusivePtr{NewRef{}, string_vec}); + auto dialects = make_intrusive(zeek::vars::string_vec); for ( unsigned int i = 0; i < ${val.dialects}->size(); ++i ) { diff --git a/src/analyzer/protocol/smb/smb2-com-negotiate.pac b/src/analyzer/protocol/smb/smb2-com-negotiate.pac index c40591b580..2fcd7f05db 100644 --- a/src/analyzer/protocol/smb/smb2-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb2-com-negotiate.pac @@ -22,7 +22,7 @@ refine connection SMB_Conn += { %{ if ( smb2_negotiate_request ) { - auto dialects = make_intrusive(IntrusivePtr{NewRef{}, index_vec}); + auto dialects = make_intrusive(zeek::vars::index_vec); for ( unsigned int i = 0; i < ${val.dialects}->size(); ++i ) dialects->Assign(i, val_mgr->Count((*${val.dialects})[i])); diff --git a/src/analyzer/protocol/smb/smb2-protocol.pac b/src/analyzer/protocol/smb/smb2-protocol.pac index 2da119cdf3..055e02377c 100644 --- a/src/analyzer/protocol/smb/smb2-protocol.pac +++ b/src/analyzer/protocol/smb/smb2-protocol.pac @@ -68,7 +68,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) rpreauth->Assign(0, val_mgr->Count(${ncv.preauth_integrity_capabilities.hash_alg_count})); rpreauth->Assign(1, val_mgr->Count(${ncv.preauth_integrity_capabilities.salt_length})); - auto ha = make_intrusive(zeek::lookup_type("index_vec")); + auto ha = make_intrusive(zeek::vars::index_vec); for ( int i = 0; i < ${ncv.preauth_integrity_capabilities.hash_alg_count}; ++i ) { @@ -87,7 +87,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rencr = make_intrusive(BifType::Record::SMB2::EncryptionCapabilities); rencr->Assign(0, val_mgr->Count(${ncv.encryption_capabilities.cipher_count})); - auto c = make_intrusive(zeek::lookup_type("index_vec")); + auto c = make_intrusive(zeek::vars::index_vec); for ( int i = 0; i < ${ncv.encryption_capabilities.cipher_count}; ++i ) { @@ -105,7 +105,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rcomp = make_intrusive(BifType::Record::SMB2::CompressionCapabilities); rcomp->Assign(0, val_mgr->Count(${ncv.compression_capabilities.alg_count})); - auto c = make_intrusive(zeek::lookup_type("index_vec")); + auto c = make_intrusive(zeek::vars::index_vec); for ( int i = 0; i < ${ncv.compression_capabilities.alg_count}; ++i ) { diff --git a/src/analyzer/protocol/socks/socks-analyzer.pac b/src/analyzer/protocol/socks/socks-analyzer.pac index 95b1812eb6..cd33098653 100644 --- a/src/analyzer/protocol/socks/socks-analyzer.pac +++ b/src/analyzer/protocol/socks/socks-analyzer.pac @@ -24,7 +24,7 @@ refine connection SOCKS_Conn += { %{ if ( socks_request ) { - auto sa = make_intrusive(socks_address); + auto sa = make_intrusive(zeek::vars::socks_address); sa->Assign(0, make_intrusive(htonl(${request.addr}))); if ( ${request.v4a} ) @@ -48,7 +48,7 @@ refine connection SOCKS_Conn += { %{ if ( socks_reply ) { - auto sa = make_intrusive(socks_address); + auto sa = make_intrusive(zeek::vars::socks_address); sa->Assign(0, make_intrusive(htonl(${reply.addr}))); BifEvent::enqueue_socks_reply(bro_analyzer(), @@ -80,7 +80,7 @@ refine connection SOCKS_Conn += { return false; } - auto sa = make_intrusive(socks_address); + auto sa = make_intrusive(zeek::vars::socks_address); // This is dumb and there must be a better way (checking for presence of a field)... switch ( ${request.remote_name.addr_type} ) @@ -119,7 +119,7 @@ refine connection SOCKS_Conn += { function socks5_reply(reply: SOCKS5_Reply): bool %{ - auto sa = make_intrusive(socks_address); + auto sa = make_intrusive(zeek::vars::socks_address); // This is dumb and there must be a better way (checking for presence of a field)... switch ( ${reply.bound.addr_type} ) diff --git a/src/analyzer/protocol/ssh/ssh-analyzer.pac b/src/analyzer/protocol/ssh/ssh-analyzer.pac index 8a6f0adc13..d0032d9b77 100644 --- a/src/analyzer/protocol/ssh/ssh-analyzer.pac +++ b/src/analyzer/protocol/ssh/ssh-analyzer.pac @@ -12,7 +12,7 @@ VectorVal* name_list_to_vector(const bytestring& nl); // Copied from IRC_Analyzer::SplitWords VectorVal* name_list_to_vector(const bytestring& nl) { - VectorVal* vv = new VectorVal(zeek::lookup_type("string_vec")); + VectorVal* vv = new VectorVal(zeek::vars::string_vec); string name_list = std_str(nl); if ( name_list.size() < 1 ) diff --git a/src/analyzer/protocol/ssl/proc-client-hello.pac b/src/analyzer/protocol/ssl/proc-client-hello.pac index 80afbb56f9..7c447bb39e 100644 --- a/src/analyzer/protocol/ssl/proc-client-hello.pac +++ b/src/analyzer/protocol/ssl/proc-client-hello.pac @@ -23,7 +23,7 @@ else std::transform(cipher_suites24->begin(), cipher_suites24->end(), std::back_inserter(cipher_suites), to_int()); - auto cipher_vec = make_intrusive(zeek::lookup_type("index_vec")); + auto cipher_vec = make_intrusive(zeek::vars::index_vec); for ( unsigned int i = 0; i < cipher_suites.size(); ++i ) { @@ -31,7 +31,7 @@ cipher_vec->Assign(i, ciph); } - auto comp_vec = make_intrusive(zeek::lookup_type("index_vec")); + auto comp_vec = make_intrusive(zeek::vars::index_vec); if ( compression_methods ) { diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index 4f499039f5..1635e375bf 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -75,7 +75,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_ec_point_formats ) return true; - auto points = make_intrusive(zeek::lookup_type("index_vec")); + auto points = make_intrusive(zeek::vars::index_vec); if ( point_format_list ) { @@ -94,7 +94,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_elliptic_curves ) return true; - auto curves = make_intrusive(zeek::lookup_type("index_vec")); + auto curves = make_intrusive(zeek::vars::index_vec); if ( list ) { @@ -113,7 +113,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(zeek::lookup_type("index_vec")); + auto nglist = make_intrusive(zeek::vars::index_vec); if ( keyshare ) { @@ -131,7 +131,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(zeek::lookup_type("index_vec")); + auto nglist = make_intrusive(zeek::vars::index_vec); nglist->Assign(0u, val_mgr->Count(keyshare->namedgroup())); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -143,7 +143,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(zeek::lookup_type("index_vec")); + auto nglist = make_intrusive(zeek::vars::index_vec); nglist->Assign(0u, val_mgr->Count(namedgroup)); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -178,7 +178,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_application_layer_protocol_negotiation ) return true; - auto plist = make_intrusive(zeek::lookup_type("string_vec")); + auto plist = make_intrusive(zeek::vars::string_vec); if ( protocols ) { @@ -194,7 +194,7 @@ refine connection Handshake_Conn += { function proc_server_name(rec: HandshakeRecord, list: ServerName[]) : bool %{ - auto servers = make_intrusive(zeek::lookup_type("string_vec")); + auto servers = make_intrusive(zeek::vars::string_vec); if ( list ) { @@ -226,7 +226,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(zeek::lookup_type("index_vec")); + auto versions = make_intrusive(zeek::vars::index_vec); if ( versions_list ) { @@ -245,7 +245,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(zeek::lookup_type("index_vec")); + auto versions = make_intrusive(zeek::vars::index_vec); versions->Assign(0u, val_mgr->Count(version)); BifEvent::enqueue_ssl_extension_supported_versions(bro_analyzer(), bro_analyzer()->Conn(), @@ -259,7 +259,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_psk_key_exchange_modes ) return true; - auto modes = make_intrusive(zeek::lookup_type("index_vec")); + auto modes = make_intrusive(zeek::vars::index_vec); if ( mode_list ) { @@ -505,7 +505,7 @@ refine connection Handshake_Conn += { } } - auto blist = make_intrusive(zeek::lookup_type("string_vec")); + auto blist = make_intrusive(zeek::vars::string_vec); if ( binders && binders->binders() ) { diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index 81b6f20f7e..f492c3e154 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -107,7 +107,7 @@ static RecordVal* build_syn_packet_val(bool is_orig, const IP_Hdr* ip, options += opt_len; } - RecordVal* v = new RecordVal(SYN_packet); + RecordVal* v = new RecordVal(zeek::vars::SYN_packet); v->Assign(0, val_mgr->Bool(is_orig)); v->Assign(1, val_mgr->Bool(int(ip->DF()))); @@ -1421,7 +1421,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) { auto p = reinterpret_cast(o + 2); auto num_pointers = (length - 2) / 4; - auto vt = zeek::lookup_type("index_vec"); + auto vt = zeek::vars::index_vec; auto sack = make_intrusive(std::move(vt)); for ( auto i = 0; i < num_pointers; ++i ) @@ -2077,7 +2077,7 @@ bool TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int capl RecordVal* TCPStats_Endpoint::BuildStats() { - RecordVal* stats = new RecordVal(endpoint_stats); + RecordVal* stats = new RecordVal(zeek::vars::endpoint_stats); stats->Assign(0, val_mgr->Count(num_pkts)); stats->Assign(1, val_mgr->Count(num_rxmit)); diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 064d4bbe9b..b98819c949 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -23,16 +23,16 @@ using namespace file_analysis; static Val* empty_connection_table() { - auto tbl_index = make_intrusive(IntrusivePtr{NewRef{}, conn_id}); - tbl_index->Append({NewRef{}, conn_id}); + auto tbl_index = make_intrusive(zeek::vars::conn_id); + tbl_index->Append(zeek::vars::conn_id); auto tbl_type = make_intrusive(std::move(tbl_index), - IntrusivePtr{NewRef{}, connection_type}); + zeek::vars::connection_type); return new TableVal(std::move(tbl_type)); } -static RecordVal* get_conn_id_val(const Connection* conn) +static IntrusivePtr get_conn_id_val(const Connection* conn) { - RecordVal* v = new RecordVal(conn_id); + auto v = make_intrusive(zeek::vars::conn_id); v->Assign(0, make_intrusive(conn->OrigAddr())); v->Assign(1, val_mgr->Port(ntohs(conn->OrigPort()), conn->ConnTransport())); v->Assign(2, make_intrusive(conn->RespAddr())); @@ -62,22 +62,22 @@ void File::StaticInit() if ( id_idx != -1 ) return; - id_idx = Idx("id", fa_file_type); - parent_id_idx = Idx("parent_id", fa_file_type); - source_idx = Idx("source", fa_file_type); - is_orig_idx = Idx("is_orig", fa_file_type); - conns_idx = Idx("conns", fa_file_type); - last_active_idx = Idx("last_active", fa_file_type); - seen_bytes_idx = Idx("seen_bytes", fa_file_type); - total_bytes_idx = Idx("total_bytes", fa_file_type); - missing_bytes_idx = Idx("missing_bytes", fa_file_type); - overflow_bytes_idx = Idx("overflow_bytes", fa_file_type); - timeout_interval_idx = Idx("timeout_interval", fa_file_type); - bof_buffer_size_idx = Idx("bof_buffer_size", fa_file_type); - bof_buffer_idx = Idx("bof_buffer", fa_file_type); - meta_mime_type_idx = Idx("mime_type", fa_metadata_type); - meta_mime_types_idx = Idx("mime_types", fa_metadata_type); - meta_inferred_idx = Idx("inferred", fa_metadata_type); + id_idx = Idx("id", zeek::vars::fa_file_type); + parent_id_idx = Idx("parent_id", zeek::vars::fa_file_type); + source_idx = Idx("source", zeek::vars::fa_file_type); + is_orig_idx = Idx("is_orig", zeek::vars::fa_file_type); + conns_idx = Idx("conns", zeek::vars::fa_file_type); + last_active_idx = Idx("last_active", zeek::vars::fa_file_type); + seen_bytes_idx = Idx("seen_bytes", zeek::vars::fa_file_type); + total_bytes_idx = Idx("total_bytes", zeek::vars::fa_file_type); + missing_bytes_idx = Idx("missing_bytes", zeek::vars::fa_file_type); + overflow_bytes_idx = Idx("overflow_bytes", zeek::vars::fa_file_type); + timeout_interval_idx = Idx("timeout_interval", zeek::vars::fa_file_type); + bof_buffer_size_idx = Idx("bof_buffer_size", zeek::vars::fa_file_type); + bof_buffer_idx = Idx("bof_buffer", zeek::vars::fa_file_type); + meta_mime_type_idx = Idx("mime_type", zeek::vars::fa_metadata_type); + meta_mime_types_idx = Idx("mime_types", zeek::vars::fa_metadata_type); + meta_inferred_idx = Idx("inferred", zeek::vars::fa_metadata_type); } File::File(const std::string& file_id, const std::string& source_name, Connection* conn, @@ -91,7 +91,7 @@ File::File(const std::string& file_id, const std::string& source_name, Connectio DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Creating new File object", file_id.c_str()); - val = new RecordVal(fa_file_type); + val = new RecordVal(zeek::vars::fa_file_type); val->Assign(id_idx, make_intrusive(file_id.c_str())); SetSource(source_name); @@ -137,16 +137,12 @@ bool File::UpdateConnectionFields(Connection* conn, bool is_orig) val->Assign(conns_idx, conns); } - Val* idx = get_conn_id_val(conn); + auto idx = get_conn_id_val(conn); - if ( conns->AsTableVal()->Lookup(idx) ) - { - Unref(idx); + if ( conns->AsTableVal()->Lookup(idx.get()) ) return false; - } - conns->AsTableVal()->Assign(idx, conn->ConnVal()); - Unref(idx); + conns->AsTableVal()->Assign(idx.get(), conn->ConnVal()); return true; } @@ -299,7 +295,7 @@ bool File::SetMime(const std::string& mime_type) if ( ! FileEventAvailable(file_sniff) ) return false; - auto meta = make_intrusive(fa_metadata_type); + auto meta = make_intrusive(zeek::vars::fa_metadata_type); meta->Assign(meta_mime_type_idx, make_intrusive(mime_type)); meta->Assign(meta_inferred_idx, val_mgr->False()); @@ -332,7 +328,7 @@ void File::InferMetadata() len = std::min(len, LookupFieldDefaultCount(bof_buffer_size_idx)); file_mgr->DetectMIME(data, len, &matches); - auto meta = make_intrusive(fa_metadata_type); + auto meta = make_intrusive(zeek::vars::fa_metadata_type); if ( ! matches.empty() ) { diff --git a/src/file_analysis/File.h b/src/file_analysis/File.h index 97e6e0817a..82f286f70e 100644 --- a/src/file_analysis/File.h +++ b/src/file_analysis/File.h @@ -323,6 +323,8 @@ protected: * @return the field offset in #val record corresponding to \a field_name. */ static int Idx(const std::string& field_name, const RecordType* type); + static int Idx(const std::string& field_name, const IntrusivePtr& type) + { return Idx(field_name, type.get()); } /** * Initializes static member. diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index bc18568444..df950416cb 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -499,12 +499,12 @@ string Manager::DetectMIME(const u_char* data, uint64_t len) const IntrusivePtr file_analysis::GenMIMEMatchesVal(const RuleMatcher::MIME_Matches& m) { - auto rval = make_intrusive(IntrusivePtr{NewRef{}, mime_matches}); + auto rval = make_intrusive(zeek::vars::mime_matches); for ( RuleMatcher::MIME_Matches::const_iterator it = m.begin(); it != m.end(); ++it ) { - auto element = make_intrusive(mime_match); + auto element = make_intrusive(zeek::vars::mime_match); for ( set::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2 ) diff --git a/src/file_analysis/analyzer/entropy/Entropy.cc b/src/file_analysis/analyzer/entropy/Entropy.cc index ab96947d30..1e605c9883 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.cc +++ b/src/file_analysis/analyzer/entropy/Entropy.cc @@ -60,7 +60,7 @@ void Entropy::Finalize() montepi = scc = ent = mean = chisq = 0.0; entropy->Get(&ent, &chisq, &mean, &montepi, &scc); - auto ent_result = make_intrusive(entropy_test_result); + auto ent_result = make_intrusive(zeek::vars::entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); ent_result->Assign(2, make_intrusive(mean, TYPE_DOUBLE)); diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index 95dfa436a9..30f484b1b3 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -11,7 +11,7 @@ VectorVal* process_rvas(const RVAS* rvas); %code{ VectorVal* process_rvas(const RVAS* rva_table) { - auto rvas = make_intrusive(zeek::lookup_type("index_vec")); + auto rvas = make_intrusive(zeek::vars::index_vec); for ( uint16 i=0; i < rva_table->rvas()->size(); ++i ) rvas->Assign(i, val_mgr->Count((*rva_table->rvas())[i]->size())); @@ -26,7 +26,7 @@ refine flow File += { function characteristics_to_bro(c: uint32, len: uint8): TableVal %{ uint64 mask = (len==16) ? 0xFFFF : 0xFFFFFFFF; - TableVal* char_set = new TableVal(zeek::lookup_type("count_set")); + TableVal* char_set = new TableVal(zeek::vars::count_set); for ( uint16 i=0; i < len; ++i ) { if ( ((c >> i) & 0x1) == 1 ) diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 8c98ed179b..afd37d4958 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -367,21 +367,21 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) { case GEN_DNS: if ( names == nullptr ) - names = new VectorVal(zeek::lookup_type("string_vec")); + names = new VectorVal(zeek::vars::string_vec); names->Assign(names->Size(), bs); break; case GEN_URI: if ( uris == nullptr ) - uris = new VectorVal(zeek::lookup_type("string_vec")); + uris = new VectorVal(zeek::vars::string_vec); uris->Assign(uris->Size(), bs); break; case GEN_EMAIL: if ( emails == nullptr ) - emails = new VectorVal(zeek::lookup_type("string_vec")); + emails = new VectorVal(zeek::vars::string_vec); emails->Assign(emails->Size(), bs); break; diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index 52033ca5d0..20c4d1bc8c 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -593,8 +593,8 @@ void Packet::ProcessLayer2() IntrusivePtr Packet::ToRawPktHdrVal() const { - auto pkt_hdr = make_intrusive(raw_pkt_hdr_type); - RecordVal* l2_hdr = new RecordVal(l2_hdr_type); + auto pkt_hdr = make_intrusive(zeek::vars::raw_pkt_hdr_type); + RecordVal* l2_hdr = new RecordVal(zeek::vars::l2_hdr_type); bool is_ethernet = link_type == DLT_EN10MB; diff --git a/src/reporter.bif b/src/reporter.bif index e37691da5f..46084d13d3 100644 --- a/src/reporter.bif +++ b/src/reporter.bif @@ -153,7 +153,7 @@ function Reporter::file_weird%(name: string, f: fa_file, addl: string &default=" ## Returns: Current weird sampling whitelist function Reporter::get_weird_sampling_whitelist%(%): string_set %{ - auto set = make_intrusive(IntrusivePtr{NewRef{}, string_set}); + auto set = make_intrusive(zeek::vars::string_set); for ( auto el : reporter->GetWeirdSamplingWhitelist() ) { auto idx = make_intrusive(el); diff --git a/src/strings.bif b/src/strings.bif index 412b065065..bef95c9bad 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -259,7 +259,7 @@ static IntrusivePtr do_split_string(StringVal* str_val, Val* do_split(StringVal* str_val, RE_Matcher* re, int incl_sep, int max_num_sep) { - TableVal* a = new TableVal({NewRef{}, string_array}); + TableVal* a = new TableVal(zeek::vars::string_array); const u_char* s = str_val->Bytes(); int n = str_val->Len(); const u_char* end_of_s = s + n; @@ -713,8 +713,7 @@ function str_split%(s: string, idx: index_vec%): string_vec indices[i] = (*idx_v)[i]->AsCount(); BroString::Vec* result = s->AsString()->Split(indices); - auto result_v = make_intrusive( - zeek::lookup_type("string_vec")); + auto result_v = make_intrusive(zeek::vars::string_vec); if ( result ) { @@ -909,7 +908,7 @@ function safe_shell_quote%(source: string%): string ## .. zeek:see: find_last strstr function find_all%(str: string, re: pattern%) : string_set %{ - auto a = make_intrusive(IntrusivePtr{NewRef{}, string_set}); + auto a = make_intrusive(zeek::vars::string_set); const u_char* s = str->Bytes(); const u_char* e = s + str->Len(); diff --git a/src/zeek.bif b/src/zeek.bif index 1876dc741e..4ecc51d9e9 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -30,7 +30,6 @@ #include "Hash.h" using namespace std; -using namespace zeek; TableType* var_sizes; @@ -1052,7 +1051,7 @@ function find_entropy%(data: string%): entropy_test_result e.Feed(data->Bytes(), data->Len()); e.Get(&ent, &chisq, &mean, &montepi, &scc); - auto ent_result = make_intrusive(entropy_test_result); + auto ent_result = make_intrusive(zeek::vars::entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); ent_result->Assign(2, make_intrusive(mean, TYPE_DOUBLE)); @@ -1103,7 +1102,7 @@ function entropy_test_finish%(handle: opaque of entropy%): entropy_test_result montepi = scc = ent = mean = chisq = 0.0; static_cast(handle)->Get(&ent, &chisq, &mean, &montepi, &scc); - auto ent_result = make_intrusive(entropy_test_result); + auto ent_result = make_intrusive(zeek::vars::entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); ent_result->Assign(2, make_intrusive(mean, TYPE_DOUBLE)); @@ -1470,7 +1469,7 @@ function sort%(v: any, ...%) : any ## .. zeek:see:: sort function order%(v: any, ...%) : index_vec %{ - auto result_v = make_intrusive(lookup_type("index_vec")); + auto result_v = make_intrusive(zeek::vars::index_vec); if ( v->GetType()->Tag() != TYPE_VECTOR ) { @@ -1823,10 +1822,9 @@ function zeek_version%(%): string ## Returns: A string vector with the field names of *rt*. function record_type_to_vector%(rt: string%): string_vec %{ - auto result = - make_intrusive(lookup_type("string_vec")); + auto result = make_intrusive(zeek::vars::string_vec); - RecordType* type = lookup_type(rt->CheckString())->AsRecordType(); + RecordType* type = zeek::lookup_type(rt->CheckString())->AsRecordType(); for ( int i = 0; i < type->NumFields(); ++i ) result->Assign(i+1, make_intrusive(type->FieldName(i))); @@ -1853,7 +1851,7 @@ function type_name%(t: any%): string ## Returns: list of command-line arguments (``argv``) used to run Zeek. function zeek_args%(%): string_vec %{ - auto sv = lookup_type("string_vec"); + auto sv = zeek::vars::string_vec; auto rval = make_intrusive(std::move(sv)); for ( auto i = 0; i < bro_argc; ++i ) @@ -1891,7 +1889,7 @@ function reading_traces%(%): bool ## .. zeek:see:: reading_live_traffic reading_traces function packet_source%(%): PacketSource %{ - auto ps_type = lookup_type("PacketSource")->AsRecordType(); + auto ps_type = zeek::lookup_type("PacketSource")->AsRecordType(); auto ps = iosource_mgr->GetPktSrc(); auto r = make_intrusive(ps_type); @@ -1941,13 +1939,13 @@ function global_sizes%(%): var_sizes ## .. zeek:see:: global_sizes function global_ids%(%): id_table %{ - auto ids = make_intrusive(IntrusivePtr{NewRef{}, id_table}); + auto ids = make_intrusive(zeek::vars::id_table); const auto& globals = global_scope()->Vars(); for ( const auto& global : globals ) { ID* id = global.second.get(); - auto rec = make_intrusive(script_id); + auto rec = make_intrusive(zeek::vars::script_id); rec->Assign(0, make_intrusive(type_name(id->GetType()->Tag()))); rec->Assign(1, val_mgr->Bool(id->IsExport())); rec->Assign(2, val_mgr->Bool(id->IsConst())); @@ -1999,8 +1997,7 @@ function record_fields%(rec: any%): record_field_table if ( ! id || ! id->IsType() || id->GetType()->Tag() != TYPE_RECORD ) { reporter->Error("record_fields string argument does not name a record type"); - auto tt = lookup_type("record_field_table"); - return make_intrusive(std::move(tt)); + return make_intrusive(zeek::vars::record_field_table); } return id->GetType()->AsRecordType()->GetRecordFieldsVal(); @@ -2186,7 +2183,7 @@ function is_v6_subnet%(s: subnet%): bool ## Returns: The vector of addresses contained in the routing header data. function routing0_data_to_addrs%(s: string%): addr_vec %{ - auto rval = make_intrusive(lookup_type("addr_vec")); + auto rval = make_intrusive(zeek::lookup_type("addr_vec")); int len = s->Len(); const u_char* bytes = s->Bytes(); @@ -2217,7 +2214,7 @@ function routing0_data_to_addrs%(s: string%): addr_vec ## .. zeek:see:: counts_to_addr function addr_to_counts%(a: addr%): index_vec %{ - auto rval = make_intrusive(lookup_type("index_vec")); + auto rval = make_intrusive(zeek::vars::index_vec); const uint32_t* bytes; int len = a->AsAddr().GetBytes(&bytes); @@ -3211,16 +3208,16 @@ static IntrusivePtr map_conn_type(TransportProto tp) { switch ( tp ) { case TRANSPORT_UNKNOWN: - return transport_proto->GetVal(0); + return zeek::vars::transport_proto->GetVal(0); case TRANSPORT_TCP: - return transport_proto->GetVal(1); + return zeek::vars::transport_proto->GetVal(1); case TRANSPORT_UDP: - return transport_proto->GetVal(2); + return zeek::vars::transport_proto->GetVal(2); case TRANSPORT_ICMP: - return transport_proto->GetVal(3); + return zeek::vars::transport_proto->GetVal(3); default: reporter->InternalError("bad connection type in map_conn_type()"); @@ -3246,7 +3243,7 @@ function get_conn_transport_proto%(cid: conn_id%): transport_proto if ( ! c ) { builtin_error("unknown connection id in get_conn_transport_proto()", cid); - return transport_proto->GetVal(0); + return zeek::vars::transport_proto->GetVal(0); } return map_conn_type(c->ConnTransport()); @@ -3298,20 +3295,20 @@ function lookup_connection%(cid: conn_id%): connection builtin_error("connection ID not a known connection", cid); // Return a dummy connection record. - auto c = make_intrusive(connection_type); + auto c = make_intrusive(zeek::vars::connection_type); - auto id_val = make_intrusive(conn_id); + auto id_val = make_intrusive(zeek::vars::conn_id); id_val->Assign(0, make_intrusive((unsigned int) 0)); id_val->Assign(1, val_mgr->Port(ntohs(0), TRANSPORT_UDP)); id_val->Assign(2, make_intrusive((unsigned int) 0)); id_val->Assign(3, val_mgr->Port(ntohs(0), TRANSPORT_UDP)); c->Assign(0, std::move(id_val)); - auto orig_endp = make_intrusive(endpoint); + auto orig_endp = make_intrusive(zeek::vars::endpoint); orig_endp->Assign(0, val_mgr->Count(0)); orig_endp->Assign(1, val_mgr->Count(int(0))); - auto resp_endp = make_intrusive(endpoint); + auto resp_endp = make_intrusive(zeek::vars::endpoint); resp_endp->Assign(0, val_mgr->Count(0)); resp_endp->Assign(1, val_mgr->Count(int(0))); @@ -3320,7 +3317,7 @@ function lookup_connection%(cid: conn_id%): connection c->Assign(3, make_intrusive(network_time, TYPE_TIME)); c->Assign(4, make_intrusive(0.0, TYPE_INTERVAL)); - c->Assign(5, make_intrusive(IntrusivePtr{NewRef{}, string_set})); // service + c->Assign(5, make_intrusive(zeek::vars::string_set)); // service c->Assign(6, val_mgr->EmptyString()); // history return c; @@ -3383,7 +3380,7 @@ function dump_current_packet%(file_name: string%) : bool function get_current_packet%(%) : pcap_packet %{ const Packet* p; - auto pkt = make_intrusive(pcap_packet); + auto pkt = make_intrusive(zeek::vars::pcap_packet); if ( ! current_pktsrc || ! current_pktsrc->GetCurrentPacket(&p) ) @@ -3423,7 +3420,7 @@ function get_current_packet_header%(%) : raw_pkt_hdr return p->ToRawPktHdrVal(); } - auto hdr = make_intrusive(raw_pkt_hdr_type); + auto hdr = make_intrusive(zeek::vars::raw_pkt_hdr_type); return hdr; %} @@ -3993,7 +3990,7 @@ function mmdb_open_asn_db%(f: string%) : bool ## .. zeek:see:: lookup_asn function lookup_location%(a: addr%) : geo_location %{ - auto location = make_intrusive(geo_location); + auto location = make_intrusive(zeek::vars::geo_location); #ifdef USE_GEOIP mmdb_check_loc(); @@ -4624,7 +4621,7 @@ function rotate_file%(f: file%): rotate_info return info; // Record indicating error. - info = make_intrusive(rotate_info); + info = make_intrusive(zeek::vars::rotate_info); info->Assign(0, val_mgr->EmptyString()); info->Assign(1, val_mgr->EmptyString()); info->Assign(2, make_intrusive(0.0, TYPE_TIME)); @@ -4643,7 +4640,7 @@ function rotate_file%(f: file%): rotate_info ## .. zeek:see:: rotate_file calc_next_rotate function rotate_file_by_name%(f: string%): rotate_info %{ - auto info = make_intrusive(rotate_info); + auto info = make_intrusive(zeek::vars::rotate_info); bool is_pkt_dumper = false; bool is_addl_pkt_dumper = false; From d34b24e77660169ca18b38aa9e17a1d90e796b43 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 12 May 2020 00:01:40 -0700 Subject: [PATCH 045/151] Deprecate global Val pointers in NetVar.h All of these have fairly niche uses, so better maintained as lookup/static closer to the usage site. --- src/Anon.cc | 27 ++++++++++++-- src/NetVar.cc | 38 -------------------- src/NetVar.h | 21 +++++++++++ src/Sessions.cc | 2 ++ src/Var.h | 12 +++++++ src/analyzer/Manager.cc | 4 +++ src/analyzer/protocol/dns/DNS.cc | 3 ++ src/analyzer/protocol/tcp/TCP_Reassembler.cc | 4 ++- src/analyzer/protocol/udp/UDP.cc | 3 ++ src/logging/Manager.cc | 8 ++--- src/probabilistic/Hasher.cc | 5 ++- src/zeek-setup.cc | 1 + src/zeek.bif | 4 +-- 13 files changed, 83 insertions(+), 49 deletions(-) diff --git a/src/Anon.cc b/src/Anon.cc index 1d92892311..96b8d5473c 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -10,6 +10,8 @@ #include "Val.h" #include "NetVar.h" #include "Reporter.h" +#include "Scope.h" +#include "ID.h" AnonymizeIPAddr* ip_anonymizer[NUM_ADDR_ANONYMIZATION_METHODS] = {nullptr}; @@ -354,6 +356,10 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::find_node(ipaddr32_t a) return nullptr; } +static IntrusivePtr anon_preserve_orig_addr; +static IntrusivePtr anon_preserve_resp_addr; +static IntrusivePtr anon_preserve_other_addr; + void init_ip_addr_anonymizers() { ip_anonymizer[KEEP_ORIG_ADDR] = nullptr; @@ -361,6 +367,21 @@ void init_ip_addr_anonymizers() ip_anonymizer[RANDOM_MD5] = new AnonymizeIPAddr_RandomMD5(); ip_anonymizer[PREFIX_PRESERVING_A50] = new AnonymizeIPAddr_A50(); ip_anonymizer[PREFIX_PRESERVING_MD5] = new AnonymizeIPAddr_PrefixMD5(); + + auto id = global_scope()->Lookup("preserve_orig_addr"); + + if ( id ) + anon_preserve_orig_addr = cast_intrusive(id->GetVal()); + + id = global_scope()->Lookup("preserve_resp_addr"); + + if ( id ) + anon_preserve_resp_addr = cast_intrusive(id->GetVal()); + + id = global_scope()->Lookup("preserve_other_addr"); + + if ( id ) + anon_preserve_other_addr = cast_intrusive(id->GetVal()); } ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl) @@ -372,17 +393,17 @@ ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl) switch ( cl ) { case ORIG_ADDR: // client address - preserve_addr = preserve_orig_addr; + preserve_addr = anon_preserve_orig_addr.get(); method = orig_addr_anonymization; break; case RESP_ADDR: // server address - preserve_addr = preserve_resp_addr; + preserve_addr = anon_preserve_resp_addr.get(); method = resp_addr_anonymization; break; default: - preserve_addr = preserve_other_addr; + preserve_addr = anon_preserve_other_addr.get(); method = other_addr_anonymization; break; } diff --git a/src/NetVar.cc b/src/NetVar.cc index 18b0f9f6d5..2b96fb7f4b 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -205,11 +205,6 @@ void init_general_global_var() table_expire_delay = opt_internal_double("table_expire_delay"); table_incremental_step = opt_internal_int("table_incremental_step"); - log_rotate_base_time = opt_internal_string("log_rotate_base_time"); - - peer_description = - zeek::lookup_val("peer_description")->AsStringVal(); - packet_filter_default = opt_internal_int("packet_filter_default"); sig_max_group_size = opt_internal_int("sig_max_group_size"); @@ -219,15 +214,8 @@ void init_general_global_var() suppress_local_output = opt_internal_int("suppress_local_output"); - trace_output_file = zeek::lookup_val("trace_output_file")->AsStringVal(); - record_all_packets = opt_internal_int("record_all_packets"); - cmd_line_bpf_filter = - zeek::lookup_val("cmd_line_bpf_filter")->AsStringVal(); - - global_hash_seed = opt_internal_string("global_hash_seed"); - bits_per_uid = opt_internal_unsigned("bits_per_uid"); } @@ -273,26 +261,11 @@ void init_net_var() tcp_storm_interarrival_thresh = opt_internal_double("tcp_storm_interarrival_thresh"); - tcp_reassembler_ports_orig = - zeek::lookup_val("tcp_reassembler_ports_orig")->AsTableVal(); - tcp_reassembler_ports_resp = - zeek::lookup_val("tcp_reassembler_ports_resp")->AsTableVal(); - - tcp_content_delivery_ports_orig = - zeek::lookup_val("tcp_content_delivery_ports_orig")->AsTableVal(); - tcp_content_delivery_ports_resp = - zeek::lookup_val("tcp_content_delivery_ports_resp")->AsTableVal(); tcp_content_deliver_all_orig = bool(zeek::lookup_val("tcp_content_deliver_all_orig")->AsBool()); tcp_content_deliver_all_resp = bool(zeek::lookup_val("tcp_content_deliver_all_resp")->AsBool()); - udp_content_delivery_ports_orig = - zeek::lookup_val("udp_content_delivery_ports_orig")->AsTableVal(); - udp_content_delivery_ports_resp = - zeek::lookup_val("udp_content_delivery_ports_resp")->AsTableVal(); - udp_content_ports = - zeek::lookup_val("udp_content_ports")->AsTableVal(); udp_content_deliver_all_orig = bool(zeek::lookup_val("udp_content_deliver_all_orig")->AsBool()); udp_content_deliver_all_resp = @@ -313,28 +286,20 @@ void init_net_var() http_entity_data_delivery_size = opt_internal_int("http_entity_data_delivery_size"); truncate_http_URI = opt_internal_int("truncate_http_URI"); - dns_skip_auth = zeek::lookup_val("dns_skip_auth")->AsTableVal(); - dns_skip_addl = zeek::lookup_val("dns_skip_addl")->AsTableVal(); dns_skip_all_auth = opt_internal_int("dns_skip_all_auth"); dns_skip_all_addl = opt_internal_int("dns_skip_all_addl"); dns_max_queries = opt_internal_int("dns_max_queries"); stp_delta = opt_internal_double("stp_delta"); stp_idle_min = opt_internal_double("stp_idle_min"); - stp_skip_src = zeek::lookup_val("stp_skip_src")->AsTableVal(); orig_addr_anonymization = opt_internal_int("orig_addr_anonymization"); resp_addr_anonymization = opt_internal_int("resp_addr_anonymization"); other_addr_anonymization = opt_internal_int("other_addr_anonymization"); - preserve_orig_addr = opt_internal_table("preserve_orig_addr"); - preserve_resp_addr = opt_internal_table("preserve_resp_addr"); - preserve_other_addr = opt_internal_table("preserve_other_addr"); - connection_status_update_interval = opt_internal_double("connection_status_update_interval"); - profiling_file = zeek::lookup_val("profiling_file").get(); expensive_profiling_multiple = opt_internal_int("expensive_profiling_multiple"); profiling_interval = opt_internal_double("profiling_interval"); @@ -342,7 +307,6 @@ void init_net_var() pkt_profile_mode = opt_internal_int("pkt_profile_mode"); pkt_profile_freq = opt_internal_double("pkt_profile_freq"); - pkt_profile_file = zeek::lookup_val("pkt_profile_file").get(); load_sample_freq = opt_internal_int("load_sample_freq"); @@ -355,8 +319,6 @@ void init_net_var() dpd_late_match_stop = opt_internal_int("dpd_late_match_stop"); dpd_ignore_ports = opt_internal_int("dpd_ignore_ports"); - likely_server_ports = zeek::lookup_val("likely_server_ports")->AsTableVal(); - timer_mgr_inactivity_timeout = opt_internal_double("timer_mgr_inactivity_timeout"); } diff --git a/src/NetVar.h b/src/NetVar.h index dbf6b31c1d..1053569379 100644 --- a/src/NetVar.h +++ b/src/NetVar.h @@ -88,16 +88,23 @@ extern double icmp_inactivity_timeout; extern int tcp_storm_thresh; extern double tcp_storm_interarrival_thresh; +[[deprecated("Remove in v4.1.")]] extern TableVal* tcp_reassembler_ports_orig; +[[deprecated("Remove in v4.1.")]] extern TableVal* tcp_reassembler_ports_resp; +[[deprecated("Remove in v4.1.")]] extern TableVal* tcp_content_delivery_ports_orig; +[[deprecated("Remove in v4.1.")]] extern TableVal* tcp_content_delivery_ports_resp; extern bool tcp_content_deliver_all_orig; extern bool tcp_content_deliver_all_resp; +[[deprecated("Remove in v4.1.")]] extern TableVal* udp_content_delivery_ports_orig; +[[deprecated("Remove in v4.1.")]] extern TableVal* udp_content_delivery_ports_resp; +[[deprecated("Remove in v4.1.")]] extern TableVal* udp_content_ports; extern bool udp_content_deliver_all_orig; extern bool udp_content_deliver_all_resp; @@ -153,7 +160,9 @@ extern RecordType* dns_dnskey_rr; extern RecordType* dns_nsec3_rr; [[deprecated("Remove in v4.1. Use zeek::vars::dns_ds_rr.")]] extern RecordType* dns_ds_rr; +[[deprecated("Remove in v4.1.")]] extern TableVal* dns_skip_auth; +[[deprecated("Remove in v4.1.")]] extern TableVal* dns_skip_addl; extern int dns_skip_all_auth; extern int dns_skip_all_addl; @@ -161,6 +170,7 @@ extern int dns_max_queries; extern double stp_delta; extern double stp_idle_min; +[[deprecated("Remove in v4.1.")]] extern TableVal* stp_skip_src; extern double table_expire_interval; @@ -169,18 +179,24 @@ extern int table_incremental_step; extern int orig_addr_anonymization, resp_addr_anonymization; extern int other_addr_anonymization; +[[deprecated("Remove in v4.1.")]] extern TableVal* preserve_orig_addr; +[[deprecated("Remove in v4.1.")]] extern TableVal* preserve_resp_addr; +[[deprecated("Remove in v4.1.")]] extern TableVal* preserve_other_addr; extern double connection_status_update_interval; [[deprecated("Remove in v4.1. Use zeek::vars::rotate_info.")]] extern RecordType* rotate_info; +[[deprecated("Remove in v4.1.")]] extern StringVal* log_rotate_base_time; +[[deprecated("Remove in v4.1.")]] extern StringVal* peer_description; +[[deprecated("Remove in v4.1.")]] extern Val* profiling_file; extern double profiling_interval; extern int expensive_profiling_multiple; @@ -188,6 +204,7 @@ extern int expensive_profiling_multiple; extern int segment_profiling; extern int pkt_profile_mode; extern double pkt_profile_freq; +[[deprecated("Remove in v4.1.")]] extern Val* pkt_profile_file; extern int load_sample_freq; @@ -207,6 +224,7 @@ extern int dpd_match_only_beginning; extern int dpd_late_match_stop; extern int dpd_ignore_ports; +[[deprecated("Remove in v4.1.")]] extern TableVal* likely_server_ports; extern int check_for_unused_event_handlers; @@ -215,6 +233,7 @@ extern int suppress_local_output; extern double timer_mgr_inactivity_timeout; +[[deprecated("Remove in v4.1.")]] extern StringVal* trace_output_file; extern int record_all_packets; @@ -232,8 +251,10 @@ extern RecordType* call_argument; [[deprecated("Remove in v4.1. Use zeek::vars::call_argument_vector.")]] extern VectorType* call_argument_vector; +[[deprecated("Remove in v4.1.")]] extern StringVal* cmd_line_bpf_filter; +[[deprecated("Remove in v4.1.")]] extern StringVal* global_hash_seed; extern bro_uint_t bits_per_uid; diff --git a/src/Sessions.cc b/src/Sessions.cc index 3c58a4427e..fd1d633ac0 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -81,6 +81,7 @@ NetSessions::NetSessions() dump_this_packet = false; num_packets_processed = 0; + static auto pkt_profile_file = zeek::lookup_val("pkt_profile_file"); if ( pkt_profile_mode && pkt_profile_freq > 0 && pkt_profile_file ) pkt_profiler = new PacketProfiler(pkt_profile_mode, @@ -1218,6 +1219,7 @@ bool NetSessions::IsLikelyServerPort(uint32_t port, TransportProto proto) const if ( ! have_cache ) { + auto likely_server_ports = zeek::lookup_val("likely_server_ports"); auto lv = likely_server_ports->ToPureListVal(); for ( int i = 0; i < lv->Length(); i++ ) port_cache.insert(lv->Idx(i)->InternalUnsigned()); diff --git a/src/Var.h b/src/Var.h index 0d495f92b4..13cdf12716 100644 --- a/src/Var.h +++ b/src/Var.h @@ -52,7 +52,9 @@ extern Val* opt_internal_val(const char* name); // returns nil if not defined extern double opt_internal_double(const char* name); extern bro_int_t opt_internal_int(const char* name); extern bro_uint_t opt_internal_unsigned(const char* name); +[[deprecated("Remove in v4.1. Use lookup_ID() or zeek::lookup_val().")]] extern StringVal* opt_internal_string(const char* name); +[[deprecated("Remove in v4.1. Use lookup_ID() or zeek::lookup_val().")]] extern TableVal* opt_internal_table(const char* name); // nil if not defined [[deprecated("Remove in v4.1. Use lookup_ID(), zeek::lookup_val(), and/or TableVal::ToPureListVal().")]] @@ -96,6 +98,16 @@ IntrusivePtr lookup_type(const char* name) */ const IntrusivePtr& lookup_val(const char* name); +/** + * Lookup an ID by its name and return its value (as cast to @c T). + * A fatal occurs if the ID does not exist. + * @param name The identifier name to lookup + * @return The current value of the identifier. + */ +template +IntrusivePtr lookup_val(const char* name) + { return cast_intrusive(lookup_val(name)); } + /** * Lookup an ID by its name and return its value. A fatal occurs if the ID * does not exist or if it is not "const". diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index d605e04d0e..18f2569fda 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -438,6 +438,8 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) if ( tcp_contents && ! reass ) { + static auto tcp_content_delivery_ports_orig = zeek::lookup_val("tcp_content_delivery_ports_orig"); + static auto tcp_content_delivery_ports_resp = zeek::lookup_val("tcp_content_delivery_ports_resp"); const auto& dport = val_mgr->Port(ntohs(conn->RespPort()), TRANSPORT_TCP); if ( ! reass ) @@ -460,6 +462,8 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) uint16_t resp_port = ntohs(conn->RespPort()); if ( resp_port == 22 || resp_port == 23 || resp_port == 513 ) { + static auto stp_skip_src = zeek::lookup_val("stp_skip_src"); + AddrVal src(conn->OrigAddr()); if ( ! stp_skip_src->Lookup(&src) ) tcp->AddChildAnalyzer(new stepping_stone::SteppingStone_Analyzer(conn), false); diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 47d4f8dc27..6ab45052c0 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -91,6 +91,9 @@ void DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) int skip_addl = dns_skip_all_addl; if ( msg.ancount > 0 ) { // We did an answer, so can potentially skip auth/addl. + static auto dns_skip_auth = zeek::lookup_val("dns_skip_auth"); + static auto dns_skip_addl = zeek::lookup_val("dns_skip_addl"); + skip_auth = skip_auth || msg.nscount == 0 || dns_skip_auth->Lookup(&server); skip_addl = skip_addl || msg.arcount == 0 || diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.cc b/src/analyzer/protocol/tcp/TCP_Reassembler.cc index f93647adb2..073bcb7ab6 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.cc +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.cc @@ -42,9 +42,11 @@ TCP_Reassembler::TCP_Reassembler(analyzer::Analyzer* arg_dst_analyzer, if ( ::tcp_contents ) { + static auto tcp_content_delivery_ports_orig = zeek::lookup_val("tcp_content_delivery_ports_orig"); + static auto tcp_content_delivery_ports_resp = zeek::lookup_val("tcp_content_delivery_ports_resp"); const auto& dst_port_val = val_mgr->Port(ntohs(tcp_analyzer->Conn()->RespPort()), TRANSPORT_TCP); - TableVal* ports = IsOrig() ? + const auto& ports = IsOrig() ? tcp_content_delivery_ports_orig : tcp_content_delivery_ports_resp; auto result = ports->Lookup(dst_port_val.get()); diff --git a/src/analyzer/protocol/udp/UDP.cc b/src/analyzer/protocol/udp/UDP.cc index f04f29ddfe..f509d96cef 100644 --- a/src/analyzer/protocol/udp/UDP.cc +++ b/src/analyzer/protocol/udp/UDP.cc @@ -134,6 +134,9 @@ void UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig, if ( udp_contents ) { + static auto udp_content_ports = zeek::lookup_val("udp_content_ports"); + static auto udp_content_delivery_ports_orig = zeek::lookup_val("udp_content_delivery_ports_orig"); + static auto udp_content_delivery_ports_resp = zeek::lookup_val("udp_content_delivery_ports_resp"); bool do_udp_contents = false; const auto& sport_val = val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP); const auto& dport_val = val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 9dfbeff286..45578337cd 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1193,8 +1193,8 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken // Still need to set the WriterInfo's rotation parameters, which we // computed above. - const char* base_time = log_rotate_base_time ? - log_rotate_base_time->AsString()->CheckString() : nullptr; + static auto log_rotate_base_time = zeek::lookup_val("log_rotate_base_time"); + static auto base_time = log_rotate_base_time->AsString()->CheckString(); winfo->info->rotation_interval = winfo->interval; winfo->info->rotation_base = parse_rotate_base_time(base_time); @@ -1453,8 +1453,8 @@ void Manager::InstallRotationTimer(WriterInfo* winfo) if ( ! winfo->open_time ) winfo->open_time = network_time; - const char* base_time = log_rotate_base_time ? - log_rotate_base_time->AsString()->CheckString() : nullptr; + static auto log_rotate_base_time = zeek::lookup_val("log_rotate_base_time"); + static auto base_time = log_rotate_base_time->AsString()->CheckString(); double base = parse_rotate_base_time(base_time); double delta_t = diff --git a/src/probabilistic/Hasher.cc b/src/probabilistic/Hasher.cc index 78f7bb3c72..5a229638dc 100644 --- a/src/probabilistic/Hasher.cc +++ b/src/probabilistic/Hasher.cc @@ -7,6 +7,7 @@ #include #include "NetVar.h" +#include "Var.h" #include "digest.h" #include "highwayhash/sip_hash.h" @@ -22,10 +23,12 @@ Hasher::seed_t Hasher::MakeSeed(const void* data, size_t size) assert(sizeof(tmpseed) == 16); + static auto global_hash_seed = zeek::lookup_val("global_hash_seed"); + if ( data ) hash_update(ctx, data, size); - else if ( global_hash_seed && global_hash_seed->Len() > 0 ) + else if ( global_hash_seed->Len() > 0 ) hash_update(ctx, global_hash_seed->Bytes(), global_hash_seed->Len()); else diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index c895349138..df112cfb68 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -784,6 +784,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, if ( profiling_interval > 0 ) { + const auto& profiling_file = zeek::lookup_val("profiling_file"); profiling_logger = new ProfileLogger(profiling_file->AsFile(), profiling_interval); diff --git a/src/zeek.bif b/src/zeek.bif index 4ecc51d9e9..c64a0a858a 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -4694,8 +4694,8 @@ function rotate_file_by_name%(f: string%): rotate_info ## .. zeek:see:: rotate_file rotate_file_by_name function calc_next_rotate%(i: interval%) : interval %{ - const char* base_time = log_rotate_base_time ? - log_rotate_base_time->AsString()->CheckString() : 0; + static auto log_rotate_base_time = zeek::lookup_val("log_rotate_base_time"); + static auto base_time = log_rotate_base_time->AsString()->CheckString(); double base = parse_rotate_base_time(base_time); return make_intrusive(calc_next_rotate(network_time, i, base), TYPE_INTERVAL); From 9210d443d3d0ae4f269e4dff2357685202213507 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 12 May 2020 16:38:05 -0700 Subject: [PATCH 046/151] Trim the list of "global type pointers" from NetVar.h further Most of them are deprecated now, with usage sites now doing the lookup themselves. --- NEWS | 4 +- src/Conn.cc | 2 +- src/EventHandler.cc | 7 +- src/File.cc | 4 +- src/NetVar.cc | 2 +- src/NetVar.h | 126 +++++------ src/RuleCondition.cc | 3 +- src/RuleMatcher.cc | 4 +- src/Type.cc | 6 +- src/Val.cc | 5 +- src/ZeekVars.cc | 210 +++++++----------- src/ZeekVars.h | 49 +--- src/analyzer/protocol/dns/DNS.cc | 27 ++- src/analyzer/protocol/http/HTTP.cc | 6 +- src/analyzer/protocol/icmp/ICMP.cc | 9 +- src/analyzer/protocol/irc/IRC.cc | 10 +- src/analyzer/protocol/mime/MIME.cc | 6 +- src/analyzer/protocol/rpc/Portmap.cc | 12 +- src/analyzer/protocol/sip/sip-analyzer.pac | 6 +- .../protocol/socks/socks-analyzer.pac | 12 +- src/analyzer/protocol/tcp/TCP.cc | 6 +- src/file_analysis/File.cc | 40 ++-- src/file_analysis/Manager.cc | 6 +- src/file_analysis/analyzer/entropy/Entropy.cc | 3 +- src/iosource/Packet.cc | 7 +- src/zeek.bif | 33 ++- 26 files changed, 290 insertions(+), 315 deletions(-) diff --git a/NEWS b/NEWS index 5c80a4f295..78b674f729 100644 --- a/NEWS +++ b/NEWS @@ -171,8 +171,8 @@ Deprecated Functionality - ``Val::Type()`` is deprecated, use ``Val::GetType``. -- Most global type/value pointers in NetVar.h are deprecated, but there's - analogous ``IntrusivePtr`` in ``zeek::vars``. +- Most global type/value pointers in NetVar.h are deprecated, but one can + still always perform the lookup themselves. Zeek 3.1.0 ========== diff --git a/src/Conn.cc b/src/Conn.cc index 7146191cb0..597e9e81d2 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -346,7 +346,7 @@ const IntrusivePtr& Connection::ConnVal() { if ( ! conn_val ) { - conn_val = make_intrusive(zeek::vars::connection_type); + conn_val = make_intrusive(zeek::vars::connection); TransportProto prot_type = ConnTransport(); diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 95b36e6b48..45d3037650 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -5,6 +5,7 @@ #include "Scope.h" #include "NetVar.h" #include "ID.h" +#include "Var.h" #include "broker/Manager.h" #include "broker/Data.h" @@ -127,7 +128,8 @@ void EventHandler::NewEvent(const zeek::Args& vl) return; RecordType* args = FType()->Args(); - auto vargs = make_intrusive(zeek::vars::call_argument_vector); + static auto call_argument_vector = zeek::lookup_type("call_argument_vector"); + auto vargs = make_intrusive(call_argument_vector); for ( int i = 0; i < args->NumFields(); i++ ) { @@ -135,7 +137,8 @@ void EventHandler::NewEvent(const zeek::Args& vl) const auto& ftype = args->GetFieldType(i); auto fdefault = args->FieldDefault(i); - auto rec = make_intrusive(zeek::vars::call_argument); + static auto call_argument = zeek::lookup_type("call_argument"); + auto rec = make_intrusive(call_argument); rec->Assign(0, make_intrusive(fname)); ODesc d; diff --git a/src/File.cc b/src/File.cc index 7cefb2f9fd..a10305ea00 100644 --- a/src/File.cc +++ b/src/File.cc @@ -29,6 +29,7 @@ #include "Event.h" #include "Reporter.h" #include "Desc.h" +#include "Var.h" std::list> BroFile::open_files; @@ -277,7 +278,8 @@ RecordVal* BroFile::Rotate() if ( f == stdin || f == stdout || f == stderr ) return nullptr; - RecordVal* info = new RecordVal(zeek::vars::rotate_info); + static auto rotate_info = zeek::lookup_type("rotate_info"); + RecordVal* info = new RecordVal(rotate_info); FILE* newf = rotate_file(name, info); if ( ! newf ) diff --git a/src/NetVar.cc b/src/NetVar.cc index 2b96fb7f4b..1c20611d59 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -226,7 +226,7 @@ void init_net_var() #include "reporter.bif.netvar_init" #include "supervisor.bif.netvar_init" - zeek::vars::detail::Init(); + zeek::vars::detail::init(); ignore_checksums = opt_internal_int("ignore_checksums"); partial_connection_ok = opt_internal_int("partial_connection_ok"); diff --git a/src/NetVar.h b/src/NetVar.h index 1053569379..688f28d5c7 100644 --- a/src/NetVar.h +++ b/src/NetVar.h @@ -12,27 +12,27 @@ extern RecordType* conn_id; [[deprecated("Remove in v4.1. Use zeek::vars::endpoint.")]] extern RecordType* endpoint; -[[deprecated("Remove in v4.1. Use zeek::vars::endpoint_stats.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* endpoint_stats; -[[deprecated("Remove in v4.1. Use zeek::vars::connection_type.")]] +[[deprecated("Remove in v4.1. Use zeek::vars::connection.")]] extern RecordType* connection_type; -[[deprecated("Remove in v4.1. Use zeek::vars::fa_file_type.")]] +[[deprecated("Remove in v4.1. Use zeek::vars::fa_file.")]] extern RecordType* fa_file_type; -[[deprecated("Remove in v4.1. Use zeek::vars::fa_metadata_type.")]] +[[deprecated("Remove in v4.1. Use zeek::vars::fa_metadata.")]] extern RecordType* fa_metadata_type; -[[deprecated("Remove in v4.1. Use zeek::vars::icmp_conn.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* icmp_conn; -[[deprecated("Remove in v4.1. Use zeek::vars::icmp_context.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* icmp_context; -[[deprecated("Remove in v4.1. Use zeek::vars::signature_state.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* signature_state; -[[deprecated("Remove in v4.1. Use zeek::vars::SYN_packet.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* SYN_packet; -[[deprecated("Remove in v4.1. Use zeek::vars::pcap_packet.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* pcap_packet; -[[deprecated("Remove in v4.1. Use zeek::vars::raw_pkt_hdr_type.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* raw_pkt_hdr_type; -[[deprecated("Remove in v4.1. Use zeek::vars::l2_hdr_type.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* l2_hdr_type; [[deprecated("Remove in v4.1. Use zeek::vars::transport_proto.")]] extern EnumType* transport_proto; @@ -46,9 +46,9 @@ extern TableType* count_set; extern VectorType* string_vec; [[deprecated("Remove in v4.1. Use zeek::vars::index_vec.")]] extern VectorType* index_vec; -[[deprecated("Remove in v4.1. Use zeek::vars::mime_matches.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern VectorType* mime_matches; -[[deprecated("Remove in v4.1. Use zeek::vars::mime_match.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* mime_match; extern int watchdog_interval; @@ -77,7 +77,7 @@ extern int tcp_max_above_hole_without_any_acks; extern int tcp_excessive_data_without_further_acks; extern int tcp_max_old_segments; -[[deprecated("Remove in v4.1. Use zeek::vars::socks_address.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* socks_address; extern double non_analyzed_lifetime; @@ -88,23 +88,23 @@ extern double icmp_inactivity_timeout; extern int tcp_storm_thresh; extern double tcp_storm_interarrival_thresh; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* tcp_reassembler_ports_orig; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* tcp_reassembler_ports_resp; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* tcp_content_delivery_ports_orig; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* tcp_content_delivery_ports_resp; extern bool tcp_content_deliver_all_orig; extern bool tcp_content_deliver_all_resp; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* udp_content_delivery_ports_orig; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* udp_content_delivery_ports_resp; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* udp_content_ports; extern bool udp_content_deliver_all_orig; extern bool udp_content_deliver_all_resp; @@ -115,54 +115,54 @@ extern double rpc_timeout; extern int mime_segment_length; extern int mime_segment_overlap_length; -[[deprecated("Remove in v4.1. Use zeek::vars::mime_header_rec.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* mime_header_rec; -[[deprecated("Remove in v4.1. Use zeek::vars::mime_header_list.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableType* mime_header_list; extern int http_entity_data_delivery_size; -[[deprecated("Remove in v4.1. Use zeek::vars::http_stats_rec.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* http_stats_rec; -[[deprecated("Remove in v4.1. Use zeek::vars::http_message_stat.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* http_message_stat; extern int truncate_http_URI; -[[deprecated("Remove in v4.1. Use zeek::vars::pm_mapping.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* pm_mapping; -[[deprecated("Remove in v4.1. Use zeek::vars::pm_mappings.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableType* pm_mappings; -[[deprecated("Remove in v4.1. Use zeek::vars::pm_port_request.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* pm_port_request; -[[deprecated("Remove in v4.1. Use zeek::vars::pm_callit_request.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* pm_callit_request; -[[deprecated("Remove in v4.1. Use zeek::vars::geo_location.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* geo_location; -[[deprecated("Remove in v4.1. Use zeek::vars::entropy_test_result.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* entropy_test_result; -[[deprecated("Remove in v4.1. Use zeek::vars::dns_msg.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* dns_msg; -[[deprecated("Remove in v4.1. Use zeek::vars::dns_answer.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* dns_answer; -[[deprecated("Remove in v4.1. Use zeek::vars::dns_soa.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* dns_soa; -[[deprecated("Remove in v4.1. Use zeek::vars::dns_edns_additional.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* dns_edns_additional; -[[deprecated("Remove in v4.1. Use zeek::vars::dns_tsig_additional.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* dns_tsig_additional; -[[deprecated("Remove in v4.1. Use zeek::vars::dns_rrsig_rr.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* dns_rrsig_rr; -[[deprecated("Remove in v4.1. Use zeek::vars::dns_dnskey_rr.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* dns_dnskey_rr; -[[deprecated("Remove in v4.1. Use zeek::vars::dns_nsec3_rr.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* dns_nsec3_rr; -[[deprecated("Remove in v4.1. Use zeek::vars::dns_ds_rr.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* dns_ds_rr; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* dns_skip_auth; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* dns_skip_addl; extern int dns_skip_all_auth; extern int dns_skip_all_addl; @@ -170,7 +170,7 @@ extern int dns_max_queries; extern double stp_delta; extern double stp_idle_min; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* stp_skip_src; extern double table_expire_interval; @@ -179,24 +179,24 @@ extern int table_incremental_step; extern int orig_addr_anonymization, resp_addr_anonymization; extern int other_addr_anonymization; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* preserve_orig_addr; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* preserve_resp_addr; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* preserve_other_addr; extern double connection_status_update_interval; -[[deprecated("Remove in v4.1. Use zeek::vars::rotate_info.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* rotate_info; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern StringVal* log_rotate_base_time; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern StringVal* peer_description; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern Val* profiling_file; extern double profiling_interval; extern int expensive_profiling_multiple; @@ -204,7 +204,7 @@ extern int expensive_profiling_multiple; extern int segment_profiling; extern int pkt_profile_mode; extern double pkt_profile_freq; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern Val* pkt_profile_file; extern int load_sample_freq; @@ -213,9 +213,9 @@ extern int packet_filter_default; extern int sig_max_group_size; -[[deprecated("Remove in v4.1. Use zeek::vars::irc_join_list.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableType* irc_join_list; -[[deprecated("Remove in v4.1. Use zeek::vars::irc_join_info.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* irc_join_info; extern int dpd_reassemble_first_packets; @@ -224,7 +224,7 @@ extern int dpd_match_only_beginning; extern int dpd_late_match_stop; extern int dpd_ignore_ports; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* likely_server_ports; extern int check_for_unused_event_handlers; @@ -233,28 +233,28 @@ extern int suppress_local_output; extern double timer_mgr_inactivity_timeout; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern StringVal* trace_output_file; extern int record_all_packets; -[[deprecated("Remove in v4.1. Use zeek::vars::script_id.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* script_id; -[[deprecated("Remove in v4.1. Use zeek::vars::id_table.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableType* id_table; -[[deprecated("Remove in v4.1. Use zeek::vars::record_field.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* record_field; -[[deprecated("Remove in v4.1. Use zeek::vars::record_field_table.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableType* record_field_table; -[[deprecated("Remove in v4.1. Use zeek::vars::call_argument.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* call_argument; -[[deprecated("Remove in v4.1. Use zeek::vars::call_argument_vector.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern VectorType* call_argument_vector; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern StringVal* cmd_line_bpf_filter; -[[deprecated("Remove in v4.1.")]] +[[deprecated("Remove in v4.1. Perform your own lookup.")]] extern StringVal* global_hash_seed; extern bro_uint_t bits_per_uid; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index b3434088dd..3fb6925039 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -145,8 +145,9 @@ RuleConditionEval::RuleConditionEval(const char* func) if ( f->Yield()->Tag() != TYPE_BOOL ) rules_error("eval function type must yield a 'bool'", func); + static auto signature_state = zeek::lookup_type("signature_state"); TypeList tl; - tl.Append(zeek::vars::signature_state); + tl.Append(signature_state); tl.Append(base_type(TYPE_STRING)); if ( ! f->CheckArgs(tl.Types()) ) diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index fdc9af6471..03c5329597 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -20,6 +20,7 @@ #include "File.h" #include "Reporter.h" #include "module_util.h" +#include "Var.h" using namespace std; @@ -79,7 +80,8 @@ RuleHdrTest::RuleHdrTest(Prot arg_prot, Comp arg_comp, vector arg_v) Val* RuleMatcher::BuildRuleStateValue(const Rule* rule, const RuleEndpointState* state) const { - RecordVal* val = new RecordVal(zeek::vars::signature_state); + static auto signature_state = zeek::lookup_type("signature_state"); + RecordVal* val = new RecordVal(signature_state); val->Assign(0, make_intrusive(rule->ID())); val->Assign(1, state->GetAnalyzer()->ConnVal()); val->Assign(2, val_mgr->Bool(state->is_orig)); diff --git a/src/Type.cc b/src/Type.cc index 2826a741a4..bb3e1c4dd3 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -796,7 +796,9 @@ static string container_type_name(const BroType* ft) IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const { - auto rval = make_intrusive(zeek::lookup_type("record_field_table")); + static auto record_field = zeek::lookup_type("record_field"); + static auto record_field_table = zeek::lookup_type("record_field_table"); + auto rval = make_intrusive(record_field_table); for ( int i = 0; i < NumFields(); ++i ) { @@ -812,7 +814,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const bool logged = (fd->attrs && fd->FindAttr(ATTR_LOG) != nullptr); - auto nr = make_intrusive(zeek::lookup_type("record_field")->AsRecordType()); + auto nr = make_intrusive(record_field); string s = container_type_name(ft.get()); nr->Assign(0, make_intrusive(s)); diff --git a/src/Val.cc b/src/Val.cc index 53e603bbfa..91b6e12007 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -411,12 +411,13 @@ bool Val::WouldOverflow(const BroType* from_type, const BroType* to_type, const IntrusivePtr Val::GetRecordFields() { + static auto record_field_table = zeek::lookup_type("record_field_table"); auto t = GetType().get(); if ( t->Tag() != TYPE_RECORD && t->Tag() != TYPE_TYPE ) { reporter->Error("non-record value/type passed to record_fields"); - return make_intrusive(zeek::lookup_type("record_field_table")); + return make_intrusive(record_field_table); } RecordType* rt = nullptr; @@ -434,7 +435,7 @@ IntrusivePtr Val::GetRecordFields() if ( t->Tag() != TYPE_RECORD ) { reporter->Error("non-record value/type passed to record_fields"); - return make_intrusive(zeek::lookup_type("record_field_table")); + return make_intrusive(record_field_table); } rt = t->AsRecordType(); diff --git a/src/ZeekVars.cc b/src/ZeekVars.cc index 317c265dbc..fc1040efb2 100644 --- a/src/ZeekVars.cc +++ b/src/ZeekVars.cc @@ -3,163 +3,119 @@ #include "ZeekVars.h" #include "Var.h" #include "NetVar.h" +#include "Scope.h" IntrusivePtr zeek::vars::conn_id; IntrusivePtr zeek::vars::endpoint; -IntrusivePtr zeek::vars::endpoint_stats; -IntrusivePtr zeek::vars::connection_type; -IntrusivePtr zeek::vars::fa_file_type; -IntrusivePtr zeek::vars::fa_metadata_type; -IntrusivePtr zeek::vars::icmp_conn; -IntrusivePtr zeek::vars::icmp_context; -IntrusivePtr zeek::vars::signature_state; -IntrusivePtr zeek::vars::SYN_packet; -IntrusivePtr zeek::vars::pcap_packet; -IntrusivePtr zeek::vars::raw_pkt_hdr_type; -IntrusivePtr zeek::vars::l2_hdr_type; +IntrusivePtr zeek::vars::connection; +IntrusivePtr zeek::vars::fa_file; +IntrusivePtr zeek::vars::fa_metadata; IntrusivePtr zeek::vars::transport_proto; IntrusivePtr zeek::vars::string_set; IntrusivePtr zeek::vars::string_array; IntrusivePtr zeek::vars::count_set; IntrusivePtr zeek::vars::string_vec; IntrusivePtr zeek::vars::index_vec; -IntrusivePtr zeek::vars::mime_matches; -IntrusivePtr zeek::vars::mime_match; -IntrusivePtr zeek::vars::socks_address; -IntrusivePtr zeek::vars::mime_header_rec; -IntrusivePtr zeek::vars::mime_header_list; -IntrusivePtr zeek::vars::http_stats_rec; -IntrusivePtr zeek::vars::http_message_stat; -IntrusivePtr zeek::vars::pm_mapping; -IntrusivePtr zeek::vars::pm_mappings; -IntrusivePtr zeek::vars::pm_port_request; -IntrusivePtr zeek::vars::pm_callit_request; -IntrusivePtr zeek::vars::geo_location; -IntrusivePtr zeek::vars::entropy_test_result; -IntrusivePtr zeek::vars::dns_msg; -IntrusivePtr zeek::vars::dns_answer; -IntrusivePtr zeek::vars::dns_soa; -IntrusivePtr zeek::vars::dns_edns_additional; -IntrusivePtr zeek::vars::dns_tsig_additional; -IntrusivePtr zeek::vars::dns_rrsig_rr; -IntrusivePtr zeek::vars::dns_dnskey_rr; -IntrusivePtr zeek::vars::dns_nsec3_rr; -IntrusivePtr zeek::vars::dns_ds_rr; -IntrusivePtr zeek::vars::rotate_info; -IntrusivePtr zeek::vars::irc_join_list; -IntrusivePtr zeek::vars::irc_join_info; -IntrusivePtr zeek::vars::script_id; -IntrusivePtr zeek::vars::id_table; -IntrusivePtr zeek::vars::record_field; -IntrusivePtr zeek::vars::record_field_table; -IntrusivePtr zeek::vars::call_argument; -IntrusivePtr zeek::vars::call_argument_vector; -void zeek::vars::detail::Init() +void zeek::vars::detail::init() { // Types conn_id = zeek::lookup_type("conn_id"); endpoint = zeek::lookup_type("endpoint"); - endpoint_stats = zeek::lookup_type("endpoint_stats"); - connection_type = zeek::lookup_type("connection"); - fa_file_type = zeek::lookup_type("fa_file"); - fa_metadata_type = zeek::lookup_type("fa_metadata"); - icmp_conn = zeek::lookup_type("icmp_conn"); - icmp_context = zeek::lookup_type("icmp_context"); - signature_state = zeek::lookup_type("signature_state"); - SYN_packet = zeek::lookup_type("SYN_packet"); - pcap_packet = zeek::lookup_type("pcap_packet"); - raw_pkt_hdr_type = zeek::lookup_type("raw_pkt_hdr"); - l2_hdr_type = zeek::lookup_type("l2_hdr"); + connection = zeek::lookup_type("connection"); + fa_file = zeek::lookup_type("fa_file"); + fa_metadata = zeek::lookup_type("fa_metadata"); transport_proto = zeek::lookup_type("transport_proto"); string_set = zeek::lookup_type("string_set"); string_array = zeek::lookup_type("string_array"); count_set = zeek::lookup_type("count_set"); string_vec = zeek::lookup_type("string_vec"); index_vec = zeek::lookup_type("index_vec"); - mime_matches = zeek::lookup_type("mime_matches"); - mime_match = zeek::lookup_type("mime_match"); - socks_address = zeek::lookup_type("SOCKS::Address"); - mime_header_rec = zeek::lookup_type("mime_header_rec"); - mime_header_list = zeek::lookup_type("mime_header_list"); - http_stats_rec = zeek::lookup_type("http_stats_rec"); - http_message_stat = zeek::lookup_type("http_message_stat"); - pm_mapping = zeek::lookup_type("pm_mapping"); - pm_mappings = zeek::lookup_type("pm_mappings"); - pm_port_request = zeek::lookup_type("pm_port_request"); - pm_callit_request = zeek::lookup_type("pm_callit_request"); - geo_location = zeek::lookup_type("geo_location"); - entropy_test_result = zeek::lookup_type("entropy_test_result"); - dns_msg = zeek::lookup_type("dns_msg"); - dns_answer = zeek::lookup_type("dns_answer"); - dns_soa = zeek::lookup_type("dns_soa"); - dns_edns_additional = zeek::lookup_type("dns_edns_additional"); - dns_tsig_additional = zeek::lookup_type("dns_tsig_additional"); - dns_rrsig_rr = zeek::lookup_type("dns_rrsig_rr"); - dns_dnskey_rr = zeek::lookup_type("dns_dnskey_rr"); - dns_nsec3_rr = zeek::lookup_type("dns_nsec3_rr"); - dns_ds_rr = zeek::lookup_type("dns_ds_rr"); - rotate_info = zeek::lookup_type("rotate_info"); - irc_join_list = zeek::lookup_type("irc_join_list"); - irc_join_info = zeek::lookup_type("irc_join_info"); - script_id = zeek::lookup_type("script_id"); - id_table = zeek::lookup_type("id_table"); - record_field = zeek::lookup_type("record_field"); - record_field_table = zeek::lookup_type("record_field_table"); - call_argument = zeek::lookup_type("call_argument"); - call_argument_vector = zeek::lookup_type("call_argument_vector"); // Note: to bypass deprecation warnings on setting the legacy globals, // CMake was told to compile this file with -Wno-deprecated-declarations. // Once the legacy globals are removed, that compile flag can go also. ::conn_id = conn_id.get(); ::endpoint = endpoint.get(); - ::endpoint_stats = endpoint_stats.get(); - ::connection_type = connection_type.get(); - ::fa_file_type = fa_file_type.get(); - ::fa_metadata_type = fa_metadata_type.get(); - ::icmp_conn = icmp_conn.get(); - ::icmp_context = icmp_context.get(); - ::signature_state = signature_state.get(); - ::SYN_packet = SYN_packet.get(); - ::pcap_packet = pcap_packet.get(); - ::raw_pkt_hdr_type = raw_pkt_hdr_type.get(); - ::l2_hdr_type = l2_hdr_type.get(); + ::connection_type = connection.get(); + ::fa_file_type = fa_file.get(); + ::fa_metadata_type = fa_metadata.get(); + ::icmp_conn = zeek::lookup_type("icmp_conn")->AsRecordType(); + ::icmp_context = zeek::lookup_type("icmp_context")->AsRecordType(); + ::signature_state = zeek::lookup_type("signature_state")->AsRecordType(); + ::SYN_packet = zeek::lookup_type("SYN_packet")->AsRecordType(); + ::pcap_packet = zeek::lookup_type("pcap_packet")->AsRecordType(); + ::raw_pkt_hdr_type = zeek::lookup_type("raw_pkt_hdr")->AsRecordType(); + ::l2_hdr_type = zeek::lookup_type("l2_hdr")->AsRecordType(); ::transport_proto = transport_proto.get(); ::string_set = string_set.get(); ::string_array = string_array.get(); ::count_set = count_set.get(); ::string_vec = string_vec.get(); ::index_vec = index_vec.get(); - ::mime_matches = mime_matches.get(); - ::mime_match = mime_match.get(); - ::socks_address = socks_address.get(); - ::mime_header_rec = mime_header_rec.get(); - ::mime_header_list = mime_header_list.get(); - ::http_stats_rec = http_stats_rec.get(); - ::http_message_stat = http_message_stat.get(); - ::pm_mapping = pm_mapping.get(); - ::pm_mappings = pm_mappings.get(); - ::pm_port_request = pm_port_request.get(); - ::pm_callit_request = pm_callit_request.get(); - ::geo_location = geo_location.get(); - ::entropy_test_result = entropy_test_result.get(); - ::dns_msg = dns_msg.get(); - ::dns_answer = dns_answer.get(); - ::dns_soa = dns_soa.get(); - ::dns_edns_additional = dns_edns_additional.get(); - ::dns_tsig_additional = dns_tsig_additional.get(); - ::dns_rrsig_rr = dns_rrsig_rr.get(); - ::dns_dnskey_rr = dns_dnskey_rr.get(); - ::dns_nsec3_rr = dns_nsec3_rr.get(); - ::dns_ds_rr = dns_ds_rr.get(); - ::rotate_info = rotate_info.get(); - ::irc_join_list = irc_join_list.get(); - ::irc_join_info = irc_join_info.get(); - ::script_id = script_id.get(); - ::id_table = id_table.get(); - ::record_field = record_field.get(); - ::record_field_table = record_field_table.get(); - ::call_argument = call_argument.get(); - ::call_argument_vector = call_argument_vector.get(); + ::mime_matches = zeek::lookup_type("mime_matches")->AsVectorType(); + ::mime_match = zeek::lookup_type("mime_match")->AsRecordType(); + ::socks_address = zeek::lookup_type("SOCKS::Address")->AsRecordType(); + ::mime_header_rec = zeek::lookup_type("mime_header_rec")->AsRecordType(); + ::mime_header_list = zeek::lookup_type("mime_header_list")->AsTableType(); + ::http_stats_rec = zeek::lookup_type("http_stats_rec")->AsRecordType(); + ::http_message_stat = zeek::lookup_type("http_message_stat")->AsRecordType(); + ::pm_mapping = zeek::lookup_type("pm_mapping")->AsRecordType(); + ::pm_mappings = zeek::lookup_type("pm_mappings")->AsTableType(); + ::pm_port_request = zeek::lookup_type("pm_port_request")->AsRecordType(); + ::pm_callit_request = zeek::lookup_type("pm_callit_request")->AsRecordType(); + ::geo_location = zeek::lookup_type("geo_location")->AsRecordType(); + ::entropy_test_result = zeek::lookup_type("entropy_test_result")->AsRecordType(); + ::dns_msg = zeek::lookup_type("dns_msg")->AsRecordType(); + ::dns_answer = zeek::lookup_type("dns_answer")->AsRecordType(); + ::dns_soa = zeek::lookup_type("dns_soa")->AsRecordType(); + ::dns_edns_additional = zeek::lookup_type("dns_edns_additional")->AsRecordType(); + ::dns_tsig_additional = zeek::lookup_type("dns_tsig_additional")->AsRecordType(); + ::dns_rrsig_rr = zeek::lookup_type("dns_rrsig_rr")->AsRecordType(); + ::dns_dnskey_rr = zeek::lookup_type("dns_dnskey_rr")->AsRecordType(); + ::dns_nsec3_rr = zeek::lookup_type("dns_nsec3_rr")->AsRecordType(); + ::dns_ds_rr = zeek::lookup_type("dns_ds_rr")->AsRecordType(); + ::rotate_info = zeek::lookup_type("rotate_info")->AsRecordType(); + ::irc_join_list = zeek::lookup_type("irc_join_list")->AsTableType(); + ::irc_join_info = zeek::lookup_type("irc_join_info")->AsRecordType(); + ::script_id = zeek::lookup_type("script_id")->AsRecordType(); + ::id_table = zeek::lookup_type("id_table")->AsTableType(); + ::record_field = zeek::lookup_type("record_field")->AsRecordType(); + ::record_field_table = zeek::lookup_type("record_field_table")->AsTableType(); + ::call_argument = zeek::lookup_type("call_argument")->AsRecordType(); + ::call_argument_vector = zeek::lookup_type("call_argument_vector")->AsVectorType(); + + ::log_rotate_base_time = zeek::lookup_val("log_rotate_base_time")->AsStringVal(); + ::pkt_profile_file = zeek::lookup_val("pkt_profile_file").get(); + ::likely_server_ports = zeek::lookup_val("likely_server_ports")->AsTableVal(); + ::tcp_content_delivery_ports_orig = zeek::lookup_val("tcp_content_delivery_ports_orig")->AsTableVal(); + ::tcp_content_delivery_ports_resp = zeek::lookup_val("tcp_content_delivery_ports_resp")->AsTableVal(); + ::stp_skip_src = zeek::lookup_val("stp_skip_src")->AsTableVal(); + ::dns_skip_auth = zeek::lookup_val("dns_skip_auth")->AsTableVal(); + ::dns_skip_addl = zeek::lookup_val("dns_skip_addl")->AsTableVal(); + ::udp_content_ports = zeek::lookup_val("udp_content_ports")->AsTableVal(); + ::udp_content_delivery_ports_orig = zeek::lookup_val("udp_content_delivery_ports_orig")->AsTableVal(); + ::udp_content_delivery_ports_resp = zeek::lookup_val("udp_content_delivery_ports_resp")->AsTableVal(); + ::profiling_file = zeek::lookup_val("profiling_file").get(); + ::global_hash_seed = zeek::lookup_val("global_hash_seed")->AsStringVal(); + ::tcp_reassembler_ports_orig = zeek::lookup_val("tcp_reassembler_ports_orig")->AsTableVal(); + ::tcp_reassembler_ports_resp = zeek::lookup_val("tcp_reassembler_ports_resp")->AsTableVal(); + ::peer_description = zeek::lookup_val("peer_description")->AsStringVal(); + ::trace_output_file = zeek::lookup_val("trace_output_file")->AsStringVal(); + ::cmd_line_bpf_filter = zeek::lookup_val("cmd_line_bpf_filter")->AsStringVal(); + + auto anon_id = global_scope()->Lookup("preserve_orig_addr"); + + if ( anon_id ) + preserve_orig_addr = anon_id->GetVal()->AsTableVal(); + + anon_id = global_scope()->Lookup("preserve_resp_addr"); + + if ( anon_id ) + preserve_resp_addr = anon_id->GetVal()->AsTableVal(); + + anon_id = global_scope()->Lookup("preserve_other_addr"); + + if ( anon_id ) + preserve_other_addr = anon_id->GetVal()->AsTableVal(); } diff --git a/src/ZeekVars.h b/src/ZeekVars.h index 9c55af833f..758be90da1 100644 --- a/src/ZeekVars.h +++ b/src/ZeekVars.h @@ -7,61 +7,22 @@ #include "IntrusivePtr.h" namespace zeek { namespace vars { namespace detail { -void Init(); +void init(); }}} namespace zeek { namespace vars { -// Types +// Common Types extern IntrusivePtr conn_id; extern IntrusivePtr endpoint; -extern IntrusivePtr endpoint_stats; -extern IntrusivePtr connection_type; -extern IntrusivePtr fa_file_type; -extern IntrusivePtr fa_metadata_type; -extern IntrusivePtr icmp_conn; -extern IntrusivePtr icmp_context; -extern IntrusivePtr signature_state; -extern IntrusivePtr SYN_packet; -extern IntrusivePtr pcap_packet; -extern IntrusivePtr raw_pkt_hdr_type; -extern IntrusivePtr l2_hdr_type; +extern IntrusivePtr connection; +extern IntrusivePtr fa_file; +extern IntrusivePtr fa_metadata; extern IntrusivePtr transport_proto; extern IntrusivePtr string_set; extern IntrusivePtr string_array; extern IntrusivePtr count_set; extern IntrusivePtr string_vec; extern IntrusivePtr index_vec; -extern IntrusivePtr mime_matches; -extern IntrusivePtr mime_match; -extern IntrusivePtr socks_address; -extern IntrusivePtr mime_header_rec; -extern IntrusivePtr mime_header_list; -extern IntrusivePtr http_stats_rec; -extern IntrusivePtr http_message_stat; -extern IntrusivePtr pm_mapping; -extern IntrusivePtr pm_mappings; -extern IntrusivePtr pm_port_request; -extern IntrusivePtr pm_callit_request; -extern IntrusivePtr geo_location; -extern IntrusivePtr entropy_test_result; -extern IntrusivePtr dns_msg; -extern IntrusivePtr dns_answer; -extern IntrusivePtr dns_soa; -extern IntrusivePtr dns_edns_additional; -extern IntrusivePtr dns_tsig_additional; -extern IntrusivePtr dns_rrsig_rr; -extern IntrusivePtr dns_dnskey_rr; -extern IntrusivePtr dns_nsec3_rr; -extern IntrusivePtr dns_ds_rr; -extern IntrusivePtr rotate_info; -extern IntrusivePtr irc_join_list; -extern IntrusivePtr irc_join_info; -extern IntrusivePtr script_id; -extern IntrusivePtr id_table; -extern IntrusivePtr record_field; -extern IntrusivePtr record_field_table; -extern IntrusivePtr call_argument; -extern IntrusivePtr call_argument_vector; }} // namespace zeek::vars diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 6ab45052c0..048f88a326 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -595,7 +595,8 @@ bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, if ( dns_SOA_reply && ! msg->skip_event ) { - auto r = make_intrusive(zeek::vars::dns_soa); + static auto dns_soa = zeek::lookup_type("dns_soa"); + auto r = make_intrusive(dns_soa); r->Assign(0, make_intrusive(new BroString(mname, mname_end - mname, true))); r->Assign(1, make_intrusive(new BroString(rname, rname_end - rname, true))); r->Assign(2, val_mgr->Count(serial)); @@ -1438,7 +1439,8 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query) IntrusivePtr DNS_MsgInfo::BuildHdrVal() { - auto r = make_intrusive(zeek::vars::dns_msg); + static auto dns_msg = zeek::lookup_type("dns_msg"); + auto r = make_intrusive(dns_msg); r->Assign(0, val_mgr->Count(id)); r->Assign(1, val_mgr->Count(opcode)); @@ -1459,7 +1461,8 @@ IntrusivePtr DNS_MsgInfo::BuildHdrVal() IntrusivePtr DNS_MsgInfo::BuildAnswerVal() { - auto r = make_intrusive(zeek::vars::dns_answer); + static auto dns_answer = zeek::lookup_type("dns_answer"); + auto r = make_intrusive(dns_answer); r->Assign(0, val_mgr->Count(int(answer_type))); r->Assign(1, query_name); @@ -1474,7 +1477,8 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() { // We have to treat the additional record type in EDNS differently // than a regular resource record. - auto r = make_intrusive(zeek::vars::dns_edns_additional); + static auto dns_edns_additional = zeek::lookup_type("dns_edns_additional"); + auto r = make_intrusive(dns_edns_additional); r->Assign(0, val_mgr->Count(int(answer_type))); r->Assign(1, query_name); @@ -1507,7 +1511,8 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) { - auto r = make_intrusive(zeek::vars::dns_tsig_additional); + static auto dns_tsig_additional = zeek::lookup_type("dns_tsig_additional"); + auto r = make_intrusive(dns_tsig_additional); double rtime = tsig->time_s + tsig->time_ms / 1000.0; // r->Assign(0, val_mgr->Count(int(answer_type))); @@ -1526,7 +1531,8 @@ IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) { - auto r = make_intrusive(zeek::vars::dns_rrsig_rr); + static auto dns_rrsig_rr = zeek::lookup_type("dns_rrsig_rr"); + auto r = make_intrusive(dns_rrsig_rr); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); @@ -1546,7 +1552,8 @@ IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) { - auto r = make_intrusive(zeek::vars::dns_dnskey_rr); + static auto dns_dnskey_rr = zeek::lookup_type("dns_dnskey_rr"); + auto r = make_intrusive(dns_dnskey_rr); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); @@ -1561,7 +1568,8 @@ IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) { - auto r = make_intrusive(zeek::vars::dns_nsec3_rr); + static auto dns_nsec3_rr = zeek::lookup_type("dns_nsec3_rr"); + auto r = make_intrusive(dns_nsec3_rr); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); @@ -1580,7 +1588,8 @@ IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) IntrusivePtr DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) { - auto r = make_intrusive(zeek::vars::dns_ds_rr); + static auto dns_ds_rr = zeek::lookup_type("dns_ds_rr"); + auto r = make_intrusive(dns_ds_rr); r->Assign(0, query_name); r->Assign(1, val_mgr->Count(int(answer_type))); diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index daf928941c..21091fc48b 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -615,7 +615,8 @@ HTTP_Message::~HTTP_Message() IntrusivePtr HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) { - auto stat = make_intrusive(zeek::vars::http_message_stat); + static auto http_message_stat = zeek::lookup_type("http_message_stat"); + auto stat = make_intrusive(http_message_stat); int field = 0; stat->Assign(field++, make_intrusive(start_time, TYPE_TIME)); stat->Assign(field++, val_mgr->Bool(interrupted)); @@ -1151,7 +1152,8 @@ void HTTP_Analyzer::GenStats() { if ( http_stats ) { - auto r = make_intrusive(zeek::vars::http_stats_rec); + static auto http_stats_rec = zeek::lookup_type("http_stats_rec"); + auto r = make_intrusive(http_stats_rec); r->Assign(0, val_mgr->Count(num_requests)); r->Assign(1, val_mgr->Count(num_replies)); r->Assign(2, make_intrusive(request_version.ToDouble(), TYPE_DOUBLE)); diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 33c730d63f..5ae6239ec2 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -225,7 +225,8 @@ ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, { if ( ! icmp_conn_val ) { - icmp_conn_val = make_intrusive(zeek::vars::icmp_conn); + static auto icmp_conn = zeek::lookup_type("icmp_conn"); + icmp_conn_val = make_intrusive(icmp_conn); icmp_conn_val->Assign(0, make_intrusive(Conn()->OrigAddr())); icmp_conn_val->Assign(1, make_intrusive(Conn()->RespAddr())); @@ -350,7 +351,8 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP4Context(int len, const u_char } } - auto iprec = make_intrusive(zeek::vars::icmp_context); + static auto icmp_context = zeek::lookup_type("icmp_context"); + auto iprec = make_intrusive(icmp_context); auto id_val = make_intrusive(zeek::vars::conn_id); id_val->Assign(0, make_intrusive(src_addr)); @@ -409,7 +411,8 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP6Context(int len, const u_char } } - auto iprec = make_intrusive(zeek::vars::icmp_context); + static auto icmp_context = zeek::lookup_type("icmp_context"); + auto iprec = make_intrusive(icmp_context); auto id_val = make_intrusive(zeek::vars::conn_id); id_val->Assign(0, make_intrusive(src_addr)); diff --git a/src/analyzer/protocol/irc/IRC.cc b/src/analyzer/protocol/irc/IRC.cc index 6d7f2f0d82..7305380c8d 100644 --- a/src/analyzer/protocol/irc/IRC.cc +++ b/src/analyzer/protocol/irc/IRC.cc @@ -44,6 +44,8 @@ inline void IRC_Analyzer::SkipLeadingWhitespace(string& str) void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) { + static auto irc_join_list = zeek::lookup_type("irc_join_list"); + static auto irc_join_info = zeek::lookup_type("irc_join_info"); tcp::TCP_ApplicationAnalyzer::DeliverStream(length, line, orig); if ( starttls ) @@ -836,7 +838,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) nickname = prefix.substr(0, pos); } - auto list = make_intrusive(zeek::vars::irc_join_list); + auto list = make_intrusive(irc_join_list); vector channels = SplitWords(parts[0], ','); vector passwords; @@ -847,7 +849,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) string empty_string = ""; for ( unsigned int i = 0; i < channels.size(); ++i ) { - RecordVal* info = new RecordVal(zeek::vars::irc_join_info); + RecordVal* info = new RecordVal(irc_join_info); info->Assign(0, make_intrusive(nickname.c_str())); info->Assign(1, make_intrusive(channels[i].c_str())); if ( i < passwords.size() ) @@ -881,13 +883,13 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) parts[1] = parts[1].substr(1); vector users = SplitWords(parts[1], ','); - auto list = make_intrusive(zeek::vars::irc_join_list); + auto list = make_intrusive(irc_join_list); string empty_string = ""; for ( unsigned int i = 0; i < users.size(); ++i ) { - auto info = make_intrusive(zeek::vars::irc_join_info); + auto info = make_intrusive(irc_join_info); string nick = users[i]; string mode = "none"; diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index b994407933..69e0ac4ef2 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -1289,7 +1289,8 @@ void MIME_Entity::DebugPrintHeaders() IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) { - auto header_record = make_intrusive(zeek::vars::mime_header_rec); + static auto mime_header_rec = zeek::lookup_type("mime_header_rec"); + auto header_record = make_intrusive(mime_header_rec); header_record->Assign(0, new_string_val(h->get_name())); auto upper_hn = new_string_val(h->get_name()); upper_hn->ToUpper(); @@ -1300,7 +1301,8 @@ IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) IntrusivePtr MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) { - auto t = make_intrusive(zeek::vars::mime_header_list); + static auto mime_header_list = zeek::lookup_type("mime_header_list"); + auto t = make_intrusive(mime_header_list); for ( unsigned int i = 0; i < hlist.size(); ++i ) { diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 91a0becb04..2f4bbf1316 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -138,7 +138,8 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu event = success ? pm_request_dump : pm_attempt_dump; if ( success ) { - TableVal* mappings = new TableVal(zeek::vars::pm_mappings); + static auto pm_mappings = zeek::lookup_type("pm_mappings"); + TableVal* mappings = new TableVal(pm_mappings); uint32_t nmap = 0; // Each call in the loop test pulls the next "opted" @@ -193,7 +194,8 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) { - RecordVal* mapping = new RecordVal(zeek::vars::pm_mapping); + static auto pm_mapping = zeek::lookup_type("pm_mapping"); + RecordVal* mapping = new RecordVal(pm_mapping); mapping->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); mapping->Assign(1, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -213,7 +215,8 @@ Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) { - RecordVal* pr = new RecordVal(zeek::vars::pm_port_request); + static auto pm_port_request = zeek::lookup_type("pm_port_request"); + RecordVal* pr = new RecordVal(pm_port_request); pr->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); pr->Assign(1, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -233,7 +236,8 @@ Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) Val* PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) { - RecordVal* c = new RecordVal(zeek::vars::pm_callit_request); + static auto pm_callit_request = zeek::lookup_type("pm_callit_request"); + RecordVal* c = new RecordVal(pm_callit_request); c->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); c->Assign(1, val_mgr->Count(extract_XDR_uint32(buf, len))); diff --git a/src/analyzer/protocol/sip/sip-analyzer.pac b/src/analyzer/protocol/sip/sip-analyzer.pac index dab40b4e26..26f7548c78 100644 --- a/src/analyzer/protocol/sip/sip-analyzer.pac +++ b/src/analyzer/protocol/sip/sip-analyzer.pac @@ -67,7 +67,8 @@ refine flow SIP_Flow += { function build_sip_headers_val(): BroVal %{ - TableVal* t = new TableVal(zeek::vars::mime_header_list); + static auto mime_header_list = zeek::lookup_type("mime_header_list"); + TableVal* t = new TableVal(mime_header_list); for ( unsigned int i = 0; i < headers.size(); ++i ) { // index starting from 1 @@ -101,7 +102,8 @@ refine flow SIP_Flow += { function build_sip_header_val(name: const_bytestring, value: const_bytestring): BroVal %{ - RecordVal* header_record = new RecordVal(zeek::vars::mime_header_rec); + static auto mime_header_rec = zeek::lookup_type("mime_header_rec"); + RecordVal* header_record = new RecordVal(mime_header_rec); IntrusivePtr name_val; if ( name.length() > 0 ) diff --git a/src/analyzer/protocol/socks/socks-analyzer.pac b/src/analyzer/protocol/socks/socks-analyzer.pac index cd33098653..cf621d69be 100644 --- a/src/analyzer/protocol/socks/socks-analyzer.pac +++ b/src/analyzer/protocol/socks/socks-analyzer.pac @@ -24,7 +24,8 @@ refine connection SOCKS_Conn += { %{ if ( socks_request ) { - auto sa = make_intrusive(zeek::vars::socks_address); + static auto socks_address = zeek::lookup_type("SOCKS::Address"); + auto sa = make_intrusive(socks_address); sa->Assign(0, make_intrusive(htonl(${request.addr}))); if ( ${request.v4a} ) @@ -48,7 +49,8 @@ refine connection SOCKS_Conn += { %{ if ( socks_reply ) { - auto sa = make_intrusive(zeek::vars::socks_address); + static auto socks_address = zeek::lookup_type("SOCKS::Address"); + auto sa = make_intrusive(socks_address); sa->Assign(0, make_intrusive(htonl(${reply.addr}))); BifEvent::enqueue_socks_reply(bro_analyzer(), @@ -80,7 +82,8 @@ refine connection SOCKS_Conn += { return false; } - auto sa = make_intrusive(zeek::vars::socks_address); + static auto socks_address = zeek::lookup_type("SOCKS::Address"); + auto sa = make_intrusive(socks_address); // This is dumb and there must be a better way (checking for presence of a field)... switch ( ${request.remote_name.addr_type} ) @@ -119,7 +122,8 @@ refine connection SOCKS_Conn += { function socks5_reply(reply: SOCKS5_Reply): bool %{ - auto sa = make_intrusive(zeek::vars::socks_address); + static auto socks_address = zeek::lookup_type("SOCKS::Address"); + auto sa = make_intrusive(socks_address); // This is dumb and there must be a better way (checking for presence of a field)... switch ( ${reply.bound.addr_type} ) diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index f492c3e154..f1bdd7639c 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -107,7 +107,8 @@ static RecordVal* build_syn_packet_val(bool is_orig, const IP_Hdr* ip, options += opt_len; } - RecordVal* v = new RecordVal(zeek::vars::SYN_packet); + static auto SYN_packet = zeek::lookup_type("SYN_packet"); + RecordVal* v = new RecordVal(SYN_packet); v->Assign(0, val_mgr->Bool(is_orig)); v->Assign(1, val_mgr->Bool(int(ip->DF()))); @@ -2077,7 +2078,8 @@ bool TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int capl RecordVal* TCPStats_Endpoint::BuildStats() { - RecordVal* stats = new RecordVal(zeek::vars::endpoint_stats); + static auto endpoint_stats = zeek::lookup_type("endpoint_stats"); + RecordVal* stats = new RecordVal(endpoint_stats); stats->Assign(0, val_mgr->Count(num_pkts)); stats->Assign(1, val_mgr->Count(num_rxmit)); diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index b98819c949..005978fef6 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -26,7 +26,7 @@ static Val* empty_connection_table() auto tbl_index = make_intrusive(zeek::vars::conn_id); tbl_index->Append(zeek::vars::conn_id); auto tbl_type = make_intrusive(std::move(tbl_index), - zeek::vars::connection_type); + zeek::vars::connection); return new TableVal(std::move(tbl_type)); } @@ -62,22 +62,22 @@ void File::StaticInit() if ( id_idx != -1 ) return; - id_idx = Idx("id", zeek::vars::fa_file_type); - parent_id_idx = Idx("parent_id", zeek::vars::fa_file_type); - source_idx = Idx("source", zeek::vars::fa_file_type); - is_orig_idx = Idx("is_orig", zeek::vars::fa_file_type); - conns_idx = Idx("conns", zeek::vars::fa_file_type); - last_active_idx = Idx("last_active", zeek::vars::fa_file_type); - seen_bytes_idx = Idx("seen_bytes", zeek::vars::fa_file_type); - total_bytes_idx = Idx("total_bytes", zeek::vars::fa_file_type); - missing_bytes_idx = Idx("missing_bytes", zeek::vars::fa_file_type); - overflow_bytes_idx = Idx("overflow_bytes", zeek::vars::fa_file_type); - timeout_interval_idx = Idx("timeout_interval", zeek::vars::fa_file_type); - bof_buffer_size_idx = Idx("bof_buffer_size", zeek::vars::fa_file_type); - bof_buffer_idx = Idx("bof_buffer", zeek::vars::fa_file_type); - meta_mime_type_idx = Idx("mime_type", zeek::vars::fa_metadata_type); - meta_mime_types_idx = Idx("mime_types", zeek::vars::fa_metadata_type); - meta_inferred_idx = Idx("inferred", zeek::vars::fa_metadata_type); + id_idx = Idx("id", zeek::vars::fa_file); + parent_id_idx = Idx("parent_id", zeek::vars::fa_file); + source_idx = Idx("source", zeek::vars::fa_file); + is_orig_idx = Idx("is_orig", zeek::vars::fa_file); + conns_idx = Idx("conns", zeek::vars::fa_file); + last_active_idx = Idx("last_active", zeek::vars::fa_file); + seen_bytes_idx = Idx("seen_bytes", zeek::vars::fa_file); + total_bytes_idx = Idx("total_bytes", zeek::vars::fa_file); + missing_bytes_idx = Idx("missing_bytes", zeek::vars::fa_file); + overflow_bytes_idx = Idx("overflow_bytes", zeek::vars::fa_file); + timeout_interval_idx = Idx("timeout_interval", zeek::vars::fa_file); + bof_buffer_size_idx = Idx("bof_buffer_size", zeek::vars::fa_file); + bof_buffer_idx = Idx("bof_buffer", zeek::vars::fa_file); + meta_mime_type_idx = Idx("mime_type", zeek::vars::fa_metadata); + meta_mime_types_idx = Idx("mime_types", zeek::vars::fa_metadata); + meta_inferred_idx = Idx("inferred", zeek::vars::fa_metadata); } File::File(const std::string& file_id, const std::string& source_name, Connection* conn, @@ -91,7 +91,7 @@ File::File(const std::string& file_id, const std::string& source_name, Connectio DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Creating new File object", file_id.c_str()); - val = new RecordVal(zeek::vars::fa_file_type); + val = new RecordVal(zeek::vars::fa_file); val->Assign(id_idx, make_intrusive(file_id.c_str())); SetSource(source_name); @@ -295,7 +295,7 @@ bool File::SetMime(const std::string& mime_type) if ( ! FileEventAvailable(file_sniff) ) return false; - auto meta = make_intrusive(zeek::vars::fa_metadata_type); + auto meta = make_intrusive(zeek::vars::fa_metadata); meta->Assign(meta_mime_type_idx, make_intrusive(mime_type)); meta->Assign(meta_inferred_idx, val_mgr->False()); @@ -328,7 +328,7 @@ void File::InferMetadata() len = std::min(len, LookupFieldDefaultCount(bof_buffer_size_idx)); file_mgr->DetectMIME(data, len, &matches); - auto meta = make_intrusive(zeek::vars::fa_metadata_type); + auto meta = make_intrusive(zeek::vars::fa_metadata); if ( ! matches.empty() ) { diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index df950416cb..010087f6b9 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -499,12 +499,14 @@ string Manager::DetectMIME(const u_char* data, uint64_t len) const IntrusivePtr file_analysis::GenMIMEMatchesVal(const RuleMatcher::MIME_Matches& m) { - auto rval = make_intrusive(zeek::vars::mime_matches); + static auto mime_matches = zeek::lookup_type("mime_matches"); + static auto mime_match = zeek::lookup_type("mime_match"); + auto rval = make_intrusive(mime_matches); for ( RuleMatcher::MIME_Matches::const_iterator it = m.begin(); it != m.end(); ++it ) { - auto element = make_intrusive(zeek::vars::mime_match); + auto element = make_intrusive(mime_match); for ( set::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2 ) diff --git a/src/file_analysis/analyzer/entropy/Entropy.cc b/src/file_analysis/analyzer/entropy/Entropy.cc index 1e605c9883..eb3dbf6d8e 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.cc +++ b/src/file_analysis/analyzer/entropy/Entropy.cc @@ -60,7 +60,8 @@ void Entropy::Finalize() montepi = scc = ent = mean = chisq = 0.0; entropy->Get(&ent, &chisq, &mean, &montepi, &scc); - auto ent_result = make_intrusive(zeek::vars::entropy_test_result); + static auto entropy_test_result = zeek::lookup_type("entropy_test_result"); + auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); ent_result->Assign(2, make_intrusive(mean, TYPE_DOUBLE)); diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index 20c4d1bc8c..d7331a920a 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -4,6 +4,7 @@ #include "IP.h" #include "IntrusivePtr.h" #include "iosource/Manager.h" +#include "Var.h" extern "C" { #include @@ -593,8 +594,10 @@ void Packet::ProcessLayer2() IntrusivePtr Packet::ToRawPktHdrVal() const { - auto pkt_hdr = make_intrusive(zeek::vars::raw_pkt_hdr_type); - RecordVal* l2_hdr = new RecordVal(zeek::vars::l2_hdr_type); + static auto raw_pkt_hdr_type = zeek::lookup_type("raw_pkt_hdr"); + static auto l2_hdr_type = zeek::lookup_type("l2_hdr"); + auto pkt_hdr = make_intrusive(raw_pkt_hdr_type); + RecordVal* l2_hdr = new RecordVal(l2_hdr_type); bool is_ethernet = link_type == DLT_EN10MB; diff --git a/src/zeek.bif b/src/zeek.bif index c64a0a858a..bdf0543375 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1051,7 +1051,8 @@ function find_entropy%(data: string%): entropy_test_result e.Feed(data->Bytes(), data->Len()); e.Get(&ent, &chisq, &mean, &montepi, &scc); - auto ent_result = make_intrusive(zeek::vars::entropy_test_result); + static auto entropy_test_result = zeek::lookup_type("entropy_test_result"); + auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); ent_result->Assign(2, make_intrusive(mean, TYPE_DOUBLE)); @@ -1102,7 +1103,8 @@ function entropy_test_finish%(handle: opaque of entropy%): entropy_test_result montepi = scc = ent = mean = chisq = 0.0; static_cast(handle)->Get(&ent, &chisq, &mean, &montepi, &scc); - auto ent_result = make_intrusive(zeek::vars::entropy_test_result); + static auto entropy_test_result = zeek::lookup_type("entropy_test_result"); + auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); ent_result->Assign(2, make_intrusive(mean, TYPE_DOUBLE)); @@ -1939,13 +1941,15 @@ function global_sizes%(%): var_sizes ## .. zeek:see:: global_sizes function global_ids%(%): id_table %{ - auto ids = make_intrusive(zeek::vars::id_table); + static auto id_table = zeek::lookup_type("id_table"); + auto ids = make_intrusive(id_table); const auto& globals = global_scope()->Vars(); for ( const auto& global : globals ) { ID* id = global.second.get(); - auto rec = make_intrusive(zeek::vars::script_id); + static auto script_id = zeek::lookup_type("script_id"); + auto rec = make_intrusive(script_id); rec->Assign(0, make_intrusive(type_name(id->GetType()->Tag()))); rec->Assign(1, val_mgr->Bool(id->IsExport())); rec->Assign(2, val_mgr->Bool(id->IsConst())); @@ -1990,6 +1994,8 @@ function lookup_ID%(id: string%) : any ## Returns: A table that describes the fields of a record. function record_fields%(rec: any%): record_field_table %{ + static auto record_field_table = zeek::lookup_type("record_field_table"); + if ( rec->GetType()->Tag() == TYPE_STRING ) { auto id = global_scope()->Lookup(rec->AsStringVal()->ToStdString()); @@ -1997,7 +2003,7 @@ function record_fields%(rec: any%): record_field_table if ( ! id || ! id->IsType() || id->GetType()->Tag() != TYPE_RECORD ) { reporter->Error("record_fields string argument does not name a record type"); - return make_intrusive(zeek::vars::record_field_table); + return make_intrusive(record_field_table); } return id->GetType()->AsRecordType()->GetRecordFieldsVal(); @@ -3295,7 +3301,7 @@ function lookup_connection%(cid: conn_id%): connection builtin_error("connection ID not a known connection", cid); // Return a dummy connection record. - auto c = make_intrusive(zeek::vars::connection_type); + auto c = make_intrusive(zeek::vars::connection); auto id_val = make_intrusive(zeek::vars::conn_id); id_val->Assign(0, make_intrusive((unsigned int) 0)); @@ -3379,8 +3385,9 @@ function dump_current_packet%(file_name: string%) : bool ## .. zeek:see:: dump_current_packet dump_packet function get_current_packet%(%) : pcap_packet %{ + static auto pcap_packet = zeek::lookup_type("pcap_packet"); const Packet* p; - auto pkt = make_intrusive(zeek::vars::pcap_packet); + auto pkt = make_intrusive(pcap_packet); if ( ! current_pktsrc || ! current_pktsrc->GetCurrentPacket(&p) ) @@ -3420,7 +3427,8 @@ function get_current_packet_header%(%) : raw_pkt_hdr return p->ToRawPktHdrVal(); } - auto hdr = make_intrusive(zeek::vars::raw_pkt_hdr_type); + static auto raw_pkt_hdr_type = zeek::lookup_type("raw_pkt_hdr"); + auto hdr = make_intrusive(raw_pkt_hdr_type); return hdr; %} @@ -3990,7 +3998,8 @@ function mmdb_open_asn_db%(f: string%) : bool ## .. zeek:see:: lookup_asn function lookup_location%(a: addr%) : geo_location %{ - auto location = make_intrusive(zeek::vars::geo_location); + static auto geo_location = zeek::lookup_type("geo_location"); + auto location = make_intrusive(geo_location); #ifdef USE_GEOIP mmdb_check_loc(); @@ -4621,7 +4630,8 @@ function rotate_file%(f: file%): rotate_info return info; // Record indicating error. - info = make_intrusive(zeek::vars::rotate_info); + static auto rotate_info = zeek::lookup_type("rotate_info"); + info = make_intrusive(rotate_info); info->Assign(0, val_mgr->EmptyString()); info->Assign(1, val_mgr->EmptyString()); info->Assign(2, make_intrusive(0.0, TYPE_TIME)); @@ -4640,7 +4650,8 @@ function rotate_file%(f: file%): rotate_info ## .. zeek:see:: rotate_file calc_next_rotate function rotate_file_by_name%(f: string%): rotate_info %{ - auto info = make_intrusive(zeek::vars::rotate_info); + static auto rotate_info = zeek::lookup_type("rotate_info"); + auto info = make_intrusive(rotate_info); bool is_pkt_dumper = false; bool is_addl_pkt_dumper = false; From a5762c12ccc4259a66979af32cdb4bcf783bb805 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 12 May 2020 18:08:52 -0700 Subject: [PATCH 047/151] Move various elements into ID.h and zeek::id namespace * A handful of generic/useful/common global type pointers that used to be in NetVar.h * Lookup functions that used to be Var.h --- NEWS | 8 +- aux/bifcl | 2 +- src/BroString.cc | 5 +- src/CMakeLists.txt | 4 +- src/Conn.cc | 10 +- src/DNS_Mgr.cc | 2 +- src/Discard.cc | 8 +- src/EventHandler.cc | 4 +- src/File.cc | 2 +- src/Func.cc | 30 ++--- src/ID.cc | 83 ++++++++++++ src/ID.h | 86 +++++++++++++ src/IP.cc | 34 +++-- src/NetVar.cc | 16 ++- src/NetVar.h | 23 ++-- src/OpaqueVal.cc | 2 +- src/Reporter.cc | 16 +-- src/RuleCondition.cc | 5 +- src/RuleMatcher.cc | 2 +- src/Sessions.cc | 6 +- src/SmithWaterman.cc | 8 +- src/Stats.cc | 4 +- src/Stmt.cc | 6 +- src/TunnelEncapsulation.cc | 2 +- src/TunnelEncapsulation.h | 4 +- src/Type.cc | 4 +- src/Val.cc | 6 +- src/Var.cc | 54 +------- src/Var.h | 72 ++--------- src/ZeekVars.cc | 121 ------------------ src/ZeekVars.h | 28 ---- src/analyzer/Manager.cc | 6 +- .../protocol/bittorrent/BitTorrentTracker.cc | 10 +- src/analyzer/protocol/conn-size/ConnSize.cc | 4 +- src/analyzer/protocol/dhcp/dhcp-analyzer.pac | 2 +- src/analyzer/protocol/dhcp/dhcp-options.pac | 2 +- src/analyzer/protocol/dns/DNS.cc | 30 ++--- src/analyzer/protocol/http/HTTP.cc | 4 +- src/analyzer/protocol/icmp/ICMP.cc | 16 +-- src/analyzer/protocol/imap/imap-analyzer.pac | 2 +- src/analyzer/protocol/irc/IRC.cc | 10 +- src/analyzer/protocol/krb/krb-padata.pac | 2 +- src/analyzer/protocol/krb/krb-types.pac | 6 +- src/analyzer/protocol/login/Login.cc | 14 +- src/analyzer/protocol/mime/MIME.cc | 4 +- .../protocol/mqtt/commands/subscribe.pac | 4 +- .../protocol/mqtt/commands/unsubscribe.pac | 2 +- .../protocol/mysql/mysql-analyzer.pac | 2 +- src/analyzer/protocol/rpc/MOUNT.cc | 2 +- src/analyzer/protocol/rpc/NFS.cc | 2 +- src/analyzer/protocol/rpc/Portmap.cc | 8 +- src/analyzer/protocol/sip/sip-analyzer.pac | 4 +- .../protocol/smb/smb1-com-negotiate.pac | 2 +- .../protocol/smb/smb2-com-negotiate.pac | 2 +- src/analyzer/protocol/smb/smb2-protocol.pac | 6 +- .../protocol/socks/socks-analyzer.pac | 8 +- src/analyzer/protocol/ssh/ssh-analyzer.pac | 2 +- .../protocol/ssl/proc-client-hello.pac | 4 +- .../protocol/ssl/tls-handshake-analyzer.pac | 26 ++-- src/analyzer/protocol/tcp/TCP.cc | 6 +- src/analyzer/protocol/tcp/TCP_Reassembler.cc | 4 +- src/analyzer/protocol/teredo/Teredo.cc | 6 +- src/analyzer/protocol/udp/UDP.cc | 6 +- src/bro-bif.h | 3 +- src/broker/Data.cc | 4 +- src/broker/Manager.cc | 10 +- src/broker/Store.cc | 4 +- src/broker/comm.bif | 8 +- src/file_analysis/File.cc | 46 +++---- src/file_analysis/Manager.cc | 7 +- src/file_analysis/analyzer/entropy/Entropy.cc | 2 +- src/file_analysis/analyzer/pe/pe-analyzer.pac | 4 +- src/file_analysis/analyzer/x509/OCSP.cc | 2 +- src/file_analysis/analyzer/x509/X509.cc | 8 +- src/file_analysis/analyzer/x509/functions.bif | 2 +- src/iosource/Packet.cc | 4 +- src/legacy-netvar-init.cc | 93 ++++++++++++++ src/logging/Manager.cc | 8 +- src/probabilistic/Hasher.cc | 2 +- src/reporter.bif | 2 +- src/stats.bif | 2 +- src/strings.bif | 8 +- src/zeek-setup.cc | 6 +- src/zeek.bif | 56 ++++---- 84 files changed, 578 insertions(+), 568 deletions(-) delete mode 100644 src/ZeekVars.cc delete mode 100644 src/ZeekVars.h create mode 100644 src/legacy-netvar-init.cc diff --git a/NEWS b/NEWS index 78b674f729..1178de57a9 100644 --- a/NEWS +++ b/NEWS @@ -159,15 +159,15 @@ Deprecated Functionality - ``ID::ID_Val()`` is deprecated, use ``ID::GetVal()``. -- ``internal_type()`` is deprecated, use ``zeek::lookup_type()``. +- ``internal_type()`` is deprecated, use ``zeek::id::lookup_type()``. - ``internal_val()`` and ``internal_const_val()`` are deprecated, use - ``zeek::lookup_val()`` or ``zeek::lookup_const()``. + ``zeek::id::lookup_val()`` or ``zeek::id::lookup_const()``. -- ``internal_func()`` is deprecated, use ``zeek::lookup_func()``. +- ``internal_func()`` is deprecated, use ``zeek::id::lookup_func()``. - ``opt_internal_val()`` is deprecated, use ``lookup_ID()`` or - ``zeek::lookup_val()``. + ``zeek::id::lookup_val()``. - ``Val::Type()`` is deprecated, use ``Val::GetType``. diff --git a/aux/bifcl b/aux/bifcl index 883d7174c8..071a1517a7 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 883d7174c8d80a44910855b05482fe107a60e55c +Subproject commit 071a1517a73bde131da42fe35cac05a3503340be diff --git a/src/BroString.cc b/src/BroString.cc index 6e5465160e..2fe950b87d 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -8,10 +8,9 @@ #include #include "Val.h" -#include "Var.h" +#include "ID.h" #include "Reporter.h" #include "util.h" -#include "ZeekVars.h" #ifdef DEBUG #define DEBUG_STR(msg) DBG_LOG(DBG_STRING, msg) @@ -341,7 +340,7 @@ BroString::Vec* BroString::Split(const BroString::IdxVec& indices) const VectorVal* BroString:: VecToPolicy(Vec* vec) { - auto result = make_intrusive(zeek::vars::string_vec); + auto result = make_intrusive(zeek::id::string_vec); for ( unsigned int i = 0; i < vec->size(); ++i ) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5526ab35ab..f1b80e4b92 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -205,7 +205,7 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/DebugCmdConstants.h set_source_files_properties(nb_dns.c PROPERTIES COMPILE_FLAGS -fno-strict-aliasing) -set_source_files_properties(ZeekVars.cc PROPERTIES COMPILE_FLAGS +set_source_files_properties(legacy-netvar-init.cc PROPERTIES COMPILE_FLAGS -Wno-deprecated-declarations) set(MAIN_SRCS @@ -289,7 +289,7 @@ set(MAIN_SRCS Var.cc WeirdState.cc ZeekArgs.cc - ZeekVars.cc + legacy-netvar-init.cc bsd-getopt-long.c bro_inet_ntop.c patricia.c diff --git a/src/Conn.cc b/src/Conn.cc index 597e9e81d2..6d19444095 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -346,17 +346,17 @@ const IntrusivePtr& Connection::ConnVal() { if ( ! conn_val ) { - conn_val = make_intrusive(zeek::vars::connection); + conn_val = make_intrusive(zeek::id::connection); TransportProto prot_type = ConnTransport(); - auto id_val = make_intrusive(zeek::vars::conn_id); + auto id_val = make_intrusive(zeek::id::conn_id); id_val->Assign(0, make_intrusive(orig_addr)); id_val->Assign(1, val_mgr->Port(ntohs(orig_port), prot_type)); id_val->Assign(2, make_intrusive(resp_addr)); id_val->Assign(3, val_mgr->Port(ntohs(resp_port), prot_type)); - auto orig_endp = make_intrusive(zeek::vars::endpoint); + auto orig_endp = make_intrusive(zeek::id::endpoint); orig_endp->Assign(0, val_mgr->Count(0)); orig_endp->Assign(1, val_mgr->Count(0)); orig_endp->Assign(4, val_mgr->Count(orig_flow_label)); @@ -367,7 +367,7 @@ const IntrusivePtr& Connection::ConnVal() if ( memcmp(&orig_l2_addr, &null, l2_len) != 0 ) orig_endp->Assign(5, make_intrusive(fmt_mac(orig_l2_addr, l2_len))); - auto resp_endp = make_intrusive(zeek::vars::endpoint); + auto resp_endp = make_intrusive(zeek::id::endpoint); resp_endp->Assign(0, val_mgr->Count(0)); resp_endp->Assign(1, val_mgr->Count(0)); resp_endp->Assign(4, val_mgr->Count(resp_flow_label)); @@ -379,7 +379,7 @@ const IntrusivePtr& Connection::ConnVal() conn_val->Assign(1, std::move(orig_endp)); conn_val->Assign(2, std::move(resp_endp)); // 3 and 4 are set below. - conn_val->Assign(5, make_intrusive(zeek::vars::string_set)); // service + conn_val->Assign(5, make_intrusive(zeek::id::string_set)); // service conn_val->Assign(6, val_mgr->EmptyString()); // history if ( ! uid ) diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index b6f4f4a00e..c834ba7c80 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -462,7 +462,7 @@ void DNS_Mgr::InitPostScript() dns_mapping_name_changed = internal_handler("dns_mapping_name_changed"); dns_mapping_altered = internal_handler("dns_mapping_altered"); - dm_rec = zeek::lookup_type("dns_mapping")->AsRecordType(); + dm_rec = zeek::id::lookup_type("dns_mapping")->AsRecordType(); // Registering will call Init() iosource_mgr->Register(this, true); diff --git a/src/Discard.cc b/src/Discard.cc index 4386874ad8..b41a8a9946 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -16,10 +16,10 @@ Discarder::Discarder() { - check_ip = zeek::lookup_func("discarder_check_ip"); - check_tcp = zeek::lookup_func("discarder_check_tcp"); - check_udp = zeek::lookup_func("discarder_check_udp"); - check_icmp = zeek::lookup_func("discarder_check_icmp"); + check_ip = zeek::id::lookup_func("discarder_check_ip"); + check_tcp = zeek::id::lookup_func("discarder_check_tcp"); + check_udp = zeek::id::lookup_func("discarder_check_udp"); + check_icmp = zeek::id::lookup_func("discarder_check_icmp"); discarder_maxlen = static_cast(opt_internal_int("discarder_maxlen")); } diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 45d3037650..1f8edb162b 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -128,7 +128,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) return; RecordType* args = FType()->Args(); - static auto call_argument_vector = zeek::lookup_type("call_argument_vector"); + static auto call_argument_vector = zeek::id::lookup_type("call_argument_vector"); auto vargs = make_intrusive(call_argument_vector); for ( int i = 0; i < args->NumFields(); i++ ) @@ -137,7 +137,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) const auto& ftype = args->GetFieldType(i); auto fdefault = args->FieldDefault(i); - static auto call_argument = zeek::lookup_type("call_argument"); + static auto call_argument = zeek::id::lookup_type("call_argument"); auto rec = make_intrusive(call_argument); rec->Assign(0, make_intrusive(fname)); diff --git a/src/File.cc b/src/File.cc index a10305ea00..9fdafe2651 100644 --- a/src/File.cc +++ b/src/File.cc @@ -278,7 +278,7 @@ RecordVal* BroFile::Rotate() if ( f == stdin || f == stdout || f == stderr ) return nullptr; - static auto rotate_info = zeek::lookup_type("rotate_info"); + static auto rotate_info = zeek::id::lookup_type("rotate_info"); RecordVal* info = new RecordVal(rotate_info); FILE* newf = rotate_file(name, info); diff --git a/src/Func.cc b/src/Func.cc index b60df3f4a3..51a6313998 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -54,8 +54,6 @@ #include "iosource/PktSrc.h" #include "iosource/PktDumper.h" -using namespace zeek; - extern RETSIGTYPE sig_handler(int signo); std::vector call_stack; @@ -750,21 +748,21 @@ void builtin_error(const char* msg, BroObj* arg) void init_builtin_funcs() { - ProcStats = lookup_type("ProcStats")->AsRecordType(); - NetStats = lookup_type("NetStats")->AsRecordType(); - MatcherStats = lookup_type("MatcherStats")->AsRecordType(); - ConnStats = lookup_type("ConnStats")->AsRecordType(); - ReassemblerStats = lookup_type("ReassemblerStats")->AsRecordType(); - DNSStats = lookup_type("DNSStats")->AsRecordType(); - GapStats = lookup_type("GapStats")->AsRecordType(); - EventStats = lookup_type("EventStats")->AsRecordType(); - TimerStats = lookup_type("TimerStats")->AsRecordType(); - FileAnalysisStats = lookup_type("FileAnalysisStats")->AsRecordType(); - ThreadStats = lookup_type("ThreadStats")->AsRecordType(); - BrokerStats = lookup_type("BrokerStats")->AsRecordType(); - ReporterStats = lookup_type("ReporterStats")->AsRecordType(); + ProcStats = zeek::id::lookup_type("ProcStats")->AsRecordType(); + NetStats = zeek::id::lookup_type("NetStats")->AsRecordType(); + MatcherStats = zeek::id::lookup_type("MatcherStats")->AsRecordType(); + ConnStats = zeek::id::lookup_type("ConnStats")->AsRecordType(); + ReassemblerStats = zeek::id::lookup_type("ReassemblerStats")->AsRecordType(); + DNSStats = zeek::id::lookup_type("DNSStats")->AsRecordType(); + GapStats = zeek::id::lookup_type("GapStats")->AsRecordType(); + EventStats = zeek::id::lookup_type("EventStats")->AsRecordType(); + TimerStats = zeek::id::lookup_type("TimerStats")->AsRecordType(); + FileAnalysisStats = zeek::id::lookup_type("FileAnalysisStats")->AsRecordType(); + ThreadStats = zeek::id::lookup_type("ThreadStats")->AsRecordType(); + BrokerStats = zeek::id::lookup_type("BrokerStats")->AsRecordType(); + ReporterStats = zeek::id::lookup_type("ReporterStats")->AsRecordType(); - var_sizes = lookup_type("var_sizes")->AsTableType(); + var_sizes = zeek::id::lookup_type("var_sizes")->AsTableType(); #include "zeek.bif.func_init" #include "stats.bif.func_init" diff --git a/src/ID.cc b/src/ID.cc index 01cd943784..3184aa2aef 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -19,6 +19,89 @@ #include "zeekygen/ScriptInfo.h" #include "module_util.h" +IntrusivePtr zeek::id::conn_id; +IntrusivePtr zeek::id::endpoint; +IntrusivePtr zeek::id::connection; +IntrusivePtr zeek::id::fa_file; +IntrusivePtr zeek::id::fa_metadata; +IntrusivePtr zeek::id::transport_proto; +IntrusivePtr zeek::id::string_set; +IntrusivePtr zeek::id::string_array; +IntrusivePtr zeek::id::count_set; +IntrusivePtr zeek::id::string_vec; +IntrusivePtr zeek::id::index_vec; + +IntrusivePtr zeek::id::lookup(const char* name) + { + auto id = global_scope()->Lookup(name); + + if ( ! id ) + return nullptr; + + return {NewRef{}, id}; + } + +const IntrusivePtr& zeek::id::lookup_type(const char* name) + { + auto id = zeek::id::lookup(name); + + if ( ! id ) + reporter->InternalError("Failed to find type named: %s", name); + + return id->GetType(); + } + +const IntrusivePtr& zeek::id::lookup_val(const char* name) + { + auto id = zeek::id::lookup(name); + + if ( ! id ) + reporter->InternalError("Failed to find variable named: %s", name); + + return id->GetVal(); + } + +const IntrusivePtr& zeek::id::lookup_const(const char* name) + { + auto id = zeek::id::lookup(name); + + if ( ! id ) + reporter->InternalError("Failed to find variable named: %s", name); + + if ( ! id->IsConst() ) + reporter->InternalError("Variable is not 'const', but expected to be: %s", name); + + return id->GetVal(); + } + +IntrusivePtr zeek::id::lookup_func(const char* name) + { + const auto& v = zeek::id::lookup_val(name); + + if ( ! v ) + return nullptr; + + if ( ! IsFunc(v->GetType()->Tag()) ) + reporter->InternalError("Expected variable '%s' to be a function", name); + + return {NewRef{}, v->AsFunc()}; + } + +void zeek::id::detail::init() + { + conn_id = lookup_type("conn_id"); + endpoint = lookup_type("endpoint"); + connection = lookup_type("connection"); + fa_file = lookup_type("fa_file"); + fa_metadata = lookup_type("fa_metadata"); + transport_proto = lookup_type("transport_proto"); + string_set = lookup_type("string_set"); + string_array = lookup_type("string_array"); + count_set = lookup_type("count_set"); + string_vec = lookup_type("string_vec"); + index_vec = lookup_type("index_vec"); + } + ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) { name = copy_string(arg_name); diff --git a/src/ID.h b/src/ID.h index 0ec222f733..7965fc3c6d 100644 --- a/src/ID.h +++ b/src/ID.h @@ -16,6 +16,10 @@ class Val; class Expr; class Func; class BroType; +class RecordType; +class TableType; +class VectorType; +class EnumType; class Attributes; typedef enum { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, } init_class; @@ -152,3 +156,85 @@ protected: std::multimap> option_handlers; }; + +namespace zeek { namespace id { + +/** + * Lookup an ID in the global module and return it, if one exists; + * @param name The identifier name to lookup. + * @return The identifier, which may reference a nil object if no such + * name exists. + */ +IntrusivePtr lookup(const char* name); + +/** + * Lookup an ID by its name and return its type. A fatal occurs if the ID + * does not exist. + * @param name The identifier name to lookup + * @return The type of the identifier. + */ +const IntrusivePtr& lookup_type(const char* name); + +/** + * Lookup an ID by its name and return its type (as cast to @c T). + * A fatal occurs if the ID does not exist. + * @param name The identifier name to lookup + * @return The type of the identifier. + */ +template +IntrusivePtr lookup_type(const char* name) + { return cast_intrusive(lookup_type(name)); } + +/** + * Lookup an ID by its name and return its value. A fatal occurs if the ID + * does not exist. + * @param name The identifier name to lookup + * @return The current value of the identifier + */ +const IntrusivePtr& lookup_val(const char* name); + +/** + * Lookup an ID by its name and return its value (as cast to @c T). + * A fatal occurs if the ID does not exist. + * @param name The identifier name to lookup + * @return The current value of the identifier. + */ +template +IntrusivePtr lookup_val(const char* name) + { return cast_intrusive(lookup_val(name)); } + +/** + * Lookup an ID by its name and return its value. A fatal occurs if the ID + * does not exist or if it is not "const". + * @param name The identifier name to lookup + * @return The current value of the identifier + */ +const IntrusivePtr& lookup_const(const char* name); + +/** + * Lookup an ID by its name and return the function it references. + * A fatal occurs if the ID does not exist or if it is not a function. + * @param name The identifier name to lookup + * @return The current function value the identifier references. + */ +IntrusivePtr lookup_func(const char* name); + +extern IntrusivePtr conn_id; +extern IntrusivePtr endpoint; +extern IntrusivePtr connection; +extern IntrusivePtr fa_file; +extern IntrusivePtr fa_metadata; +extern IntrusivePtr transport_proto; +extern IntrusivePtr string_set; +extern IntrusivePtr string_array; +extern IntrusivePtr count_set; +extern IntrusivePtr string_vec; +extern IntrusivePtr index_vec; + +namespace detail { + +void init(); + +} // namespace zeek::id::detail + +}} // namespace zeek::id diff --git a/src/IP.cc b/src/IP.cc index fb98e32a76..a451cf26d8 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -13,8 +13,6 @@ #include "BroString.h" #include "Reporter.h" -using namespace zeek; - static RecordType* ip4_hdr_type = nullptr; static RecordType* ip6_hdr_type = nullptr; static RecordType* ip6_ext_hdr_type = nullptr; @@ -39,14 +37,14 @@ static RecordType* ip6_mob_be_type = nullptr; static inline RecordType* hdrType(RecordType*& type, const char* name) { if ( ! type ) - type = lookup_type(name)->AsRecordType(); + type = zeek::id::lookup_type(name)->AsRecordType(); return type; } static IntrusivePtr BuildOptionsVal(const u_char* data, int len) { - auto vv = make_intrusive(lookup_type("ip6_options")); + auto vv = make_intrusive(zeek::id::lookup_type("ip6_options")); while ( len > 0 ) { @@ -97,7 +95,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const rv->Assign(6, make_intrusive(IPAddr(ip6->ip6_dst))); if ( ! chain ) chain = make_intrusive( - lookup_type("ip6_ext_hdr_chain")); + zeek::id::lookup_type("ip6_ext_hdr_chain")); rv->Assign(7, std::move(chain)); } break; @@ -369,7 +367,7 @@ IntrusivePtr IP_Hdr::ToPktHdrVal() const static RecordType* pkt_hdr_type = nullptr; if ( ! pkt_hdr_type ) - pkt_hdr_type = lookup_type("pkt_hdr")->AsRecordType(); + pkt_hdr_type = zeek::id::lookup_type("pkt_hdr")->AsRecordType(); return ToPktHdrVal(make_intrusive(pkt_hdr_type), 0); } @@ -387,9 +385,9 @@ IntrusivePtr IP_Hdr::ToPktHdrVal(IntrusivePtr pkt_hdr, int if ( ! tcp_hdr_type ) { - tcp_hdr_type = lookup_type("tcp_hdr")->AsRecordType(); - udp_hdr_type = lookup_type("udp_hdr")->AsRecordType(); - icmp_hdr_type = lookup_type("icmp_hdr")->AsRecordType(); + tcp_hdr_type = zeek::id::lookup_type("tcp_hdr")->AsRecordType(); + udp_hdr_type = zeek::id::lookup_type("udp_hdr")->AsRecordType(); + icmp_hdr_type = zeek::id::lookup_type("icmp_hdr")->AsRecordType(); } if ( ip4 ) @@ -699,18 +697,18 @@ IntrusivePtr IPv6_Hdr_Chain::ToVal() const { if ( ! ip6_ext_hdr_type ) { - ip6_ext_hdr_type = lookup_type("ip6_ext_hdr")->AsRecordType(); - ip6_hopopts_type = lookup_type("ip6_hopopts")->AsRecordType(); - ip6_dstopts_type = lookup_type("ip6_dstopts")->AsRecordType(); - ip6_routing_type = lookup_type("ip6_routing")->AsRecordType(); - ip6_fragment_type = lookup_type("ip6_fragment")->AsRecordType(); - ip6_ah_type = lookup_type("ip6_ah")->AsRecordType(); - ip6_esp_type = lookup_type("ip6_esp")->AsRecordType(); - ip6_mob_type = lookup_type("ip6_mobility_hdr")->AsRecordType(); + ip6_ext_hdr_type = zeek::id::lookup_type("ip6_ext_hdr")->AsRecordType(); + ip6_hopopts_type = zeek::id::lookup_type("ip6_hopopts")->AsRecordType(); + ip6_dstopts_type = zeek::id::lookup_type("ip6_dstopts")->AsRecordType(); + ip6_routing_type = zeek::id::lookup_type("ip6_routing")->AsRecordType(); + ip6_fragment_type = zeek::id::lookup_type("ip6_fragment")->AsRecordType(); + ip6_ah_type = zeek::id::lookup_type("ip6_ah")->AsRecordType(); + ip6_esp_type = zeek::id::lookup_type("ip6_esp")->AsRecordType(); + ip6_mob_type = zeek::id::lookup_type("ip6_mobility_hdr")->AsRecordType(); } auto rval = make_intrusive( - lookup_type("ip6_ext_hdr_chain")); + zeek::id::lookup_type("ip6_ext_hdr_chain")); for ( size_t i = 1; i < chain.size(); ++i ) { diff --git a/src/NetVar.cc b/src/NetVar.cc index 1c20611d59..9d984ce871 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -6,6 +6,7 @@ #include "Var.h" #include "EventHandler.h" #include "Val.h" +#include "ID.h" RecordType* conn_id; RecordType* endpoint; @@ -219,6 +220,8 @@ void init_general_global_var() bits_per_uid = opt_internal_unsigned("bits_per_uid"); } +extern void zeek_legacy_netvar_init(); + void init_net_var() { #include "const.bif.netvar_init" @@ -226,7 +229,8 @@ void init_net_var() #include "reporter.bif.netvar_init" #include "supervisor.bif.netvar_init" - zeek::vars::detail::init(); + zeek::id::detail::init(); + zeek_legacy_netvar_init(); ignore_checksums = opt_internal_int("ignore_checksums"); partial_connection_ok = opt_internal_int("partial_connection_ok"); @@ -262,16 +266,16 @@ void init_net_var() opt_internal_double("tcp_storm_interarrival_thresh"); tcp_content_deliver_all_orig = - bool(zeek::lookup_val("tcp_content_deliver_all_orig")->AsBool()); + bool(zeek::id::lookup_val("tcp_content_deliver_all_orig")->AsBool()); tcp_content_deliver_all_resp = - bool(zeek::lookup_val("tcp_content_deliver_all_resp")->AsBool()); + bool(zeek::id::lookup_val("tcp_content_deliver_all_resp")->AsBool()); udp_content_deliver_all_orig = - bool(zeek::lookup_val("udp_content_deliver_all_orig")->AsBool()); + bool(zeek::id::lookup_val("udp_content_deliver_all_orig")->AsBool()); udp_content_deliver_all_resp = - bool(zeek::lookup_val("udp_content_deliver_all_resp")->AsBool()); + bool(zeek::id::lookup_val("udp_content_deliver_all_resp")->AsBool()); udp_content_delivery_ports_use_resp = - bool(zeek::lookup_val("udp_content_delivery_ports_use_resp")->AsBool()); + bool(zeek::id::lookup_val("udp_content_delivery_ports_use_resp")->AsBool()); dns_session_timeout = opt_internal_double("dns_session_timeout"); rpc_timeout = opt_internal_double("rpc_timeout"); diff --git a/src/NetVar.h b/src/NetVar.h index 688f28d5c7..2d37cb960c 100644 --- a/src/NetVar.h +++ b/src/NetVar.h @@ -6,19 +6,18 @@ #include "Func.h" #include "EventRegistry.h" #include "Stats.h" -#include "ZeekVars.h" -[[deprecated("Remove in v4.1. Use zeek::vars::conn_id.")]] +[[deprecated("Remove in v4.1. Use zeek::id::conn_id.")]] extern RecordType* conn_id; -[[deprecated("Remove in v4.1. Use zeek::vars::endpoint.")]] +[[deprecated("Remove in v4.1. Use zeek::id::endpoint.")]] extern RecordType* endpoint; [[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* endpoint_stats; -[[deprecated("Remove in v4.1. Use zeek::vars::connection.")]] +[[deprecated("Remove in v4.1. Use zeek::id::connection.")]] extern RecordType* connection_type; -[[deprecated("Remove in v4.1. Use zeek::vars::fa_file.")]] +[[deprecated("Remove in v4.1. Use zeek::id::fa_file.")]] extern RecordType* fa_file_type; -[[deprecated("Remove in v4.1. Use zeek::vars::fa_metadata.")]] +[[deprecated("Remove in v4.1. Use zeek::id::fa_metadata.")]] extern RecordType* fa_metadata_type; [[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* icmp_conn; @@ -34,17 +33,17 @@ extern RecordType* pcap_packet; extern RecordType* raw_pkt_hdr_type; [[deprecated("Remove in v4.1. Perform your own lookup.")]] extern RecordType* l2_hdr_type; -[[deprecated("Remove in v4.1. Use zeek::vars::transport_proto.")]] +[[deprecated("Remove in v4.1. Use zeek::id::transport_proto.")]] extern EnumType* transport_proto; -[[deprecated("Remove in v4.1. Use zeek::vars::string_set.")]] +[[deprecated("Remove in v4.1. Use zeek::id::string_set.")]] extern TableType* string_set; -[[deprecated("Remove in v4.1. Use zeek::vars::string_array.")]] +[[deprecated("Remove in v4.1. Use zeek::id::string_array.")]] extern TableType* string_array; -[[deprecated("Remove in v4.1. Use zeek::vars::count_set.")]] +[[deprecated("Remove in v4.1. Use zeek::id::count_set.")]] extern TableType* count_set; -[[deprecated("Remove in v4.1. Use zeek::vars::string_vec.")]] +[[deprecated("Remove in v4.1. Use zeek::id::string_vec.")]] extern VectorType* string_vec; -[[deprecated("Remove in v4.1. Use zeek::vars::index_vec.")]] +[[deprecated("Remove in v4.1. Use zeek::id::index_vec.")]] extern VectorType* index_vec; [[deprecated("Remove in v4.1. Perform your own lookup.")]] extern VectorType* mime_matches; diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index ff236fb894..dd6f75620c 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -981,7 +981,7 @@ ParaglobVal::ParaglobVal(std::unique_ptr p) IntrusivePtr ParaglobVal::Get(StringVal* &pattern) { - auto rval = make_intrusive(zeek::vars::string_vec); + auto rval = make_intrusive(zeek::id::string_vec); std::string string_pattern (reinterpret_cast(pattern->Bytes()), pattern->Len()); std::vector matches = this->internal_paraglob->get(string_pattern); diff --git a/src/Reporter.cc b/src/Reporter.cc index 57d35b7baf..77dec0c326 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -15,7 +15,7 @@ #include "Net.h" #include "Conn.h" #include "Timer.h" -#include "Var.h" +#include "ID.h" #include "EventHandler.h" #include "plugin/Plugin.h" #include "plugin/Manager.h" @@ -63,13 +63,13 @@ Reporter::~Reporter() void Reporter::InitOptions() { - info_to_stderr = zeek::lookup_val("Reporter::info_to_stderr")->AsBool(); - warnings_to_stderr = zeek::lookup_val("Reporter::warnings_to_stderr")->AsBool(); - errors_to_stderr = zeek::lookup_val("Reporter::errors_to_stderr")->AsBool(); - weird_sampling_rate = zeek::lookup_val("Weird::sampling_rate")->AsCount(); - weird_sampling_threshold = zeek::lookup_val("Weird::sampling_threshold")->AsCount(); - weird_sampling_duration = zeek::lookup_val("Weird::sampling_duration")->AsInterval(); - auto wl_val = zeek::lookup_val("Weird::sampling_whitelist")->AsTableVal(); + info_to_stderr = zeek::id::lookup_val("Reporter::info_to_stderr")->AsBool(); + warnings_to_stderr = zeek::id::lookup_val("Reporter::warnings_to_stderr")->AsBool(); + errors_to_stderr = zeek::id::lookup_val("Reporter::errors_to_stderr")->AsBool(); + weird_sampling_rate = zeek::id::lookup_val("Weird::sampling_rate")->AsCount(); + weird_sampling_threshold = zeek::id::lookup_val("Weird::sampling_threshold")->AsCount(); + weird_sampling_duration = zeek::id::lookup_val("Weird::sampling_duration")->AsInterval(); + auto wl_val = zeek::id::lookup_val("Weird::sampling_whitelist")->AsTableVal(); auto wl_table = wl_val->AsTable(); HashKey* k; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 3fb6925039..b7c43ccab8 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -6,9 +6,8 @@ #include "Reporter.h" #include "Scope.h" #include "Func.h" +#include "ID.h" #include "Val.h" -#include "Var.h" -#include "ZeekVars.h" static inline bool is_established(const analyzer::tcp::TCP_Endpoint* e) { @@ -145,7 +144,7 @@ RuleConditionEval::RuleConditionEval(const char* func) if ( f->Yield()->Tag() != TYPE_BOOL ) rules_error("eval function type must yield a 'bool'", func); - static auto signature_state = zeek::lookup_type("signature_state"); + static auto signature_state = zeek::id::lookup_type("signature_state"); TypeList tl; tl.Append(signature_state); tl.Append(base_type(TYPE_STRING)); diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index 03c5329597..75baa10f9b 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -80,7 +80,7 @@ RuleHdrTest::RuleHdrTest(Prot arg_prot, Comp arg_comp, vector arg_v) Val* RuleMatcher::BuildRuleStateValue(const Rule* rule, const RuleEndpointState* state) const { - static auto signature_state = zeek::lookup_type("signature_state"); + static auto signature_state = zeek::id::lookup_type("signature_state"); RecordVal* val = new RecordVal(signature_state); val->Assign(0, make_intrusive(rule->ID())); val->Assign(1, state->GetAnalyzer()->ConnVal()); diff --git a/src/Sessions.cc b/src/Sessions.cc index fd1d633ac0..8e04444298 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -81,7 +81,7 @@ NetSessions::NetSessions() dump_this_packet = false; num_packets_processed = 0; - static auto pkt_profile_file = zeek::lookup_val("pkt_profile_file"); + static auto pkt_profile_file = zeek::id::lookup_val("pkt_profile_file"); if ( pkt_profile_mode && pkt_profile_freq > 0 && pkt_profile_file ) pkt_profiler = new PacketProfiler(pkt_profile_mode, @@ -915,7 +915,7 @@ Connection* NetSessions::FindConnection(Val* v) int orig_h, orig_p; // indices into record's value list int resp_h, resp_p; - if ( vr == zeek::vars::conn_id ) + if ( vr == zeek::id::conn_id ) { orig_h = 0; orig_p = 1; @@ -1219,7 +1219,7 @@ bool NetSessions::IsLikelyServerPort(uint32_t port, TransportProto proto) const if ( ! have_cache ) { - auto likely_server_ports = zeek::lookup_val("likely_server_ports"); + auto likely_server_ports = zeek::id::lookup_val("likely_server_ports"); auto lv = likely_server_ports->ToPureListVal(); for ( int i = 0; i < lv->Length(); i++ ) port_cache.insert(lv->Idx(i)->InternalUnsigned()); diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index 9e679470b2..3f10077f6d 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -59,19 +59,19 @@ bool BroSubstring::DoesCover(const BroSubstring* bst) const VectorVal* BroSubstring::VecToPolicy(Vec* vec) { RecordType* sw_substring_type = - zeek::lookup_type("sw_substring")->AsRecordType(); + zeek::id::lookup_type("sw_substring")->AsRecordType(); if ( ! sw_substring_type ) return nullptr; RecordType* sw_align_type = - zeek::lookup_type("sw_align")->AsRecordType(); + zeek::id::lookup_type("sw_align")->AsRecordType(); if ( ! sw_align_type ) return nullptr; - auto sw_align_vec_type = zeek::lookup_type("sw_align_vec"); + auto sw_align_vec_type = zeek::id::lookup_type("sw_align_vec"); auto result = - make_intrusive(zeek::lookup_type("sw_substring_vec")); + make_intrusive(zeek::id::lookup_type("sw_substring_vec")); if ( vec ) { diff --git a/src/Stats.cc b/src/Stats.cc index e340e9ebb2..5f47644f74 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -5,7 +5,7 @@ #include "Event.h" #include "Net.h" #include "NetVar.h" -#include "Var.h" +#include "ID.h" #include "Sessions.h" #include "Scope.h" #include "DNS_Mgr.h" @@ -342,7 +342,7 @@ SampleLogger::SampleLogger() static TableType* load_sample_info = nullptr; if ( ! load_sample_info ) - load_sample_info = zeek::lookup_type("load_sample_info")->AsTableType(); + load_sample_info = zeek::id::lookup_type("load_sample_info")->AsTableType(); load_samples = new TableVal({NewRef{}, load_sample_info}); } diff --git a/src/Stmt.cc b/src/Stmt.cc index 1575e874eb..e085a95f19 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -201,8 +201,8 @@ static IntrusivePtr lookup_enum_val(const char* module_name, const char static void print_log(const std::vector>& vals) { auto plval = lookup_enum_val("Log", "PRINTLOG"); - auto record = make_intrusive(zeek::lookup_type("Log::PrintLogInfo")->AsRecordType()); - auto vec = make_intrusive(zeek::vars::string_vec); + auto record = make_intrusive(zeek::id::lookup_type("Log::PrintLogInfo")->AsRecordType()); + auto vec = make_intrusive(zeek::id::string_vec); for ( const auto& val : vals ) { @@ -237,7 +237,7 @@ IntrusivePtr PrintStmt::DoExec(std::vector> vals, } static auto print_log_type = static_cast( - zeek::lookup_val("Log::print_to_log")->AsEnum()); + zeek::id::lookup_val("Log::print_to_log")->AsEnum()); switch ( print_log_type ) { case BifEnum::Log::REDIRECT_NONE: diff --git a/src/TunnelEncapsulation.cc b/src/TunnelEncapsulation.cc index ad3461f8bb..61a4e7bbbb 100644 --- a/src/TunnelEncapsulation.cc +++ b/src/TunnelEncapsulation.cc @@ -20,7 +20,7 @@ IntrusivePtr EncapsulatingConn::ToVal() const { auto rv = make_intrusive(BifType::Record::Tunnel::EncapsulatingConn); - auto id_val = make_intrusive(zeek::vars::conn_id); + auto id_val = make_intrusive(zeek::id::conn_id); id_val->Assign(0, make_intrusive(src_addr)); id_val->Assign(1, val_mgr->Port(ntohs(src_port), proto)); id_val->Assign(2, make_intrusive(dst_addr)); diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 1dc01dfe6b..36933153d7 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -6,7 +6,7 @@ #include "IntrusivePtr.h" #include "NetVar.h" #include "IPAddr.h" -#include "Var.h" +#include "ID.h" #include "UID.h" #include @@ -198,7 +198,7 @@ public: IntrusivePtr ToVal() const { auto vv = make_intrusive( - zeek::lookup_type("EncapsulatingConnVector")); + zeek::id::lookup_type("EncapsulatingConnVector")); if ( conns ) { diff --git a/src/Type.cc b/src/Type.cc index bb3e1c4dd3..9dfe0ded36 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -796,8 +796,8 @@ static string container_type_name(const BroType* ft) IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const { - static auto record_field = zeek::lookup_type("record_field"); - static auto record_field_table = zeek::lookup_type("record_field_table"); + static auto record_field = zeek::id::lookup_type("record_field"); + static auto record_field_table = zeek::id::lookup_type("record_field_table"); auto rval = make_intrusive(record_field_table); for ( int i = 0; i < NumFields(); ++i ) diff --git a/src/Val.cc b/src/Val.cc index 91b6e12007..fd729116b8 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -34,7 +34,7 @@ #include "Conn.h" #include "Reporter.h" #include "IPAddr.h" -#include "Var.h" +#include "ID.h" #include "broker/Data.h" @@ -411,7 +411,7 @@ bool Val::WouldOverflow(const BroType* from_type, const BroType* to_type, const IntrusivePtr Val::GetRecordFields() { - static auto record_field_table = zeek::lookup_type("record_field_table"); + static auto record_field_table = zeek::id::lookup_type("record_field_table"); auto t = GetType().get(); if ( t->Tag() != TYPE_RECORD && t->Tag() != TYPE_TYPE ) @@ -1931,7 +1931,7 @@ IntrusivePtr TableVal::LookupSubnets(const SubNetVal* search) if ( ! subnets ) reporter->InternalError("LookupSubnets called on wrong table type"); - auto result = make_intrusive(zeek::lookup_type("subnet_vec")); + auto result = make_intrusive(zeek::id::lookup_type("subnet_vec")); auto matches = subnets->FindAll(search); for ( auto element : matches ) diff --git a/src/Var.cc b/src/Var.cc index 37b699c835..01b5329edb 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -15,6 +15,7 @@ #include "EventRegistry.h" #include "Traverse.h" #include "module_util.h" +#include "ID.h" static IntrusivePtr init_val(Expr* init, const BroType* t, IntrusivePtr aggr) @@ -657,7 +658,7 @@ void end_func(IntrusivePtr body) Val* internal_val(const char* name) { - return zeek::lookup_val(name).get(); + return zeek::id::lookup_val(name).get(); } id_list gather_outer_ids(Scope* scope, Stmt* body) @@ -682,7 +683,7 @@ id_list gather_outer_ids(Scope* scope, Stmt* body) Val* internal_const_val(const char* name) { - return zeek::lookup_const(name).get(); + return zeek::id::lookup_const(name).get(); } Val* opt_internal_val(const char* name) @@ -760,44 +761,12 @@ ListVal* internal_list_val(const char* name) BroType* internal_type(const char* name) { - return zeek::lookup_type(name).get(); - } - -const IntrusivePtr& zeek::lookup_val(const char* name) - { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); - - if ( ! id ) - reporter->InternalError("Failed to find variable named: %s", name); - - return id->GetVal(); - } - -const IntrusivePtr& zeek::lookup_const(const char* name) - { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); - - if ( ! id ) - reporter->InternalError("Failed to find variable named: %s", name); - - if ( ! id->IsConst() ) - reporter->InternalError("Variable is not 'const', but expected to be: %s", name); - - return id->GetVal(); - } - -const IntrusivePtr& zeek::lookup_type(const char* name) - { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); - if ( ! id ) - reporter->InternalError("Failed to find type named: %s", name); - - return id->GetType(); + return zeek::id::lookup_type(name).get(); } Func* internal_func(const char* name) { - const auto& v = zeek::lookup_val(name); + const auto& v = zeek::id::lookup_val(name); if ( v ) return v->AsFunc(); @@ -805,19 +774,6 @@ Func* internal_func(const char* name) return nullptr; } -IntrusivePtr zeek::lookup_func(const char* name) - { - const auto& v = zeek::lookup_val(name); - - if ( ! v ) - return nullptr; - - if ( ! IsFunc(v->GetType()->Tag()) ) - reporter->InternalError("Expected variable '%s' to be a function", name); - - return {NewRef{}, v->AsFunc()}; - } - EventHandlerPtr internal_handler(const char* name) { // If there already is an entry in the registry, we have a diff --git a/src/Var.h b/src/Var.h index 13cdf12716..86c4928866 100644 --- a/src/Var.h +++ b/src/Var.h @@ -40,88 +40,32 @@ extern void end_func(IntrusivePtr body); // Gather all IDs referenced inside a body that aren't part of a given scope. extern id_list gather_outer_ids(Scope* scope, Stmt* body); -[[deprecated("Remove in v4.1. Use zeek::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::lookup_val().")]] extern Val* internal_val(const char* name); -[[deprecated("Remove in v4.1. Use zeek::lookup_const().")]] +[[deprecated("Remove in v4.1. Use zeek::id::lookup_const().")]] extern Val* internal_const_val(const char* name); // internal error if not const -[[deprecated("Remove in v4.1. Use lookup_ID() or zeek::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] extern Val* opt_internal_val(const char* name); // returns nil if not defined extern double opt_internal_double(const char* name); extern bro_int_t opt_internal_int(const char* name); extern bro_uint_t opt_internal_unsigned(const char* name); -[[deprecated("Remove in v4.1. Use lookup_ID() or zeek::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] extern StringVal* opt_internal_string(const char* name); -[[deprecated("Remove in v4.1. Use lookup_ID() or zeek::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] extern TableVal* opt_internal_table(const char* name); // nil if not defined -[[deprecated("Remove in v4.1. Use lookup_ID(), zeek::lookup_val(), and/or TableVal::ToPureListVal().")]] +[[deprecated("Remove in v4.1. Use zeek::id::lookup(), zeek::id::lookup_val(), and/or TableVal::ToPureListVal().")]] extern ListVal* internal_list_val(const char* name); -[[deprecated("Remove in v4.1. Use zeek::lookup_type().")]] +[[deprecated("Remove in v4.1. Use zeek::id::lookup_type().")]] extern BroType* internal_type(const char* name); -[[deprecated("Remove in v4.1. Use zeek::lookup_func().")]] +[[deprecated("Remove in v4.1. Use zeek::id::lookup_func().")]] extern Func* internal_func(const char* name); extern EventHandlerPtr internal_handler(const char* name); extern int signal_val; // 0 if no signal pending - -namespace zeek { - -/** - * Lookup an ID by its name and return its type. A fatal occurs if the ID - * does not exist. - * @param name The identifier name to lookup - * @return The type of the identifier. - */ -const IntrusivePtr& lookup_type(const char* name); - -/** - * Lookup an ID by its name and return its type (as cast to @c T). - * A fatal occurs if the ID does not exist. - * @param name The identifier name to lookup - * @return The type of the identifier. - */ -template -IntrusivePtr lookup_type(const char* name) - { return cast_intrusive(lookup_type(name)); } - -/** - * Lookup an ID by its name and return its value. A fatal occurs if the ID - * does not exist. - * @param name The identifier name to lookup - * @return The current value of the identifier - */ -const IntrusivePtr& lookup_val(const char* name); - -/** - * Lookup an ID by its name and return its value (as cast to @c T). - * A fatal occurs if the ID does not exist. - * @param name The identifier name to lookup - * @return The current value of the identifier. - */ -template -IntrusivePtr lookup_val(const char* name) - { return cast_intrusive(lookup_val(name)); } - -/** - * Lookup an ID by its name and return its value. A fatal occurs if the ID - * does not exist or if it is not "const". - * @param name The identifier name to lookup - * @return The current value of the identifier - */ -const IntrusivePtr& lookup_const(const char* name); - -/** - * Lookup an ID by its name and return the function it references. - * A fatal occurs if the ID does not exist or if it is not a function. - * @param name The identifier name to lookup - * @return The current function value the identifier references. - */ -IntrusivePtr lookup_func(const char* name); - -} // namespace zeek diff --git a/src/ZeekVars.cc b/src/ZeekVars.cc deleted file mode 100644 index fc1040efb2..0000000000 --- a/src/ZeekVars.cc +++ /dev/null @@ -1,121 +0,0 @@ -// See the file "COPYING" in the main distribution directory for copyright. - -#include "ZeekVars.h" -#include "Var.h" -#include "NetVar.h" -#include "Scope.h" - -IntrusivePtr zeek::vars::conn_id; -IntrusivePtr zeek::vars::endpoint; -IntrusivePtr zeek::vars::connection; -IntrusivePtr zeek::vars::fa_file; -IntrusivePtr zeek::vars::fa_metadata; -IntrusivePtr zeek::vars::transport_proto; -IntrusivePtr zeek::vars::string_set; -IntrusivePtr zeek::vars::string_array; -IntrusivePtr zeek::vars::count_set; -IntrusivePtr zeek::vars::string_vec; -IntrusivePtr zeek::vars::index_vec; - -void zeek::vars::detail::init() - { - // Types - conn_id = zeek::lookup_type("conn_id"); - endpoint = zeek::lookup_type("endpoint"); - connection = zeek::lookup_type("connection"); - fa_file = zeek::lookup_type("fa_file"); - fa_metadata = zeek::lookup_type("fa_metadata"); - transport_proto = zeek::lookup_type("transport_proto"); - string_set = zeek::lookup_type("string_set"); - string_array = zeek::lookup_type("string_array"); - count_set = zeek::lookup_type("count_set"); - string_vec = zeek::lookup_type("string_vec"); - index_vec = zeek::lookup_type("index_vec"); - - // Note: to bypass deprecation warnings on setting the legacy globals, - // CMake was told to compile this file with -Wno-deprecated-declarations. - // Once the legacy globals are removed, that compile flag can go also. - ::conn_id = conn_id.get(); - ::endpoint = endpoint.get(); - ::connection_type = connection.get(); - ::fa_file_type = fa_file.get(); - ::fa_metadata_type = fa_metadata.get(); - ::icmp_conn = zeek::lookup_type("icmp_conn")->AsRecordType(); - ::icmp_context = zeek::lookup_type("icmp_context")->AsRecordType(); - ::signature_state = zeek::lookup_type("signature_state")->AsRecordType(); - ::SYN_packet = zeek::lookup_type("SYN_packet")->AsRecordType(); - ::pcap_packet = zeek::lookup_type("pcap_packet")->AsRecordType(); - ::raw_pkt_hdr_type = zeek::lookup_type("raw_pkt_hdr")->AsRecordType(); - ::l2_hdr_type = zeek::lookup_type("l2_hdr")->AsRecordType(); - ::transport_proto = transport_proto.get(); - ::string_set = string_set.get(); - ::string_array = string_array.get(); - ::count_set = count_set.get(); - ::string_vec = string_vec.get(); - ::index_vec = index_vec.get(); - ::mime_matches = zeek::lookup_type("mime_matches")->AsVectorType(); - ::mime_match = zeek::lookup_type("mime_match")->AsRecordType(); - ::socks_address = zeek::lookup_type("SOCKS::Address")->AsRecordType(); - ::mime_header_rec = zeek::lookup_type("mime_header_rec")->AsRecordType(); - ::mime_header_list = zeek::lookup_type("mime_header_list")->AsTableType(); - ::http_stats_rec = zeek::lookup_type("http_stats_rec")->AsRecordType(); - ::http_message_stat = zeek::lookup_type("http_message_stat")->AsRecordType(); - ::pm_mapping = zeek::lookup_type("pm_mapping")->AsRecordType(); - ::pm_mappings = zeek::lookup_type("pm_mappings")->AsTableType(); - ::pm_port_request = zeek::lookup_type("pm_port_request")->AsRecordType(); - ::pm_callit_request = zeek::lookup_type("pm_callit_request")->AsRecordType(); - ::geo_location = zeek::lookup_type("geo_location")->AsRecordType(); - ::entropy_test_result = zeek::lookup_type("entropy_test_result")->AsRecordType(); - ::dns_msg = zeek::lookup_type("dns_msg")->AsRecordType(); - ::dns_answer = zeek::lookup_type("dns_answer")->AsRecordType(); - ::dns_soa = zeek::lookup_type("dns_soa")->AsRecordType(); - ::dns_edns_additional = zeek::lookup_type("dns_edns_additional")->AsRecordType(); - ::dns_tsig_additional = zeek::lookup_type("dns_tsig_additional")->AsRecordType(); - ::dns_rrsig_rr = zeek::lookup_type("dns_rrsig_rr")->AsRecordType(); - ::dns_dnskey_rr = zeek::lookup_type("dns_dnskey_rr")->AsRecordType(); - ::dns_nsec3_rr = zeek::lookup_type("dns_nsec3_rr")->AsRecordType(); - ::dns_ds_rr = zeek::lookup_type("dns_ds_rr")->AsRecordType(); - ::rotate_info = zeek::lookup_type("rotate_info")->AsRecordType(); - ::irc_join_list = zeek::lookup_type("irc_join_list")->AsTableType(); - ::irc_join_info = zeek::lookup_type("irc_join_info")->AsRecordType(); - ::script_id = zeek::lookup_type("script_id")->AsRecordType(); - ::id_table = zeek::lookup_type("id_table")->AsTableType(); - ::record_field = zeek::lookup_type("record_field")->AsRecordType(); - ::record_field_table = zeek::lookup_type("record_field_table")->AsTableType(); - ::call_argument = zeek::lookup_type("call_argument")->AsRecordType(); - ::call_argument_vector = zeek::lookup_type("call_argument_vector")->AsVectorType(); - - ::log_rotate_base_time = zeek::lookup_val("log_rotate_base_time")->AsStringVal(); - ::pkt_profile_file = zeek::lookup_val("pkt_profile_file").get(); - ::likely_server_ports = zeek::lookup_val("likely_server_ports")->AsTableVal(); - ::tcp_content_delivery_ports_orig = zeek::lookup_val("tcp_content_delivery_ports_orig")->AsTableVal(); - ::tcp_content_delivery_ports_resp = zeek::lookup_val("tcp_content_delivery_ports_resp")->AsTableVal(); - ::stp_skip_src = zeek::lookup_val("stp_skip_src")->AsTableVal(); - ::dns_skip_auth = zeek::lookup_val("dns_skip_auth")->AsTableVal(); - ::dns_skip_addl = zeek::lookup_val("dns_skip_addl")->AsTableVal(); - ::udp_content_ports = zeek::lookup_val("udp_content_ports")->AsTableVal(); - ::udp_content_delivery_ports_orig = zeek::lookup_val("udp_content_delivery_ports_orig")->AsTableVal(); - ::udp_content_delivery_ports_resp = zeek::lookup_val("udp_content_delivery_ports_resp")->AsTableVal(); - ::profiling_file = zeek::lookup_val("profiling_file").get(); - ::global_hash_seed = zeek::lookup_val("global_hash_seed")->AsStringVal(); - ::tcp_reassembler_ports_orig = zeek::lookup_val("tcp_reassembler_ports_orig")->AsTableVal(); - ::tcp_reassembler_ports_resp = zeek::lookup_val("tcp_reassembler_ports_resp")->AsTableVal(); - ::peer_description = zeek::lookup_val("peer_description")->AsStringVal(); - ::trace_output_file = zeek::lookup_val("trace_output_file")->AsStringVal(); - ::cmd_line_bpf_filter = zeek::lookup_val("cmd_line_bpf_filter")->AsStringVal(); - - auto anon_id = global_scope()->Lookup("preserve_orig_addr"); - - if ( anon_id ) - preserve_orig_addr = anon_id->GetVal()->AsTableVal(); - - anon_id = global_scope()->Lookup("preserve_resp_addr"); - - if ( anon_id ) - preserve_resp_addr = anon_id->GetVal()->AsTableVal(); - - anon_id = global_scope()->Lookup("preserve_other_addr"); - - if ( anon_id ) - preserve_other_addr = anon_id->GetVal()->AsTableVal(); - } diff --git a/src/ZeekVars.h b/src/ZeekVars.h deleted file mode 100644 index 758be90da1..0000000000 --- a/src/ZeekVars.h +++ /dev/null @@ -1,28 +0,0 @@ -// See the file "COPYING" in the main distribution directory for copyright. - -#pragma once - -#include "Val.h" -#include "Type.h" -#include "IntrusivePtr.h" - -namespace zeek { namespace vars { namespace detail { -void init(); -}}} - -namespace zeek { namespace vars { - -// Common Types -extern IntrusivePtr conn_id; -extern IntrusivePtr endpoint; -extern IntrusivePtr connection; -extern IntrusivePtr fa_file; -extern IntrusivePtr fa_metadata; -extern IntrusivePtr transport_proto; -extern IntrusivePtr string_set; -extern IntrusivePtr string_array; -extern IntrusivePtr count_set; -extern IntrusivePtr string_vec; -extern IntrusivePtr index_vec; - -}} // namespace zeek::vars diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index 18f2569fda..3ef7b211f0 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -438,8 +438,8 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) if ( tcp_contents && ! reass ) { - static auto tcp_content_delivery_ports_orig = zeek::lookup_val("tcp_content_delivery_ports_orig"); - static auto tcp_content_delivery_ports_resp = zeek::lookup_val("tcp_content_delivery_ports_resp"); + static auto tcp_content_delivery_ports_orig = zeek::id::lookup_val("tcp_content_delivery_ports_orig"); + static auto tcp_content_delivery_ports_resp = zeek::id::lookup_val("tcp_content_delivery_ports_resp"); const auto& dport = val_mgr->Port(ntohs(conn->RespPort()), TRANSPORT_TCP); if ( ! reass ) @@ -462,7 +462,7 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) uint16_t resp_port = ntohs(conn->RespPort()); if ( resp_port == 22 || resp_port == 23 || resp_port == 513 ) { - static auto stp_skip_src = zeek::lookup_val("stp_skip_src"); + static auto stp_skip_src = zeek::id::lookup_val("stp_skip_src"); AddrVal src(conn->OrigAddr()); if ( ! stp_skip_src->Lookup(&src) ) diff --git a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc index d400cf771d..5c8f56b148 100644 --- a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc +++ b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc @@ -27,15 +27,15 @@ BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) if ( ! bt_tracker_headers ) { bt_tracker_headers = - zeek::lookup_type("bt_tracker_headers")->AsTableType(); + zeek::id::lookup_type("bt_tracker_headers")->AsTableType(); bittorrent_peer = - zeek::lookup_type("bittorrent_peer")->AsRecordType(); + zeek::id::lookup_type("bittorrent_peer")->AsRecordType(); bittorrent_peer_set = - zeek::lookup_type("bittorrent_peer_set")->AsTableType(); + zeek::id::lookup_type("bittorrent_peer_set")->AsTableType(); bittorrent_benc_value = - zeek::lookup_type("bittorrent_benc_value")->AsRecordType(); + zeek::id::lookup_type("bittorrent_benc_value")->AsRecordType(); bittorrent_benc_dir = - zeek::lookup_type("bittorrent_benc_dir")->AsTableType(); + zeek::id::lookup_type("bittorrent_benc_dir")->AsTableType(); } keep_alive = false; diff --git a/src/analyzer/protocol/conn-size/ConnSize.cc b/src/analyzer/protocol/conn-size/ConnSize.cc index 4742f6f50f..e7682111b2 100644 --- a/src/analyzer/protocol/conn-size/ConnSize.cc +++ b/src/analyzer/protocol/conn-size/ConnSize.cc @@ -174,8 +174,8 @@ void ConnSize_Analyzer::UpdateConnVal(RecordVal *conn_val) RecordVal *resp_endp = conn_val->Lookup("resp")->AsRecordVal(); // endpoint is the RecordType from NetVar.h - int pktidx = zeek::vars::endpoint->FieldOffset("num_pkts"); - int bytesidx = zeek::vars::endpoint->FieldOffset("num_bytes_ip"); + int pktidx = zeek::id::endpoint->FieldOffset("num_pkts"); + int bytesidx = zeek::id::endpoint->FieldOffset("num_bytes_ip"); if ( pktidx < 0 ) reporter->InternalError("'endpoint' record missing 'num_pkts' field"); diff --git a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac index 53233069d9..eb0e5ac7a7 100644 --- a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac +++ b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac @@ -20,7 +20,7 @@ refine flow DHCP_Flow += { if ( ! options ) { options = make_intrusive(BifType::Record::DHCP::Options); - all_options = make_intrusive(zeek::vars::index_vec); + all_options = make_intrusive(zeek::id::index_vec); options->Assign(0, all_options); } diff --git a/src/analyzer/protocol/dhcp/dhcp-options.pac b/src/analyzer/protocol/dhcp/dhcp-options.pac index 5d319826ab..eb0be08e4c 100644 --- a/src/analyzer/protocol/dhcp/dhcp-options.pac +++ b/src/analyzer/protocol/dhcp/dhcp-options.pac @@ -462,7 +462,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_par_req_list_option(v: OptionValue): bool %{ - auto params = make_intrusive(zeek::vars::index_vec); + auto params = make_intrusive(zeek::id::index_vec); int num_parms = ${v.par_req_list}->size(); vector* plist = ${v.par_req_list}; diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 048f88a326..12d6dc4f1b 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -91,8 +91,8 @@ void DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) int skip_addl = dns_skip_all_addl; if ( msg.ancount > 0 ) { // We did an answer, so can potentially skip auth/addl. - static auto dns_skip_auth = zeek::lookup_val("dns_skip_auth"); - static auto dns_skip_addl = zeek::lookup_val("dns_skip_addl"); + static auto dns_skip_auth = zeek::id::lookup_val("dns_skip_auth"); + static auto dns_skip_addl = zeek::id::lookup_val("dns_skip_addl"); skip_auth = skip_auth || msg.nscount == 0 || dns_skip_auth->Lookup(&server); @@ -595,7 +595,7 @@ bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, if ( dns_SOA_reply && ! msg->skip_event ) { - static auto dns_soa = zeek::lookup_type("dns_soa"); + static auto dns_soa = zeek::id::lookup_type("dns_soa"); auto r = make_intrusive(dns_soa); r->Assign(0, make_intrusive(new BroString(mname, mname_end - mname, true))); r->Assign(1, make_intrusive(new BroString(rname, rname_end - rname, true))); @@ -1002,7 +1002,7 @@ bool DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, int typebitmaps_len = rdlength - (data - data_start); - auto char_strings = make_intrusive(zeek::vars::string_vec); + auto char_strings = make_intrusive(zeek::id::string_vec); while ( typebitmaps_len > 0 && len > 0 ) { @@ -1077,7 +1077,7 @@ bool DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, int typebitmaps_len = rdlength - (data - data_start); - auto char_strings = make_intrusive(zeek::vars::string_vec); + auto char_strings = make_intrusive(zeek::id::string_vec); while ( typebitmaps_len > 0 && len > 0 ) { @@ -1292,7 +1292,7 @@ bool DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, return true; } - auto char_strings = make_intrusive(zeek::vars::string_vec); + auto char_strings = make_intrusive(zeek::id::string_vec); IntrusivePtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) @@ -1320,7 +1320,7 @@ bool DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, return true; } - auto char_strings = make_intrusive(zeek::vars::string_vec); + auto char_strings = make_intrusive(zeek::id::string_vec); IntrusivePtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) @@ -1439,7 +1439,7 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query) IntrusivePtr DNS_MsgInfo::BuildHdrVal() { - static auto dns_msg = zeek::lookup_type("dns_msg"); + static auto dns_msg = zeek::id::lookup_type("dns_msg"); auto r = make_intrusive(dns_msg); r->Assign(0, val_mgr->Count(id)); @@ -1461,7 +1461,7 @@ IntrusivePtr DNS_MsgInfo::BuildHdrVal() IntrusivePtr DNS_MsgInfo::BuildAnswerVal() { - static auto dns_answer = zeek::lookup_type("dns_answer"); + static auto dns_answer = zeek::id::lookup_type("dns_answer"); auto r = make_intrusive(dns_answer); r->Assign(0, val_mgr->Count(int(answer_type))); @@ -1477,7 +1477,7 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() { // We have to treat the additional record type in EDNS differently // than a regular resource record. - static auto dns_edns_additional = zeek::lookup_type("dns_edns_additional"); + static auto dns_edns_additional = zeek::id::lookup_type("dns_edns_additional"); auto r = make_intrusive(dns_edns_additional); r->Assign(0, val_mgr->Count(int(answer_type))); @@ -1511,7 +1511,7 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) { - static auto dns_tsig_additional = zeek::lookup_type("dns_tsig_additional"); + static auto dns_tsig_additional = zeek::id::lookup_type("dns_tsig_additional"); auto r = make_intrusive(dns_tsig_additional); double rtime = tsig->time_s + tsig->time_ms / 1000.0; @@ -1531,7 +1531,7 @@ IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) { - static auto dns_rrsig_rr = zeek::lookup_type("dns_rrsig_rr"); + static auto dns_rrsig_rr = zeek::id::lookup_type("dns_rrsig_rr"); auto r = make_intrusive(dns_rrsig_rr); r->Assign(0, query_name); @@ -1552,7 +1552,7 @@ IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) { - static auto dns_dnskey_rr = zeek::lookup_type("dns_dnskey_rr"); + static auto dns_dnskey_rr = zeek::id::lookup_type("dns_dnskey_rr"); auto r = make_intrusive(dns_dnskey_rr); r->Assign(0, query_name); @@ -1568,7 +1568,7 @@ IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) { - static auto dns_nsec3_rr = zeek::lookup_type("dns_nsec3_rr"); + static auto dns_nsec3_rr = zeek::id::lookup_type("dns_nsec3_rr"); auto r = make_intrusive(dns_nsec3_rr); r->Assign(0, query_name); @@ -1588,7 +1588,7 @@ IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) IntrusivePtr DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) { - static auto dns_ds_rr = zeek::lookup_type("dns_ds_rr"); + static auto dns_ds_rr = zeek::id::lookup_type("dns_ds_rr"); auto r = make_intrusive(dns_ds_rr); r->Assign(0, query_name); diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index 21091fc48b..f210f27644 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -615,7 +615,7 @@ HTTP_Message::~HTTP_Message() IntrusivePtr HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) { - static auto http_message_stat = zeek::lookup_type("http_message_stat"); + static auto http_message_stat = zeek::id::lookup_type("http_message_stat"); auto stat = make_intrusive(http_message_stat); int field = 0; stat->Assign(field++, make_intrusive(start_time, TYPE_TIME)); @@ -1152,7 +1152,7 @@ void HTTP_Analyzer::GenStats() { if ( http_stats ) { - static auto http_stats_rec = zeek::lookup_type("http_stats_rec"); + static auto http_stats_rec = zeek::id::lookup_type("http_stats_rec"); auto r = make_intrusive(http_stats_rec); r->Assign(0, val_mgr->Count(num_requests)); r->Assign(1, val_mgr->Count(num_replies)); diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 5ae6239ec2..947efce0db 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -225,7 +225,7 @@ ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, { if ( ! icmp_conn_val ) { - static auto icmp_conn = zeek::lookup_type("icmp_conn"); + static auto icmp_conn = zeek::id::lookup_type("icmp_conn"); icmp_conn_val = make_intrusive(icmp_conn); icmp_conn_val->Assign(0, make_intrusive(Conn()->OrigAddr())); @@ -351,9 +351,9 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP4Context(int len, const u_char } } - static auto icmp_context = zeek::lookup_type("icmp_context"); + static auto icmp_context = zeek::id::lookup_type("icmp_context"); auto iprec = make_intrusive(icmp_context); - auto id_val = make_intrusive(zeek::vars::conn_id); + auto id_val = make_intrusive(zeek::id::conn_id); id_val->Assign(0, make_intrusive(src_addr)); id_val->Assign(1, val_mgr->Port(src_port, proto)); @@ -411,9 +411,9 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP6Context(int len, const u_char } } - static auto icmp_context = zeek::lookup_type("icmp_context"); + static auto icmp_context = zeek::id::lookup_type("icmp_context"); auto iprec = make_intrusive(icmp_context); - auto id_val = make_intrusive(zeek::vars::conn_id); + auto id_val = make_intrusive(zeek::id::conn_id); id_val->Assign(0, make_intrusive(src_addr)); id_val->Assign(1, val_mgr->Port(src_port, proto)); @@ -729,13 +729,13 @@ IntrusivePtr ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha if ( ! icmp6_nd_option_type ) { - icmp6_nd_option_type = zeek::lookup_type("icmp6_nd_option")->AsRecordType(); + icmp6_nd_option_type = zeek::id::lookup_type("icmp6_nd_option")->AsRecordType(); icmp6_nd_prefix_info_type = - zeek::lookup_type("icmp6_nd_prefix_info")->AsRecordType(); + zeek::id::lookup_type("icmp6_nd_prefix_info")->AsRecordType(); } auto vv = make_intrusive( - zeek::lookup_type("icmp6_nd_options")); + zeek::id::lookup_type("icmp6_nd_options")); while ( caplen > 0 ) { diff --git a/src/analyzer/protocol/imap/imap-analyzer.pac b/src/analyzer/protocol/imap/imap-analyzer.pac index c6c6ffe87a..b8fe0652ec 100644 --- a/src/analyzer/protocol/imap/imap-analyzer.pac +++ b/src/analyzer/protocol/imap/imap-analyzer.pac @@ -59,7 +59,7 @@ refine connection IMAP_Conn += { if ( ! imap_capabilities ) return true; - auto capv = make_intrusive(zeek::vars::string_vec); + auto capv = make_intrusive(zeek::id::string_vec); for ( unsigned int i = 0; i< capabilities->size(); i++ ) { diff --git a/src/analyzer/protocol/irc/IRC.cc b/src/analyzer/protocol/irc/IRC.cc index 7305380c8d..1bab5d6c5d 100644 --- a/src/analyzer/protocol/irc/IRC.cc +++ b/src/analyzer/protocol/irc/IRC.cc @@ -44,8 +44,8 @@ inline void IRC_Analyzer::SkipLeadingWhitespace(string& str) void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) { - static auto irc_join_list = zeek::lookup_type("irc_join_list"); - static auto irc_join_info = zeek::lookup_type("irc_join_info"); + static auto irc_join_list = zeek::id::lookup_type("irc_join_list"); + static auto irc_join_info = zeek::id::lookup_type("irc_join_info"); tcp::TCP_ApplicationAnalyzer::DeliverStream(length, line, orig); if ( starttls ) @@ -273,7 +273,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) if ( parts.size() > 0 && parts[0][0] == ':' ) parts[0] = parts[0].substr(1); - auto set = make_intrusive(zeek::vars::string_set); + auto set = make_intrusive(zeek::id::string_set); for ( unsigned int i = 0; i < parts.size(); ++i ) { @@ -466,7 +466,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) if ( parts.size() > 0 && parts[0][0] == ':' ) parts[0] = parts[0].substr(1); - auto set = make_intrusive(zeek::vars::string_set); + auto set = make_intrusive(zeek::id::string_set); for ( unsigned int i = 0; i < parts.size(); ++i ) { @@ -953,7 +953,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) nick = nick.substr(0, pos); vector channelList = SplitWords(channels, ','); - auto set = make_intrusive(zeek::vars::string_set); + auto set = make_intrusive(zeek::id::string_set); for ( unsigned int i = 0; i < channelList.size(); ++i ) { diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index f61a12c4bc..c5bc3f1b8c 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -13,7 +13,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a %code{ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) { - auto vv = make_intrusive(zeek::lookup_type("KRB::Type_Value_Vector")); + auto vv = make_intrusive(zeek::id::lookup_type("KRB::Type_Value_Vector")); if ( ! data->data()->has_padata() ) return vv.release(); diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index 560a2b5b93..0802b98f1e 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -27,7 +27,7 @@ IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pname) VectorVal* proc_cipher_list(const Array* list) { - auto ciphers = make_intrusive(zeek::vars::index_vec); + auto ciphers = make_intrusive(zeek::id::index_vec); for ( uint i = 0; i < list->data()->size(); ++i ) ciphers->Assign(ciphers->Size(), asn1_integer_to_val((*list->data())[i], TYPE_COUNT)); return ciphers.release(); @@ -35,7 +35,7 @@ VectorVal* proc_cipher_list(const Array* list) VectorVal* proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) { - auto addrs = make_intrusive(zeek::lookup_type("KRB::Host_Address_Vector")); + auto addrs = make_intrusive(zeek::id::lookup_type("KRB::Host_Address_Vector")); for ( uint i = 0; i < list->addresses()->size(); ++i ) { @@ -94,7 +94,7 @@ RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list) { - auto tickets = make_intrusive(zeek::lookup_type("KRB::Ticket_Vector")); + auto tickets = make_intrusive(zeek::id::lookup_type("KRB::Ticket_Vector")); for ( uint i = 0; i < list->tickets()->size(); ++i ) { diff --git a/src/analyzer/protocol/login/Login.cc b/src/analyzer/protocol/login/Login.cc index 4339c97fc4..56fb7d1188 100644 --- a/src/analyzer/protocol/login/Login.cc +++ b/src/analyzer/protocol/login/Login.cc @@ -45,13 +45,13 @@ Login_Analyzer::Login_Analyzer(const char* name, Connection* conn) if ( ! re_skip_authentication ) { - IntrusivePtr skip_authentication = zeek::lookup_val("skip_authentication")->AsTableVal()->ToPureListVal(); - IntrusivePtr direct_login_prompts = zeek::lookup_val("direct_login_prompts")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_prompts = zeek::lookup_val("login_prompts")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_non_failure_msgs = zeek::lookup_val("login_non_failure_msgs")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_failure_msgs = zeek::lookup_val("login_failure_msgs")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_success_msgs = zeek::lookup_val("login_success_msgs")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_timeouts = zeek::lookup_val("login_timeouts")->AsTableVal()->ToPureListVal(); + IntrusivePtr skip_authentication = zeek::id::lookup_val("skip_authentication")->AsTableVal()->ToPureListVal(); + IntrusivePtr direct_login_prompts = zeek::id::lookup_val("direct_login_prompts")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_prompts = zeek::id::lookup_val("login_prompts")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_non_failure_msgs = zeek::id::lookup_val("login_non_failure_msgs")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_failure_msgs = zeek::id::lookup_val("login_failure_msgs")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_success_msgs = zeek::id::lookup_val("login_success_msgs")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_timeouts = zeek::id::lookup_val("login_timeouts")->AsTableVal()->ToPureListVal(); #ifdef USE_PERFTOOLS_DEBUG HeapLeakChecker::Disabler disabler; diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index 69e0ac4ef2..e181666488 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -1289,7 +1289,7 @@ void MIME_Entity::DebugPrintHeaders() IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) { - static auto mime_header_rec = zeek::lookup_type("mime_header_rec"); + static auto mime_header_rec = zeek::id::lookup_type("mime_header_rec"); auto header_record = make_intrusive(mime_header_rec); header_record->Assign(0, new_string_val(h->get_name())); auto upper_hn = new_string_val(h->get_name()); @@ -1301,7 +1301,7 @@ IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) IntrusivePtr MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) { - static auto mime_header_list = zeek::lookup_type("mime_header_list"); + static auto mime_header_list = zeek::id::lookup_type("mime_header_list"); auto t = make_intrusive(mime_header_list); for ( unsigned int i = 0; i < hlist.size(); ++i ) diff --git a/src/analyzer/protocol/mqtt/commands/subscribe.pac b/src/analyzer/protocol/mqtt/commands/subscribe.pac index a2bca0c0cd..a6d9b01dd8 100644 --- a/src/analyzer/protocol/mqtt/commands/subscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/subscribe.pac @@ -19,8 +19,8 @@ refine flow MQTT_Flow += { %{ if ( mqtt_subscribe ) { - auto topics = make_intrusive(zeek::vars::string_vec); - auto qos_levels = make_intrusive(zeek::vars::index_vec); + auto topics = make_intrusive(zeek::id::string_vec); + auto qos_levels = make_intrusive(zeek::id::index_vec); for ( auto topic: *${msg.topics} ) { diff --git a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac index cb0b747313..15342aef85 100644 --- a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac @@ -14,7 +14,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_unsubscribe ) { - auto topics = make_intrusive(zeek::vars::string_vec); + auto topics = make_intrusive(zeek::id::string_vec); for ( auto topic: *${msg.topics} ) { diff --git a/src/analyzer/protocol/mysql/mysql-analyzer.pac b/src/analyzer/protocol/mysql/mysql-analyzer.pac index 9d0f13ecb6..3e5ef0afd6 100644 --- a/src/analyzer/protocol/mysql/mysql-analyzer.pac +++ b/src/analyzer/protocol/mysql/mysql-analyzer.pac @@ -82,7 +82,7 @@ refine flow MySQL_Flow += { if ( ! mysql_result_row ) return true; - auto vt = zeek::vars::string_vec; + auto vt = zeek::id::string_vec; auto vv = make_intrusive(std::move(vt)); auto& bstring = ${msg.row.first_field.val}; diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index edbd34c57d..b8060730d4 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -192,7 +192,7 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(zeek::vars::index_vec); + auto auxgids = make_intrusive(zeek::id::index_vec); for (size_t i = 0; i < c->AuxGIDs().size(); ++i) { diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index 0789fb806b..2a60851e56 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -328,7 +328,7 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_ zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(zeek::vars::index_vec); + auto auxgids = make_intrusive(zeek::id::index_vec); for ( size_t i = 0; i < c->AuxGIDs().size(); ++i ) auxgids->Assign(i, val_mgr->Count(c->AuxGIDs()[i])); diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 2f4bbf1316..9d6a938587 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -138,7 +138,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu event = success ? pm_request_dump : pm_attempt_dump; if ( success ) { - static auto pm_mappings = zeek::lookup_type("pm_mappings"); + static auto pm_mappings = zeek::id::lookup_type("pm_mappings"); TableVal* mappings = new TableVal(pm_mappings); uint32_t nmap = 0; @@ -194,7 +194,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) { - static auto pm_mapping = zeek::lookup_type("pm_mapping"); + static auto pm_mapping = zeek::id::lookup_type("pm_mapping"); RecordVal* mapping = new RecordVal(pm_mapping); mapping->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -215,7 +215,7 @@ Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) { - static auto pm_port_request = zeek::lookup_type("pm_port_request"); + static auto pm_port_request = zeek::id::lookup_type("pm_port_request"); RecordVal* pr = new RecordVal(pm_port_request); pr->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -236,7 +236,7 @@ Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) Val* PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) { - static auto pm_callit_request = zeek::lookup_type("pm_callit_request"); + static auto pm_callit_request = zeek::id::lookup_type("pm_callit_request"); RecordVal* c = new RecordVal(pm_callit_request); c->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); diff --git a/src/analyzer/protocol/sip/sip-analyzer.pac b/src/analyzer/protocol/sip/sip-analyzer.pac index 26f7548c78..0b37a5c385 100644 --- a/src/analyzer/protocol/sip/sip-analyzer.pac +++ b/src/analyzer/protocol/sip/sip-analyzer.pac @@ -67,7 +67,7 @@ refine flow SIP_Flow += { function build_sip_headers_val(): BroVal %{ - static auto mime_header_list = zeek::lookup_type("mime_header_list"); + static auto mime_header_list = zeek::id::lookup_type("mime_header_list"); TableVal* t = new TableVal(mime_header_list); for ( unsigned int i = 0; i < headers.size(); ++i ) @@ -102,7 +102,7 @@ refine flow SIP_Flow += { function build_sip_header_val(name: const_bytestring, value: const_bytestring): BroVal %{ - static auto mime_header_rec = zeek::lookup_type("mime_header_rec"); + static auto mime_header_rec = zeek::id::lookup_type("mime_header_rec"); RecordVal* header_record = new RecordVal(mime_header_rec); IntrusivePtr name_val; diff --git a/src/analyzer/protocol/smb/smb1-com-negotiate.pac b/src/analyzer/protocol/smb/smb1-com-negotiate.pac index 38dc341a7a..837dcf4ef7 100644 --- a/src/analyzer/protocol/smb/smb1-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb1-com-negotiate.pac @@ -15,7 +15,7 @@ refine connection SMB_Conn += { %{ if ( smb1_negotiate_request ) { - auto dialects = make_intrusive(zeek::vars::string_vec); + auto dialects = make_intrusive(zeek::id::string_vec); for ( unsigned int i = 0; i < ${val.dialects}->size(); ++i ) { diff --git a/src/analyzer/protocol/smb/smb2-com-negotiate.pac b/src/analyzer/protocol/smb/smb2-com-negotiate.pac index 2fcd7f05db..7f6e42c60f 100644 --- a/src/analyzer/protocol/smb/smb2-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb2-com-negotiate.pac @@ -22,7 +22,7 @@ refine connection SMB_Conn += { %{ if ( smb2_negotiate_request ) { - auto dialects = make_intrusive(zeek::vars::index_vec); + auto dialects = make_intrusive(zeek::id::index_vec); for ( unsigned int i = 0; i < ${val.dialects}->size(); ++i ) dialects->Assign(i, val_mgr->Count((*${val.dialects})[i])); diff --git a/src/analyzer/protocol/smb/smb2-protocol.pac b/src/analyzer/protocol/smb/smb2-protocol.pac index 055e02377c..7c774d2f31 100644 --- a/src/analyzer/protocol/smb/smb2-protocol.pac +++ b/src/analyzer/protocol/smb/smb2-protocol.pac @@ -68,7 +68,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) rpreauth->Assign(0, val_mgr->Count(${ncv.preauth_integrity_capabilities.hash_alg_count})); rpreauth->Assign(1, val_mgr->Count(${ncv.preauth_integrity_capabilities.salt_length})); - auto ha = make_intrusive(zeek::vars::index_vec); + auto ha = make_intrusive(zeek::id::index_vec); for ( int i = 0; i < ${ncv.preauth_integrity_capabilities.hash_alg_count}; ++i ) { @@ -87,7 +87,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rencr = make_intrusive(BifType::Record::SMB2::EncryptionCapabilities); rencr->Assign(0, val_mgr->Count(${ncv.encryption_capabilities.cipher_count})); - auto c = make_intrusive(zeek::vars::index_vec); + auto c = make_intrusive(zeek::id::index_vec); for ( int i = 0; i < ${ncv.encryption_capabilities.cipher_count}; ++i ) { @@ -105,7 +105,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rcomp = make_intrusive(BifType::Record::SMB2::CompressionCapabilities); rcomp->Assign(0, val_mgr->Count(${ncv.compression_capabilities.alg_count})); - auto c = make_intrusive(zeek::vars::index_vec); + auto c = make_intrusive(zeek::id::index_vec); for ( int i = 0; i < ${ncv.compression_capabilities.alg_count}; ++i ) { diff --git a/src/analyzer/protocol/socks/socks-analyzer.pac b/src/analyzer/protocol/socks/socks-analyzer.pac index cf621d69be..e880f22bdc 100644 --- a/src/analyzer/protocol/socks/socks-analyzer.pac +++ b/src/analyzer/protocol/socks/socks-analyzer.pac @@ -24,7 +24,7 @@ refine connection SOCKS_Conn += { %{ if ( socks_request ) { - static auto socks_address = zeek::lookup_type("SOCKS::Address"); + static auto socks_address = zeek::id::lookup_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); sa->Assign(0, make_intrusive(htonl(${request.addr}))); @@ -49,7 +49,7 @@ refine connection SOCKS_Conn += { %{ if ( socks_reply ) { - static auto socks_address = zeek::lookup_type("SOCKS::Address"); + static auto socks_address = zeek::id::lookup_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); sa->Assign(0, make_intrusive(htonl(${reply.addr}))); @@ -82,7 +82,7 @@ refine connection SOCKS_Conn += { return false; } - static auto socks_address = zeek::lookup_type("SOCKS::Address"); + static auto socks_address = zeek::id::lookup_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); // This is dumb and there must be a better way (checking for presence of a field)... @@ -122,7 +122,7 @@ refine connection SOCKS_Conn += { function socks5_reply(reply: SOCKS5_Reply): bool %{ - static auto socks_address = zeek::lookup_type("SOCKS::Address"); + static auto socks_address = zeek::id::lookup_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); // This is dumb and there must be a better way (checking for presence of a field)... diff --git a/src/analyzer/protocol/ssh/ssh-analyzer.pac b/src/analyzer/protocol/ssh/ssh-analyzer.pac index d0032d9b77..da8c875882 100644 --- a/src/analyzer/protocol/ssh/ssh-analyzer.pac +++ b/src/analyzer/protocol/ssh/ssh-analyzer.pac @@ -12,7 +12,7 @@ VectorVal* name_list_to_vector(const bytestring& nl); // Copied from IRC_Analyzer::SplitWords VectorVal* name_list_to_vector(const bytestring& nl) { - VectorVal* vv = new VectorVal(zeek::vars::string_vec); + VectorVal* vv = new VectorVal(zeek::id::string_vec); string name_list = std_str(nl); if ( name_list.size() < 1 ) diff --git a/src/analyzer/protocol/ssl/proc-client-hello.pac b/src/analyzer/protocol/ssl/proc-client-hello.pac index 7c447bb39e..a1cfca8e59 100644 --- a/src/analyzer/protocol/ssl/proc-client-hello.pac +++ b/src/analyzer/protocol/ssl/proc-client-hello.pac @@ -23,7 +23,7 @@ else std::transform(cipher_suites24->begin(), cipher_suites24->end(), std::back_inserter(cipher_suites), to_int()); - auto cipher_vec = make_intrusive(zeek::vars::index_vec); + auto cipher_vec = make_intrusive(zeek::id::index_vec); for ( unsigned int i = 0; i < cipher_suites.size(); ++i ) { @@ -31,7 +31,7 @@ cipher_vec->Assign(i, ciph); } - auto comp_vec = make_intrusive(zeek::vars::index_vec); + auto comp_vec = make_intrusive(zeek::id::index_vec); if ( compression_methods ) { diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index 1635e375bf..2dc919bbaf 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -75,7 +75,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_ec_point_formats ) return true; - auto points = make_intrusive(zeek::vars::index_vec); + auto points = make_intrusive(zeek::id::index_vec); if ( point_format_list ) { @@ -94,7 +94,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_elliptic_curves ) return true; - auto curves = make_intrusive(zeek::vars::index_vec); + auto curves = make_intrusive(zeek::id::index_vec); if ( list ) { @@ -113,7 +113,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(zeek::vars::index_vec); + auto nglist = make_intrusive(zeek::id::index_vec); if ( keyshare ) { @@ -131,7 +131,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(zeek::vars::index_vec); + auto nglist = make_intrusive(zeek::id::index_vec); nglist->Assign(0u, val_mgr->Count(keyshare->namedgroup())); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -143,7 +143,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(zeek::vars::index_vec); + auto nglist = make_intrusive(zeek::id::index_vec); nglist->Assign(0u, val_mgr->Count(namedgroup)); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -155,7 +155,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_signature_algorithm ) return true; - auto slist = make_intrusive(zeek::lookup_type("signature_and_hashalgorithm_vec")); + auto slist = make_intrusive(zeek::id::lookup_type("signature_and_hashalgorithm_vec")); if ( supported_signature_algorithms ) { @@ -178,7 +178,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_application_layer_protocol_negotiation ) return true; - auto plist = make_intrusive(zeek::vars::string_vec); + auto plist = make_intrusive(zeek::id::string_vec); if ( protocols ) { @@ -194,7 +194,7 @@ refine connection Handshake_Conn += { function proc_server_name(rec: HandshakeRecord, list: ServerName[]) : bool %{ - auto servers = make_intrusive(zeek::vars::string_vec); + auto servers = make_intrusive(zeek::id::string_vec); if ( list ) { @@ -226,7 +226,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(zeek::vars::index_vec); + auto versions = make_intrusive(zeek::id::index_vec); if ( versions_list ) { @@ -245,7 +245,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(zeek::vars::index_vec); + auto versions = make_intrusive(zeek::id::index_vec); versions->Assign(0u, val_mgr->Count(version)); BifEvent::enqueue_ssl_extension_supported_versions(bro_analyzer(), bro_analyzer()->Conn(), @@ -259,7 +259,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_psk_key_exchange_modes ) return true; - auto modes = make_intrusive(zeek::vars::index_vec); + auto modes = make_intrusive(zeek::id::index_vec); if ( mode_list ) { @@ -492,7 +492,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_pre_shared_key_server_hello ) return true; - auto slist = make_intrusive(zeek::lookup_type("psk_identity_vec")); + auto slist = make_intrusive(zeek::id::lookup_type("psk_identity_vec")); if ( identities && identities->identities() ) { @@ -505,7 +505,7 @@ refine connection Handshake_Conn += { } } - auto blist = make_intrusive(zeek::vars::string_vec); + auto blist = make_intrusive(zeek::id::string_vec); if ( binders && binders->binders() ) { diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index f1bdd7639c..fc13e50848 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -107,7 +107,7 @@ static RecordVal* build_syn_packet_val(bool is_orig, const IP_Hdr* ip, options += opt_len; } - static auto SYN_packet = zeek::lookup_type("SYN_packet"); + static auto SYN_packet = zeek::id::lookup_type("SYN_packet"); RecordVal* v = new RecordVal(SYN_packet); v->Assign(0, val_mgr->Bool(is_orig)); @@ -1422,7 +1422,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) { auto p = reinterpret_cast(o + 2); auto num_pointers = (length - 2) / 4; - auto vt = zeek::vars::index_vec; + auto vt = zeek::id::index_vec; auto sack = make_intrusive(std::move(vt)); for ( auto i = 0; i < num_pointers; ++i ) @@ -2078,7 +2078,7 @@ bool TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int capl RecordVal* TCPStats_Endpoint::BuildStats() { - static auto endpoint_stats = zeek::lookup_type("endpoint_stats"); + static auto endpoint_stats = zeek::id::lookup_type("endpoint_stats"); RecordVal* stats = new RecordVal(endpoint_stats); stats->Assign(0, val_mgr->Count(num_pkts)); diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.cc b/src/analyzer/protocol/tcp/TCP_Reassembler.cc index 073bcb7ab6..9de7331255 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.cc +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.cc @@ -42,8 +42,8 @@ TCP_Reassembler::TCP_Reassembler(analyzer::Analyzer* arg_dst_analyzer, if ( ::tcp_contents ) { - static auto tcp_content_delivery_ports_orig = zeek::lookup_val("tcp_content_delivery_ports_orig"); - static auto tcp_content_delivery_ports_resp = zeek::lookup_val("tcp_content_delivery_ports_resp"); + static auto tcp_content_delivery_ports_orig = zeek::id::lookup_val("tcp_content_delivery_ports_orig"); + static auto tcp_content_delivery_ports_resp = zeek::id::lookup_val("tcp_content_delivery_ports_resp"); const auto& dst_port_val = val_mgr->Port(ntohs(tcp_analyzer->Conn()->RespPort()), TRANSPORT_TCP); const auto& ports = IsOrig() ? diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index bb551b08b7..fcd0f0323e 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -104,9 +104,9 @@ IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const if ( ! teredo_hdr_type ) { - teredo_hdr_type = zeek::lookup_type("teredo_hdr")->AsRecordType(); - teredo_auth_type = zeek::lookup_type("teredo_auth")->AsRecordType(); - teredo_origin_type = zeek::lookup_type("teredo_origin")->AsRecordType(); + teredo_hdr_type = zeek::id::lookup_type("teredo_hdr")->AsRecordType(); + teredo_auth_type = zeek::id::lookup_type("teredo_auth")->AsRecordType(); + teredo_origin_type = zeek::id::lookup_type("teredo_origin")->AsRecordType(); } auto teredo_hdr = make_intrusive(teredo_hdr_type); diff --git a/src/analyzer/protocol/udp/UDP.cc b/src/analyzer/protocol/udp/UDP.cc index f509d96cef..50c73fd51e 100644 --- a/src/analyzer/protocol/udp/UDP.cc +++ b/src/analyzer/protocol/udp/UDP.cc @@ -134,9 +134,9 @@ void UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig, if ( udp_contents ) { - static auto udp_content_ports = zeek::lookup_val("udp_content_ports"); - static auto udp_content_delivery_ports_orig = zeek::lookup_val("udp_content_delivery_ports_orig"); - static auto udp_content_delivery_ports_resp = zeek::lookup_val("udp_content_delivery_ports_resp"); + static auto udp_content_ports = zeek::id::lookup_val("udp_content_ports"); + static auto udp_content_delivery_ports_orig = zeek::id::lookup_val("udp_content_delivery_ports_orig"); + static auto udp_content_delivery_ports_resp = zeek::id::lookup_val("udp_content_delivery_ports_resp"); bool do_udp_contents = false; const auto& sport_val = val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP); const auto& dport_val = val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP); diff --git a/src/bro-bif.h b/src/bro-bif.h index a2586c692d..92702907f3 100644 --- a/src/bro-bif.h +++ b/src/bro-bif.h @@ -7,4 +7,5 @@ #include "NetVar.h" #include "Event.h" #include "Reporter.h" -#include "Var.h" +#include "ID.h" +#include "Var.h" // for internal_handler() diff --git a/src/broker/Data.cc b/src/broker/Data.cc index fa2de5dd73..39a84027dd 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -3,7 +3,7 @@ #include "Desc.h" #include "IntrusivePtr.h" #include "RE.h" -#include "Var.h" +#include "ID.h" #include "Scope.h" #include "module_util.h" #include "3rdparty/doctest.h" @@ -1154,7 +1154,7 @@ IntrusivePtr bro_broker::DataVal::castTo(BroType* t) BroType* bro_broker::DataVal::ScriptDataType() { if ( ! script_data_type ) - script_data_type = zeek::lookup_type("Broker::Data").get(); + script_data_type = zeek::id::lookup_type("Broker::Data").get(); return script_data_type; } diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 940407b032..f52e10259c 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -148,8 +148,8 @@ void Manager::InitPostScript() default_log_topic_prefix = get_option("Broker::default_log_topic_prefix")->AsString()->CheckString(); log_topic_func = get_option("Broker::log_topic")->AsFunc(); - log_id_type = zeek::lookup_type("Log::ID")->AsEnumType(); - writer_id_type = zeek::lookup_type("Log::Writer")->AsEnumType(); + log_id_type = zeek::id::lookup_type("Log::ID")->AsEnumType(); + writer_id_type = zeek::id::lookup_type("Log::Writer")->AsEnumType(); opaque_of_data_type = new OpaqueType("Broker::Data"); opaque_of_set_iterator = new OpaqueType("Broker::SetIterator"); @@ -157,7 +157,7 @@ void Manager::InitPostScript() opaque_of_vector_iterator = new OpaqueType("Broker::VectorIterator"); opaque_of_record_iterator = new OpaqueType("Broker::RecordIterator"); opaque_of_store_handle = new OpaqueType("Broker::Store"); - vector_of_data_type = make_intrusive(zeek::lookup_type("Broker::Data")); + vector_of_data_type = make_intrusive(zeek::id::lookup_type("Broker::Data")); // Register as a "dont-count" source first, we may change that later. iosource_mgr->Register(this, true); @@ -1245,13 +1245,13 @@ void Manager::ProcessStatus(broker::status stat) if ( ! event ) return; - auto ei = zeek::lookup_type("Broker::EndpointInfo")->AsRecordType(); + auto ei = zeek::id::lookup_type("Broker::EndpointInfo")->AsRecordType(); auto endpoint_info = make_intrusive(ei); if ( ctx ) { endpoint_info->Assign(0, make_intrusive(to_string(ctx->node))); - auto ni = zeek::lookup_type("Broker::NetworkInfo")->AsRecordType(); + auto ni = zeek::id::lookup_type("Broker::NetworkInfo")->AsRecordType(); auto network_info = make_intrusive(ni); if ( ctx->network ) diff --git a/src/broker/Store.cc b/src/broker/Store.cc index 5502179af8..a996923d75 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -1,6 +1,6 @@ #include "Store.h" #include "Desc.h" -#include "Var.h" +#include "ID.h" #include "broker/Manager.h" namespace bro_broker { @@ -15,7 +15,7 @@ EnumVal* query_status(bool success) if ( ! store_query_status ) { - store_query_status = zeek::lookup_type("Broker::QueryStatus")->AsEnumType(); + store_query_status = zeek::id::lookup_type("Broker::QueryStatus")->AsEnumType(); success_val = store_query_status->Lookup("Broker", "SUCCESS"); failure_val = store_query_status->Lookup("Broker", "FAILURE"); } diff --git a/src/broker/comm.bif b/src/broker/comm.bif index 8b6789464f..71a36b44b3 100644 --- a/src/broker/comm.bif +++ b/src/broker/comm.bif @@ -94,14 +94,14 @@ function Broker::__unpeer%(a: string, p: port%): bool function Broker::__peers%(%): PeerInfos %{ bro_broker::Manager::ScriptScopeGuard ssg; - auto rval = make_intrusive(zeek::lookup_type("Broker::PeerInfos")); + auto rval = make_intrusive(zeek::id::lookup_type("Broker::PeerInfos")); auto i = 0; for ( auto& p : broker_mgr->Peers() ) { - auto pi = zeek::lookup_type("Broker::PeerInfo")->AsRecordType(); - auto ei = zeek::lookup_type("Broker::EndpointInfo")->AsRecordType(); - auto ni = zeek::lookup_type("Broker::NetworkInfo")->AsRecordType(); + auto pi = zeek::id::lookup_type("Broker::PeerInfo")->AsRecordType(); + auto ei = zeek::id::lookup_type("Broker::EndpointInfo")->AsRecordType(); + auto ni = zeek::id::lookup_type("Broker::NetworkInfo")->AsRecordType(); auto peer_info = new RecordVal(pi); auto endpoint_info = new RecordVal(ei); auto network_info = new RecordVal(ni); diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 005978fef6..6f931e5d2e 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -23,16 +23,16 @@ using namespace file_analysis; static Val* empty_connection_table() { - auto tbl_index = make_intrusive(zeek::vars::conn_id); - tbl_index->Append(zeek::vars::conn_id); + auto tbl_index = make_intrusive(zeek::id::conn_id); + tbl_index->Append(zeek::id::conn_id); auto tbl_type = make_intrusive(std::move(tbl_index), - zeek::vars::connection); + zeek::id::connection); return new TableVal(std::move(tbl_type)); } static IntrusivePtr get_conn_id_val(const Connection* conn) { - auto v = make_intrusive(zeek::vars::conn_id); + auto v = make_intrusive(zeek::id::conn_id); v->Assign(0, make_intrusive(conn->OrigAddr())); v->Assign(1, val_mgr->Port(ntohs(conn->OrigPort()), conn->ConnTransport())); v->Assign(2, make_intrusive(conn->RespAddr())); @@ -62,22 +62,22 @@ void File::StaticInit() if ( id_idx != -1 ) return; - id_idx = Idx("id", zeek::vars::fa_file); - parent_id_idx = Idx("parent_id", zeek::vars::fa_file); - source_idx = Idx("source", zeek::vars::fa_file); - is_orig_idx = Idx("is_orig", zeek::vars::fa_file); - conns_idx = Idx("conns", zeek::vars::fa_file); - last_active_idx = Idx("last_active", zeek::vars::fa_file); - seen_bytes_idx = Idx("seen_bytes", zeek::vars::fa_file); - total_bytes_idx = Idx("total_bytes", zeek::vars::fa_file); - missing_bytes_idx = Idx("missing_bytes", zeek::vars::fa_file); - overflow_bytes_idx = Idx("overflow_bytes", zeek::vars::fa_file); - timeout_interval_idx = Idx("timeout_interval", zeek::vars::fa_file); - bof_buffer_size_idx = Idx("bof_buffer_size", zeek::vars::fa_file); - bof_buffer_idx = Idx("bof_buffer", zeek::vars::fa_file); - meta_mime_type_idx = Idx("mime_type", zeek::vars::fa_metadata); - meta_mime_types_idx = Idx("mime_types", zeek::vars::fa_metadata); - meta_inferred_idx = Idx("inferred", zeek::vars::fa_metadata); + id_idx = Idx("id", zeek::id::fa_file); + parent_id_idx = Idx("parent_id", zeek::id::fa_file); + source_idx = Idx("source", zeek::id::fa_file); + is_orig_idx = Idx("is_orig", zeek::id::fa_file); + conns_idx = Idx("conns", zeek::id::fa_file); + last_active_idx = Idx("last_active", zeek::id::fa_file); + seen_bytes_idx = Idx("seen_bytes", zeek::id::fa_file); + total_bytes_idx = Idx("total_bytes", zeek::id::fa_file); + missing_bytes_idx = Idx("missing_bytes", zeek::id::fa_file); + overflow_bytes_idx = Idx("overflow_bytes", zeek::id::fa_file); + timeout_interval_idx = Idx("timeout_interval", zeek::id::fa_file); + bof_buffer_size_idx = Idx("bof_buffer_size", zeek::id::fa_file); + bof_buffer_idx = Idx("bof_buffer", zeek::id::fa_file); + meta_mime_type_idx = Idx("mime_type", zeek::id::fa_metadata); + meta_mime_types_idx = Idx("mime_types", zeek::id::fa_metadata); + meta_inferred_idx = Idx("inferred", zeek::id::fa_metadata); } File::File(const std::string& file_id, const std::string& source_name, Connection* conn, @@ -91,7 +91,7 @@ File::File(const std::string& file_id, const std::string& source_name, Connectio DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Creating new File object", file_id.c_str()); - val = new RecordVal(zeek::vars::fa_file); + val = new RecordVal(zeek::id::fa_file); val->Assign(id_idx, make_intrusive(file_id.c_str())); SetSource(source_name); @@ -295,7 +295,7 @@ bool File::SetMime(const std::string& mime_type) if ( ! FileEventAvailable(file_sniff) ) return false; - auto meta = make_intrusive(zeek::vars::fa_metadata); + auto meta = make_intrusive(zeek::id::fa_metadata); meta->Assign(meta_mime_type_idx, make_intrusive(mime_type)); meta->Assign(meta_inferred_idx, val_mgr->False()); @@ -328,7 +328,7 @@ void File::InferMetadata() len = std::min(len, LookupFieldDefaultCount(bof_buffer_size_idx)); file_mgr->DetectMIME(data, len, &matches); - auto meta = make_intrusive(zeek::vars::fa_metadata); + auto meta = make_intrusive(zeek::id::fa_metadata); if ( ! matches.empty() ) { diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index 010087f6b9..85934166aa 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -3,7 +3,6 @@ #include "Manager.h" #include "File.h" #include "Analyzer.h" -#include "Var.h" #include "Event.h" #include "UID.h" #include "digest.h" @@ -432,7 +431,7 @@ string Manager::GetFileID(const analyzer::Tag& tag, Connection* c, bool is_orig) bool Manager::IsDisabled(const analyzer::Tag& tag) { if ( ! disabled ) - disabled = zeek::lookup_const("Files::disable")->AsTableVal(); + disabled = zeek::id::lookup_const("Files::disable")->AsTableVal(); auto index = val_mgr->Count(bool(tag)); auto yield = disabled->Lookup(index.get()); @@ -499,8 +498,8 @@ string Manager::DetectMIME(const u_char* data, uint64_t len) const IntrusivePtr file_analysis::GenMIMEMatchesVal(const RuleMatcher::MIME_Matches& m) { - static auto mime_matches = zeek::lookup_type("mime_matches"); - static auto mime_match = zeek::lookup_type("mime_match"); + static auto mime_matches = zeek::id::lookup_type("mime_matches"); + static auto mime_match = zeek::id::lookup_type("mime_match"); auto rval = make_intrusive(mime_matches); for ( RuleMatcher::MIME_Matches::const_iterator it = m.begin(); diff --git a/src/file_analysis/analyzer/entropy/Entropy.cc b/src/file_analysis/analyzer/entropy/Entropy.cc index eb3dbf6d8e..c2a35b27cb 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.cc +++ b/src/file_analysis/analyzer/entropy/Entropy.cc @@ -60,7 +60,7 @@ void Entropy::Finalize() montepi = scc = ent = mean = chisq = 0.0; entropy->Get(&ent, &chisq, &mean, &montepi, &scc); - static auto entropy_test_result = zeek::lookup_type("entropy_test_result"); + static auto entropy_test_result = zeek::id::lookup_type("entropy_test_result"); auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index 30f484b1b3..773dcb47c0 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -11,7 +11,7 @@ VectorVal* process_rvas(const RVAS* rvas); %code{ VectorVal* process_rvas(const RVAS* rva_table) { - auto rvas = make_intrusive(zeek::vars::index_vec); + auto rvas = make_intrusive(zeek::id::index_vec); for ( uint16 i=0; i < rva_table->rvas()->size(); ++i ) rvas->Assign(i, val_mgr->Count((*rva_table->rvas())[i]->size())); @@ -26,7 +26,7 @@ refine flow File += { function characteristics_to_bro(c: uint32, len: uint8): TableVal %{ uint64 mask = (len==16) ? 0xFFFF : 0xFFFFFFFF; - TableVal* char_set = new TableVal(zeek::vars::count_set); + TableVal* char_set = new TableVal(zeek::id::count_set); for ( uint16 i=0; i < len; ++i ) { if ( ((c >> i) & 0x1) == 1 ) diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index f8996a94ea..568837216e 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -634,7 +634,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp) //ocsp_resp_record->Assign(7, make_intrusive(len, buf)); //BIO_reset(bio); - certs_vector = new VectorVal(zeek::lookup_type("x509_opaque_vector")); + certs_vector = new VectorVal(zeek::id::lookup_type("x509_opaque_vector")); vl.emplace_back(AdoptRef{}, certs_vector); #if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER) diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index afd37d4958..b7ddbecad1 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -367,21 +367,21 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) { case GEN_DNS: if ( names == nullptr ) - names = new VectorVal(zeek::vars::string_vec); + names = new VectorVal(zeek::id::string_vec); names->Assign(names->Size(), bs); break; case GEN_URI: if ( uris == nullptr ) - uris = new VectorVal(zeek::vars::string_vec); + uris = new VectorVal(zeek::id::string_vec); uris->Assign(uris->Size(), bs); break; case GEN_EMAIL: if ( emails == nullptr ) - emails = new VectorVal(zeek::vars::string_vec); + emails = new VectorVal(zeek::id::string_vec); emails->Assign(emails->Size(), bs); break; @@ -391,7 +391,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) else if ( gen->type == GEN_IPADD ) { if ( ips == nullptr ) - ips = new VectorVal(zeek::lookup_type("addr_vec")); + ips = new VectorVal(zeek::id::lookup_type("addr_vec")); uint32_t* addr = (uint32_t*) gen->d.ip->data; diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index 622b08958f..003e19d1ac 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -556,7 +556,7 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str } int num_certs = sk_X509_num(chain); - chainVector = new VectorVal(zeek::lookup_type("x509_opaque_vector")); + chainVector = new VectorVal(zeek::id::lookup_type("x509_opaque_vector")); for ( int i = 0; i < num_certs; i++ ) { diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index d7331a920a..fdbf824042 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -594,8 +594,8 @@ void Packet::ProcessLayer2() IntrusivePtr Packet::ToRawPktHdrVal() const { - static auto raw_pkt_hdr_type = zeek::lookup_type("raw_pkt_hdr"); - static auto l2_hdr_type = zeek::lookup_type("l2_hdr"); + static auto raw_pkt_hdr_type = zeek::id::lookup_type("raw_pkt_hdr"); + static auto l2_hdr_type = zeek::id::lookup_type("l2_hdr"); auto pkt_hdr = make_intrusive(raw_pkt_hdr_type); RecordVal* l2_hdr = new RecordVal(l2_hdr_type); diff --git a/src/legacy-netvar-init.cc b/src/legacy-netvar-init.cc new file mode 100644 index 0000000000..926fff6ae9 --- /dev/null +++ b/src/legacy-netvar-init.cc @@ -0,0 +1,93 @@ + +#include "NetVar.h" +#include "Var.h" +#include "ID.h" +#include "Scope.h" + +// Compiled separately to avoid deprecation warnings at the assignment sites. +void zeek_legacy_netvar_init() + { + ::conn_id = zeek::id::conn_id.get(); + ::endpoint = zeek::id::endpoint.get(); + ::connection_type = zeek::id::connection.get(); + ::fa_file_type = zeek::id::fa_file.get(); + ::fa_metadata_type = zeek::id::fa_metadata.get(); + ::icmp_conn = zeek::id::lookup_type("icmp_conn")->AsRecordType(); + ::icmp_context = zeek::id::lookup_type("icmp_context")->AsRecordType(); + ::signature_state = zeek::id::lookup_type("signature_state")->AsRecordType(); + ::SYN_packet = zeek::id::lookup_type("SYN_packet")->AsRecordType(); + ::pcap_packet = zeek::id::lookup_type("pcap_packet")->AsRecordType(); + ::raw_pkt_hdr_type = zeek::id::lookup_type("raw_pkt_hdr")->AsRecordType(); + ::l2_hdr_type = zeek::id::lookup_type("l2_hdr")->AsRecordType(); + ::transport_proto = zeek::id::transport_proto.get(); + ::string_set = zeek::id::string_set.get(); + ::string_array = zeek::id::string_array.get(); + ::count_set = zeek::id::count_set.get(); + ::string_vec = zeek::id::string_vec.get(); + ::index_vec = zeek::id::index_vec.get(); + ::mime_matches = zeek::id::lookup_type("mime_matches")->AsVectorType(); + ::mime_match = zeek::id::lookup_type("mime_match")->AsRecordType(); + ::socks_address = zeek::id::lookup_type("SOCKS::Address")->AsRecordType(); + ::mime_header_rec = zeek::id::lookup_type("mime_header_rec")->AsRecordType(); + ::mime_header_list = zeek::id::lookup_type("mime_header_list")->AsTableType(); + ::http_stats_rec = zeek::id::lookup_type("http_stats_rec")->AsRecordType(); + ::http_message_stat = zeek::id::lookup_type("http_message_stat")->AsRecordType(); + ::pm_mapping = zeek::id::lookup_type("pm_mapping")->AsRecordType(); + ::pm_mappings = zeek::id::lookup_type("pm_mappings")->AsTableType(); + ::pm_port_request = zeek::id::lookup_type("pm_port_request")->AsRecordType(); + ::pm_callit_request = zeek::id::lookup_type("pm_callit_request")->AsRecordType(); + ::geo_location = zeek::id::lookup_type("geo_location")->AsRecordType(); + ::entropy_test_result = zeek::id::lookup_type("entropy_test_result")->AsRecordType(); + ::dns_msg = zeek::id::lookup_type("dns_msg")->AsRecordType(); + ::dns_answer = zeek::id::lookup_type("dns_answer")->AsRecordType(); + ::dns_soa = zeek::id::lookup_type("dns_soa")->AsRecordType(); + ::dns_edns_additional = zeek::id::lookup_type("dns_edns_additional")->AsRecordType(); + ::dns_tsig_additional = zeek::id::lookup_type("dns_tsig_additional")->AsRecordType(); + ::dns_rrsig_rr = zeek::id::lookup_type("dns_rrsig_rr")->AsRecordType(); + ::dns_dnskey_rr = zeek::id::lookup_type("dns_dnskey_rr")->AsRecordType(); + ::dns_nsec3_rr = zeek::id::lookup_type("dns_nsec3_rr")->AsRecordType(); + ::dns_ds_rr = zeek::id::lookup_type("dns_ds_rr")->AsRecordType(); + ::rotate_info = zeek::id::lookup_type("rotate_info")->AsRecordType(); + ::irc_join_list = zeek::id::lookup_type("irc_join_list")->AsTableType(); + ::irc_join_info = zeek::id::lookup_type("irc_join_info")->AsRecordType(); + ::script_id = zeek::id::lookup_type("script_id")->AsRecordType(); + ::id_table = zeek::id::lookup_type("id_table")->AsTableType(); + ::record_field = zeek::id::lookup_type("record_field")->AsRecordType(); + ::record_field_table = zeek::id::lookup_type("record_field_table")->AsTableType(); + ::call_argument = zeek::id::lookup_type("call_argument")->AsRecordType(); + ::call_argument_vector = zeek::id::lookup_type("call_argument_vector")->AsVectorType(); + + ::log_rotate_base_time = zeek::id::lookup_val("log_rotate_base_time")->AsStringVal(); + ::pkt_profile_file = zeek::id::lookup_val("pkt_profile_file").get(); + ::likely_server_ports = zeek::id::lookup_val("likely_server_ports")->AsTableVal(); + ::tcp_content_delivery_ports_orig = zeek::id::lookup_val("tcp_content_delivery_ports_orig")->AsTableVal(); + ::tcp_content_delivery_ports_resp = zeek::id::lookup_val("tcp_content_delivery_ports_resp")->AsTableVal(); + ::stp_skip_src = zeek::id::lookup_val("stp_skip_src")->AsTableVal(); + ::dns_skip_auth = zeek::id::lookup_val("dns_skip_auth")->AsTableVal(); + ::dns_skip_addl = zeek::id::lookup_val("dns_skip_addl")->AsTableVal(); + ::udp_content_ports = zeek::id::lookup_val("udp_content_ports")->AsTableVal(); + ::udp_content_delivery_ports_orig = zeek::id::lookup_val("udp_content_delivery_ports_orig")->AsTableVal(); + ::udp_content_delivery_ports_resp = zeek::id::lookup_val("udp_content_delivery_ports_resp")->AsTableVal(); + ::profiling_file = zeek::id::lookup_val("profiling_file").get(); + ::global_hash_seed = zeek::id::lookup_val("global_hash_seed")->AsStringVal(); + ::tcp_reassembler_ports_orig = zeek::id::lookup_val("tcp_reassembler_ports_orig")->AsTableVal(); + ::tcp_reassembler_ports_resp = zeek::id::lookup_val("tcp_reassembler_ports_resp")->AsTableVal(); + ::peer_description = zeek::id::lookup_val("peer_description")->AsStringVal(); + ::trace_output_file = zeek::id::lookup_val("trace_output_file")->AsStringVal(); + ::cmd_line_bpf_filter = zeek::id::lookup_val("cmd_line_bpf_filter")->AsStringVal(); + + auto anon_id = global_scope()->Lookup("preserve_orig_addr"); + + if ( anon_id ) + preserve_orig_addr = anon_id->GetVal()->AsTableVal(); + + anon_id = global_scope()->Lookup("preserve_resp_addr"); + + if ( anon_id ) + preserve_resp_addr = anon_id->GetVal()->AsTableVal(); + + anon_id = global_scope()->Lookup("preserve_other_addr"); + + if ( anon_id ) + preserve_other_addr = anon_id->GetVal()->AsTableVal(); + } diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 45578337cd..eda63641bc 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -313,7 +313,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) streams[idx]->event = event ? event_registry->Lookup(event->Name()) : nullptr; streams[idx]->columns = columns->Ref()->AsRecordType(); - streams[idx]->enable_remote = zeek::lookup_val("Log::enable_remote_logging")->AsBool(); + streams[idx]->enable_remote = zeek::id::lookup_val("Log::enable_remote_logging")->AsBool(); DBG_LOG(DBG_LOGGING, "Created new logging stream '%s', raising event %s", streams[idx]->name.c_str(), event ? streams[idx]->event->Name() : ""); @@ -1193,7 +1193,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken // Still need to set the WriterInfo's rotation parameters, which we // computed above. - static auto log_rotate_base_time = zeek::lookup_val("log_rotate_base_time"); + static auto log_rotate_base_time = zeek::id::lookup_val("log_rotate_base_time"); static auto base_time = log_rotate_base_time->AsString()->CheckString(); winfo->info->rotation_interval = winfo->interval; @@ -1276,7 +1276,7 @@ bool Manager::WriteFromRemote(EnumVal* id, EnumVal* writer, const string& path, void Manager::SendAllWritersTo(const broker::endpoint_info& ei) { - auto et = zeek::lookup_type("Log::Writer")->AsEnumType(); + auto et = zeek::id::lookup_type("Log::Writer")->AsEnumType(); for ( vector::iterator s = streams.begin(); s != streams.end(); ++s ) { @@ -1453,7 +1453,7 @@ void Manager::InstallRotationTimer(WriterInfo* winfo) if ( ! winfo->open_time ) winfo->open_time = network_time; - static auto log_rotate_base_time = zeek::lookup_val("log_rotate_base_time"); + static auto log_rotate_base_time = zeek::id::lookup_val("log_rotate_base_time"); static auto base_time = log_rotate_base_time->AsString()->CheckString(); double base = parse_rotate_base_time(base_time); diff --git a/src/probabilistic/Hasher.cc b/src/probabilistic/Hasher.cc index 5a229638dc..805e927a46 100644 --- a/src/probabilistic/Hasher.cc +++ b/src/probabilistic/Hasher.cc @@ -23,7 +23,7 @@ Hasher::seed_t Hasher::MakeSeed(const void* data, size_t size) assert(sizeof(tmpseed) == 16); - static auto global_hash_seed = zeek::lookup_val("global_hash_seed"); + static auto global_hash_seed = zeek::id::lookup_val("global_hash_seed"); if ( data ) hash_update(ctx, data, size); diff --git a/src/reporter.bif b/src/reporter.bif index 46084d13d3..d9a8166ac1 100644 --- a/src/reporter.bif +++ b/src/reporter.bif @@ -153,7 +153,7 @@ function Reporter::file_weird%(name: string, f: fa_file, addl: string &default=" ## Returns: Current weird sampling whitelist function Reporter::get_weird_sampling_whitelist%(%): string_set %{ - auto set = make_intrusive(zeek::vars::string_set); + auto set = make_intrusive(zeek::id::string_set); for ( auto el : reporter->GetWeirdSamplingWhitelist() ) { auto idx = make_intrusive(el); diff --git a/src/stats.bif b/src/stats.bif index 30853711a7..8451a6ed21 100644 --- a/src/stats.bif +++ b/src/stats.bif @@ -470,7 +470,7 @@ function get_reporter_stats%(%): ReporterStats auto r = make_intrusive(ReporterStats); int n = 0; - auto weirds_by_type = make_intrusive(zeek::lookup_type("table_string_of_count")); + auto weirds_by_type = make_intrusive(zeek::id::lookup_type("table_string_of_count")); for ( auto& kv : reporter->GetWeirdsByType() ) { diff --git a/src/strings.bif b/src/strings.bif index bef95c9bad..17e57a279b 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -204,7 +204,7 @@ static IntrusivePtr do_split_string(StringVal* str_val, int max_num_sep) { // string_vec is used early in the version script - do not use the NetVar. - auto rval = make_intrusive(zeek::lookup_type("string_vec")); + auto rval = make_intrusive(zeek::id::lookup_type("string_vec")); const u_char* s = str_val->Bytes(); int n = str_val->Len(); const u_char* end_of_s = s + n; @@ -259,7 +259,7 @@ static IntrusivePtr do_split_string(StringVal* str_val, Val* do_split(StringVal* str_val, RE_Matcher* re, int incl_sep, int max_num_sep) { - TableVal* a = new TableVal(zeek::vars::string_array); + TableVal* a = new TableVal(zeek::id::string_array); const u_char* s = str_val->Bytes(); int n = str_val->Len(); const u_char* end_of_s = s + n; @@ -713,7 +713,7 @@ function str_split%(s: string, idx: index_vec%): string_vec indices[i] = (*idx_v)[i]->AsCount(); BroString::Vec* result = s->AsString()->Split(indices); - auto result_v = make_intrusive(zeek::vars::string_vec); + auto result_v = make_intrusive(zeek::id::string_vec); if ( result ) { @@ -908,7 +908,7 @@ function safe_shell_quote%(source: string%): string ## .. zeek:see: find_last strstr function find_all%(str: string, re: pattern%) : string_set %{ - auto a = make_intrusive(zeek::vars::string_set); + auto a = make_intrusive(zeek::id::string_set); const u_char* s = str->Bytes(); const u_char* e = s + str->Len(); diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index df112cfb68..e6e7ebc3d8 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -363,7 +363,7 @@ static std::vector get_script_signature_files() // Parse rule files defined on the script level. char* script_signature_files = - copy_string(zeek::lookup_val("signature_files")->AsString()->CheckString()); + copy_string(zeek::id::lookup_val("signature_files")->AsString()->CheckString()); char* tmp = script_signature_files; char* s; @@ -724,7 +724,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, if ( ! options.pcap_file && ! options.interface ) { - const auto& interfaces_val = zeek::lookup_val("interfaces"); + const auto& interfaces_val = zeek::id::lookup_val("interfaces"); if ( interfaces_val ) { char* interfaces_str = @@ -784,7 +784,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, if ( profiling_interval > 0 ) { - const auto& profiling_file = zeek::lookup_val("profiling_file"); + const auto& profiling_file = zeek::id::lookup_val("profiling_file"); profiling_logger = new ProfileLogger(profiling_file->AsFile(), profiling_interval); diff --git a/src/zeek.bif b/src/zeek.bif index bdf0543375..ecfd522bc8 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1051,7 +1051,7 @@ function find_entropy%(data: string%): entropy_test_result e.Feed(data->Bytes(), data->Len()); e.Get(&ent, &chisq, &mean, &montepi, &scc); - static auto entropy_test_result = zeek::lookup_type("entropy_test_result"); + static auto entropy_test_result = zeek::id::lookup_type("entropy_test_result"); auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); @@ -1103,7 +1103,7 @@ function entropy_test_finish%(handle: opaque of entropy%): entropy_test_result montepi = scc = ent = mean = chisq = 0.0; static_cast(handle)->Get(&ent, &chisq, &mean, &montepi, &scc); - static auto entropy_test_result = zeek::lookup_type("entropy_test_result"); + static auto entropy_test_result = zeek::id::lookup_type("entropy_test_result"); auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); @@ -1471,7 +1471,7 @@ function sort%(v: any, ...%) : any ## .. zeek:see:: sort function order%(v: any, ...%) : index_vec %{ - auto result_v = make_intrusive(zeek::vars::index_vec); + auto result_v = make_intrusive(zeek::id::index_vec); if ( v->GetType()->Tag() != TYPE_VECTOR ) { @@ -1824,9 +1824,9 @@ function zeek_version%(%): string ## Returns: A string vector with the field names of *rt*. function record_type_to_vector%(rt: string%): string_vec %{ - auto result = make_intrusive(zeek::vars::string_vec); + auto result = make_intrusive(zeek::id::string_vec); - RecordType* type = zeek::lookup_type(rt->CheckString())->AsRecordType(); + RecordType* type = zeek::id::lookup_type(rt->CheckString())->AsRecordType(); for ( int i = 0; i < type->NumFields(); ++i ) result->Assign(i+1, make_intrusive(type->FieldName(i))); @@ -1853,7 +1853,7 @@ function type_name%(t: any%): string ## Returns: list of command-line arguments (``argv``) used to run Zeek. function zeek_args%(%): string_vec %{ - auto sv = zeek::vars::string_vec; + auto sv = zeek::id::string_vec; auto rval = make_intrusive(std::move(sv)); for ( auto i = 0; i < bro_argc; ++i ) @@ -1891,7 +1891,7 @@ function reading_traces%(%): bool ## .. zeek:see:: reading_live_traffic reading_traces function packet_source%(%): PacketSource %{ - auto ps_type = zeek::lookup_type("PacketSource")->AsRecordType(); + auto ps_type = zeek::id::lookup_type("PacketSource")->AsRecordType(); auto ps = iosource_mgr->GetPktSrc(); auto r = make_intrusive(ps_type); @@ -1941,14 +1941,14 @@ function global_sizes%(%): var_sizes ## .. zeek:see:: global_sizes function global_ids%(%): id_table %{ - static auto id_table = zeek::lookup_type("id_table"); + static auto id_table = zeek::id::lookup_type("id_table"); auto ids = make_intrusive(id_table); const auto& globals = global_scope()->Vars(); for ( const auto& global : globals ) { ID* id = global.second.get(); - static auto script_id = zeek::lookup_type("script_id"); + static auto script_id = zeek::id::lookup_type("script_id"); auto rec = make_intrusive(script_id); rec->Assign(0, make_intrusive(type_name(id->GetType()->Tag()))); rec->Assign(1, val_mgr->Bool(id->IsExport())); @@ -1994,7 +1994,7 @@ function lookup_ID%(id: string%) : any ## Returns: A table that describes the fields of a record. function record_fields%(rec: any%): record_field_table %{ - static auto record_field_table = zeek::lookup_type("record_field_table"); + static auto record_field_table = zeek::id::lookup_type("record_field_table"); if ( rec->GetType()->Tag() == TYPE_STRING ) { @@ -2189,7 +2189,7 @@ function is_v6_subnet%(s: subnet%): bool ## Returns: The vector of addresses contained in the routing header data. function routing0_data_to_addrs%(s: string%): addr_vec %{ - auto rval = make_intrusive(zeek::lookup_type("addr_vec")); + auto rval = make_intrusive(zeek::id::lookup_type("addr_vec")); int len = s->Len(); const u_char* bytes = s->Bytes(); @@ -2220,7 +2220,7 @@ function routing0_data_to_addrs%(s: string%): addr_vec ## .. zeek:see:: counts_to_addr function addr_to_counts%(a: addr%): index_vec %{ - auto rval = make_intrusive(zeek::vars::index_vec); + auto rval = make_intrusive(zeek::id::index_vec); const uint32_t* bytes; int len = a->AsAddr().GetBytes(&bytes); @@ -3214,16 +3214,16 @@ static IntrusivePtr map_conn_type(TransportProto tp) { switch ( tp ) { case TRANSPORT_UNKNOWN: - return zeek::vars::transport_proto->GetVal(0); + return zeek::id::transport_proto->GetVal(0); case TRANSPORT_TCP: - return zeek::vars::transport_proto->GetVal(1); + return zeek::id::transport_proto->GetVal(1); case TRANSPORT_UDP: - return zeek::vars::transport_proto->GetVal(2); + return zeek::id::transport_proto->GetVal(2); case TRANSPORT_ICMP: - return zeek::vars::transport_proto->GetVal(3); + return zeek::id::transport_proto->GetVal(3); default: reporter->InternalError("bad connection type in map_conn_type()"); @@ -3249,7 +3249,7 @@ function get_conn_transport_proto%(cid: conn_id%): transport_proto if ( ! c ) { builtin_error("unknown connection id in get_conn_transport_proto()", cid); - return zeek::vars::transport_proto->GetVal(0); + return zeek::id::transport_proto->GetVal(0); } return map_conn_type(c->ConnTransport()); @@ -3301,20 +3301,20 @@ function lookup_connection%(cid: conn_id%): connection builtin_error("connection ID not a known connection", cid); // Return a dummy connection record. - auto c = make_intrusive(zeek::vars::connection); + auto c = make_intrusive(zeek::id::connection); - auto id_val = make_intrusive(zeek::vars::conn_id); + auto id_val = make_intrusive(zeek::id::conn_id); id_val->Assign(0, make_intrusive((unsigned int) 0)); id_val->Assign(1, val_mgr->Port(ntohs(0), TRANSPORT_UDP)); id_val->Assign(2, make_intrusive((unsigned int) 0)); id_val->Assign(3, val_mgr->Port(ntohs(0), TRANSPORT_UDP)); c->Assign(0, std::move(id_val)); - auto orig_endp = make_intrusive(zeek::vars::endpoint); + auto orig_endp = make_intrusive(zeek::id::endpoint); orig_endp->Assign(0, val_mgr->Count(0)); orig_endp->Assign(1, val_mgr->Count(int(0))); - auto resp_endp = make_intrusive(zeek::vars::endpoint); + auto resp_endp = make_intrusive(zeek::id::endpoint); resp_endp->Assign(0, val_mgr->Count(0)); resp_endp->Assign(1, val_mgr->Count(int(0))); @@ -3323,7 +3323,7 @@ function lookup_connection%(cid: conn_id%): connection c->Assign(3, make_intrusive(network_time, TYPE_TIME)); c->Assign(4, make_intrusive(0.0, TYPE_INTERVAL)); - c->Assign(5, make_intrusive(zeek::vars::string_set)); // service + c->Assign(5, make_intrusive(zeek::id::string_set)); // service c->Assign(6, val_mgr->EmptyString()); // history return c; @@ -3385,7 +3385,7 @@ function dump_current_packet%(file_name: string%) : bool ## .. zeek:see:: dump_current_packet dump_packet function get_current_packet%(%) : pcap_packet %{ - static auto pcap_packet = zeek::lookup_type("pcap_packet"); + static auto pcap_packet = zeek::id::lookup_type("pcap_packet"); const Packet* p; auto pkt = make_intrusive(pcap_packet); @@ -3427,7 +3427,7 @@ function get_current_packet_header%(%) : raw_pkt_hdr return p->ToRawPktHdrVal(); } - static auto raw_pkt_hdr_type = zeek::lookup_type("raw_pkt_hdr"); + static auto raw_pkt_hdr_type = zeek::id::lookup_type("raw_pkt_hdr"); auto hdr = make_intrusive(raw_pkt_hdr_type); return hdr; %} @@ -3998,7 +3998,7 @@ function mmdb_open_asn_db%(f: string%) : bool ## .. zeek:see:: lookup_asn function lookup_location%(a: addr%) : geo_location %{ - static auto geo_location = zeek::lookup_type("geo_location"); + static auto geo_location = zeek::id::lookup_type("geo_location"); auto location = make_intrusive(geo_location); #ifdef USE_GEOIP @@ -4630,7 +4630,7 @@ function rotate_file%(f: file%): rotate_info return info; // Record indicating error. - static auto rotate_info = zeek::lookup_type("rotate_info"); + static auto rotate_info = zeek::id::lookup_type("rotate_info"); info = make_intrusive(rotate_info); info->Assign(0, val_mgr->EmptyString()); info->Assign(1, val_mgr->EmptyString()); @@ -4650,7 +4650,7 @@ function rotate_file%(f: file%): rotate_info ## .. zeek:see:: rotate_file calc_next_rotate function rotate_file_by_name%(f: string%): rotate_info %{ - static auto rotate_info = zeek::lookup_type("rotate_info"); + static auto rotate_info = zeek::id::lookup_type("rotate_info"); auto info = make_intrusive(rotate_info); bool is_pkt_dumper = false; @@ -4705,7 +4705,7 @@ function rotate_file_by_name%(f: string%): rotate_info ## .. zeek:see:: rotate_file rotate_file_by_name function calc_next_rotate%(i: interval%) : interval %{ - static auto log_rotate_base_time = zeek::lookup_val("log_rotate_base_time"); + static auto log_rotate_base_time = zeek::id::lookup_val("log_rotate_base_time"); static auto base_time = log_rotate_base_time->AsString()->CheckString(); double base = parse_rotate_base_time(base_time); From 8f95a2a0bb97c141e65812ab7a3b01bcd8a99c88 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 12 May 2020 22:20:42 -0700 Subject: [PATCH 048/151] Deprecate Scope::Lookup(), replace with Scope::Find() --- NEWS | 2 ++ src/Anon.cc | 6 +++--- src/Expr.cc | 2 +- src/ID.cc | 15 +++++---------- src/ID.h | 2 +- src/Net.cc | 2 +- src/OpaqueVal.cc | 2 +- src/RuleCondition.cc | 2 +- src/Scope.cc | 11 +++++------ src/Scope.h | 14 +++++++++++--- src/Type.cc | 2 +- src/Val.cc | 2 +- src/Var.cc | 2 +- src/analyzer/Manager.cc | 2 +- src/analyzer/protocol/mqtt/MQTT.cc | 10 ---------- src/analyzer/protocol/mqtt/MQTT.h | 2 -- src/analyzer/protocol/mqtt/commands/publish.pac | 3 ++- src/broker/Data.cc | 4 ++-- src/broker/Manager.cc | 6 +++--- src/broker/messaging.bif | 4 ++-- src/input/Manager.cc | 2 +- src/logging/Manager.cc | 4 ++-- src/option.bif | 6 +++--- src/supervisor/Supervisor.cc | 8 ++++---- src/zeek-setup.cc | 10 +++++----- src/zeek.bif | 4 ++-- src/zeekygen/ScriptInfo.cc | 8 ++++---- 27 files changed, 65 insertions(+), 72 deletions(-) diff --git a/NEWS b/NEWS index 1178de57a9..9ccc59bc80 100644 --- a/NEWS +++ b/NEWS @@ -174,6 +174,8 @@ Deprecated Functionality - Most global type/value pointers in NetVar.h are deprecated, but one can still always perform the lookup themselves. +- ``Scope::Lookup()`` is deprecated, use ``Scope::Find()``. + Zeek 3.1.0 ========== diff --git a/src/Anon.cc b/src/Anon.cc index 96b8d5473c..d129d0663a 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -368,17 +368,17 @@ void init_ip_addr_anonymizers() ip_anonymizer[PREFIX_PRESERVING_A50] = new AnonymizeIPAddr_A50(); ip_anonymizer[PREFIX_PRESERVING_MD5] = new AnonymizeIPAddr_PrefixMD5(); - auto id = global_scope()->Lookup("preserve_orig_addr"); + auto id = global_scope()->Find("preserve_orig_addr"); if ( id ) anon_preserve_orig_addr = cast_intrusive(id->GetVal()); - id = global_scope()->Lookup("preserve_resp_addr"); + id = global_scope()->Find("preserve_resp_addr"); if ( id ) anon_preserve_resp_addr = cast_intrusive(id->GetVal()); - id = global_scope()->Lookup("preserve_other_addr"); + id = global_scope()->Find("preserve_other_addr"); if ( id ) anon_preserve_other_addr = cast_intrusive(id->GetVal()); diff --git a/src/Expr.cc b/src/Expr.cc index 9a8bec21e1..8e70088fc6 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4227,7 +4227,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, my_name = "lambda_<" + std::to_string(h[0]) + ">"; auto fullname = make_full_var_name(current_module.data(), my_name.data()); - auto id = global_scope()->Lookup(fullname); + const auto& id = global_scope()->Find(fullname); if ( id ) // Just try again to make a unique lambda name. If two peer diff --git a/src/ID.cc b/src/ID.cc index 3184aa2aef..bf8972f324 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -31,19 +31,14 @@ IntrusivePtr zeek::id::count_set; IntrusivePtr zeek::id::string_vec; IntrusivePtr zeek::id::index_vec; -IntrusivePtr zeek::id::lookup(const char* name) +const IntrusivePtr& zeek::id::lookup(const char* name) { - auto id = global_scope()->Lookup(name); - - if ( ! id ) - return nullptr; - - return {NewRef{}, id}; + return global_scope()->Find(name); } const IntrusivePtr& zeek::id::lookup_type(const char* name) { - auto id = zeek::id::lookup(name); + auto id = global_scope()->Find(name); if ( ! id ) reporter->InternalError("Failed to find type named: %s", name); @@ -53,7 +48,7 @@ const IntrusivePtr& zeek::id::lookup_type(const char* name) const IntrusivePtr& zeek::id::lookup_val(const char* name) { - auto id = zeek::id::lookup(name); + auto id = global_scope()->Find(name); if ( ! id ) reporter->InternalError("Failed to find variable named: %s", name); @@ -63,7 +58,7 @@ const IntrusivePtr& zeek::id::lookup_val(const char* name) const IntrusivePtr& zeek::id::lookup_const(const char* name) { - auto id = zeek::id::lookup(name); + auto id = global_scope()->Find(name); if ( ! id ) reporter->InternalError("Failed to find variable named: %s", name); diff --git a/src/ID.h b/src/ID.h index 7965fc3c6d..d80be7f7c9 100644 --- a/src/ID.h +++ b/src/ID.h @@ -165,7 +165,7 @@ namespace zeek { namespace id { * @return The identifier, which may reference a nil object if no such * name exists. */ -IntrusivePtr lookup(const char* name); +const IntrusivePtr& lookup(const char* name); /** * Lookup an ID by its name and return its type. A fatal occurs if the ID diff --git a/src/Net.cc b/src/Net.cc index faac9e569a..9be8191000 100644 --- a/src/Net.cc +++ b/src/Net.cc @@ -193,7 +193,7 @@ void net_init(const std::optional& interface, reporter->FatalError("problem opening dump file %s (%s)", writefile, pkt_dumper->ErrorMsg()); - if ( ID* id = global_scope()->Lookup("trace_output_file") ) + if ( const auto& id = global_scope()->Find("trace_output_file") ) id->SetVal(make_intrusive(writefile)); else reporter->Error("trace_output_file not defined in bro.init"); diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index dd6f75620c..5f561ae9f5 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -126,7 +126,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data) if ( ! name ) return nullptr; - ID* id = global_scope()->Lookup(*name); + const auto& id = global_scope()->Find(*name); if ( ! id ) return nullptr; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index b7c43ccab8..9cb335e8e0 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -129,7 +129,7 @@ bool RuleConditionPayloadSize::DoMatch(Rule* rule, RuleEndpointState* state, RuleConditionEval::RuleConditionEval(const char* func) { - id = global_scope()->Lookup(func); + id = global_scope()->Find(func).get(); if ( ! id ) { rules_error("unknown identifier", func); diff --git a/src/Scope.cc b/src/Scope.cc index 79b7f46ced..5138361aed 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -129,24 +129,23 @@ IntrusivePtr lookup_ID(const char* name, const char* curr_module, for ( int i = scopes.length() - 1; i >= 0; --i ) { - ID* id = scopes[i]->Lookup(fullname); + const auto& id = scopes[i]->Find(fullname); + if ( id ) { if ( need_export && ! id->IsExport() && ! in_debug ) reporter->Error("identifier is not exported: %s", fullname.c_str()); - return {NewRef{}, id}; + return id; } } if ( ! no_global && (strcmp(GLOBAL_MODULE_NAME, curr_module) == 0 || - ! same_module_only) ) + ! same_module_only) ) { std::string globalname = make_full_var_name(GLOBAL_MODULE_NAME, name); - ID* id = global_scope()->Lookup(globalname); - if ( id ) - return {NewRef{}, id}; + return global_scope()->Find(globalname); } return nullptr; diff --git a/src/Scope.h b/src/Scope.h index 9fec692e8c..6687be3bfd 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -22,14 +22,22 @@ public: ~Scope() override; template - ID* Lookup(N&& name) const + const IntrusivePtr& Find(N&& name) const { + static IntrusivePtr nil; const auto& entry = local.find(std::forward(name)); if ( entry != local.end() ) - return entry->second.get(); + return entry->second; - return nullptr; + return nil; + } + + template + [[deprecated("Remove in v4.1. Use Find().")]] + ID* Lookup(N&& name) const + { + return Find(name).get(); } template diff --git a/src/Type.cc b/src/Type.cc index 9dfe0ded36..c7fd3cdbaa 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1766,7 +1766,7 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) // Doing a lookup here as a roundabout way of ref-ing t1, without // changing the function params which has t1 as const and also // (potentially) avoiding a pitfall mentioned earlier about clones. - auto id = global_scope()->Lookup(t1->GetName()); + const auto& id = global_scope()->Find(t1->GetName()); if ( id && id->IsType() && id->GetType()->Tag() == TYPE_ENUM ) // It should make most sense to return the real type here rather diff --git a/src/Val.cc b/src/Val.cc index fd729116b8..7b5962f403 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -371,7 +371,7 @@ void Val::ValDescribeReST(ODesc* d) const #ifdef DEBUG ID* Val::GetID() const { - return bound_id ? global_scope()->Lookup(bound_id) : nullptr; + return bound_id ? global_scope()->Find(bound_id).get() : nullptr; } void Val::SetID(ID* id) diff --git a/src/Var.cc b/src/Var.cc index 01b5329edb..13cc3c7ee7 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -609,7 +609,7 @@ TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr) return TC_CONTINUE; for ( const auto& scope : scopes ) - if ( scope->Lookup(e->Id()->Name()) ) + if ( scope->Find(e->Id()->Name()) ) // Shadowing is not allowed, so if it's found at inner scope, it's // not something we have to worry about also being at outer scope. return TC_CONTINUE; diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index 3ef7b211f0..9e339280da 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -90,7 +90,7 @@ void Manager::InitPreScript() void Manager::InitPostScript() { - auto id = global_scope()->Lookup("Tunnel::vxlan_ports"); + const auto& id = global_scope()->Find("Tunnel::vxlan_ports"); if ( ! (id && id->GetVal()) ) reporter->FatalError("Tunnel::vxlan_ports not defined"); diff --git a/src/analyzer/protocol/mqtt/MQTT.cc b/src/analyzer/protocol/mqtt/MQTT.cc index 7addafb3f9..4514f4d907 100644 --- a/src/analyzer/protocol/mqtt/MQTT.cc +++ b/src/analyzer/protocol/mqtt/MQTT.cc @@ -9,20 +9,10 @@ using namespace analyzer::MQTT; -const ::ID* MQTT_Analyzer::max_payload_size = nullptr; - MQTT_Analyzer::MQTT_Analyzer(Connection* c) : tcp::TCP_ApplicationAnalyzer("MQTT", c) { interp = new binpac::MQTT::MQTT_Conn(this); - - if ( ! max_payload_size ) - { - max_payload_size = global_scope()->Lookup("MQTT::max_payload_size"); - - if ( ! max_payload_size ) - reporter->FatalError("option not defined: 'MQTT::max_payload_size'"); - } } MQTT_Analyzer::~MQTT_Analyzer() diff --git a/src/analyzer/protocol/mqtt/MQTT.h b/src/analyzer/protocol/mqtt/MQTT.h index 5997d3430f..a1c4e36a2d 100644 --- a/src/analyzer/protocol/mqtt/MQTT.h +++ b/src/analyzer/protocol/mqtt/MQTT.h @@ -23,8 +23,6 @@ public: static analyzer::Analyzer* InstantiateAnalyzer(Connection* conn) { return new MQTT_Analyzer(conn); } - static const ::ID* max_payload_size; - protected: binpac::MQTT::MQTT_Conn* interp; diff --git a/src/analyzer/protocol/mqtt/commands/publish.pac b/src/analyzer/protocol/mqtt/commands/publish.pac index 029f52b899..72bce23c65 100644 --- a/src/analyzer/protocol/mqtt/commands/publish.pac +++ b/src/analyzer/protocol/mqtt/commands/publish.pac @@ -31,7 +31,8 @@ refine flow MQTT_Flow += { reinterpret_cast(${msg.topic.str}.begin()))); auto len = ${msg.payload}.length(); - auto max = analyzer::MQTT::MQTT_Analyzer::max_payload_size->GetVal()->AsCount(); + static auto max_payload_size = zeek::id::lookup("MQTT::max_payload_size"); + auto max = max_payload_size->GetVal()->AsCount(); if ( len > static_cast(max) ) len = max; diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 39a84027dd..24f6d55822 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -353,7 +353,7 @@ struct val_converter { if ( ! name ) return nullptr; - auto id = global_scope()->Lookup(*name); + const auto& id = global_scope()->Find(*name); if ( ! id ) return nullptr; @@ -697,7 +697,7 @@ struct type_checker { if ( ! name ) return false; - auto id = global_scope()->Lookup(*name); + const auto& id = global_scope()->Find(*name); if ( ! id ) return false; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index f52e10259c..9d7cc5f324 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -29,7 +29,7 @@ namespace bro_broker { static inline Val* get_option(const char* option) { - auto id = global_scope()->Lookup(option); + const auto& id = global_scope()->Find(option); if ( ! (id && id->GetVal()) ) reporter->FatalError("Unknown Broker option %s", option); @@ -412,7 +412,7 @@ bool Manager::PublishIdentifier(std::string topic, std::string id) if ( peer_count == 0 ) return true; - ID* i = global_scope()->Lookup(id); + const auto& i = global_scope()->Find(id); if ( ! i ) return false; @@ -1186,7 +1186,7 @@ bool Manager::ProcessIdentifierUpdate(broker::zeek::IdentifierUpdate iu) ++statistics.num_ids_incoming; auto id_name = std::move(iu.id_name()); auto id_value = std::move(iu.id_value()); - auto id = global_scope()->Lookup(id_name); + const auto& id = global_scope()->Find(id_name); if ( ! id ) { diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index fc5cfd3f31..0189c07c82 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -185,7 +185,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool static Func* topic_func = 0; if ( ! topic_func ) - topic_func = global_scope()->Lookup("Cluster::rr_topic")->GetVal()->AsFunc(); + topic_func = global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; auto topic = topic_func->Call(vl); @@ -222,7 +222,7 @@ function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool static Func* topic_func = 0; if ( ! topic_func ) - topic_func = global_scope()->Lookup("Cluster::hrw_topic")->GetVal()->AsFunc(); + topic_func = global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; auto topic = topic_func->Call(vl); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 23931b6f56..7034225a48 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -2498,7 +2498,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co // Enums are not a base-type, so need to look it up. const auto& sv = val->val.set_val.vals[0]->val.string_val; std::string enum_name(sv.data, sv.length); - auto enum_id = global_scope()->Lookup(enum_name); + const auto& enum_id = global_scope()->Find(enum_name); if ( ! enum_id ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index eda63641bc..1c4ff43653 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1182,7 +1182,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken if ( ! found_filter_match ) { - ID* id = global_scope()->Lookup("Log::default_rotation_interval"); + const auto& id = global_scope()->Find("Log::default_rotation_interval"); assert(id); winfo->interval = id->GetVal()->AsInterval(); } @@ -1525,7 +1525,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con Func* func = winfo->postprocessor; if ( ! func ) { - ID* id = global_scope()->Lookup("Log::__default_rotation_postprocessor"); + const auto& id = global_scope()->Find("Log::__default_rotation_postprocessor"); assert(id); func = id->GetVal()->AsFunc(); } diff --git a/src/option.bif b/src/option.bif index 353dc414c1..352ffb9631 100644 --- a/src/option.bif +++ b/src/option.bif @@ -7,7 +7,7 @@ module Option; #include "NetVar.h" #include "broker/Data.h" -static bool call_option_handlers_and_set_value(StringVal* name, ID* i, +static bool call_option_handlers_and_set_value(StringVal* name, const IntrusivePtr& i, IntrusivePtr val, StringVal* location) { @@ -59,7 +59,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, ID* i, ## lower-level function. function Option::set%(ID: string, val: any, location: string &default=""%): bool %{ - auto i = global_scope()->Lookup(ID->CheckString()); + const auto& i = global_scope()->Find(ID->CheckString()); if ( ! i ) { builtin_error(fmt("Could not find ID named '%s'", ID->CheckString())); @@ -144,7 +144,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool ## .. zeek:see:: Option::set function Option::set_change_handler%(ID: string, on_change: any, priority: int &default=0%): bool %{ - auto i = global_scope()->Lookup(ID->CheckString()); + const auto& i = global_scope()->Find(ID->CheckString()); if ( ! i ) { builtin_error(fmt("Could not find ID named '%s'", ID->CheckString())); diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 0a7e588112..bd52f241b0 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1172,7 +1172,7 @@ IntrusivePtr Supervisor::Node::ToRecord() const static IntrusivePtr supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role) { - static auto node_type = global_scope()->Lookup("Cluster::NodeType")->GetType()->AsEnumType(); + static auto node_type = global_scope()->Find("Cluster::NodeType")->GetType()->AsEnumType(); switch ( role ) { case BifEnum::Supervisor::LOGGER: @@ -1193,9 +1193,9 @@ bool Supervisor::SupervisedNode::InitCluster() const if ( config.cluster.empty() ) return false; - auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->GetType()->AsRecordType(); - auto cluster_nodes_id = global_scope()->Lookup("Cluster::nodes"); - auto cluster_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger"); + const auto& cluster_node_type = global_scope()->Find("Cluster::Node")->GetType()->AsRecordType(); + const auto& cluster_nodes_id = global_scope()->Find("Cluster::nodes"); + const auto& cluster_manager_is_logger_id = global_scope()->Find("Cluster::manager_is_logger"); auto cluster_nodes = cluster_nodes_id->GetVal()->AsTableVal(); auto has_logger = false; std::optional manager_name; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index e6e7ebc3d8..30d0486a6f 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -630,11 +630,11 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, // Must come after plugin activation (and also after hash // initialization). binpac::FlowBuffer::Policy flowbuffer_policy; - flowbuffer_policy.max_capacity = global_scope()->Lookup( + flowbuffer_policy.max_capacity = global_scope()->Find( "BinPAC::flowbuffer_capacity_max")->GetVal()->AsCount(); - flowbuffer_policy.min_capacity = global_scope()->Lookup( + flowbuffer_policy.min_capacity = global_scope()->Find( "BinPAC::flowbuffer_capacity_min")->GetVal()->AsCount(); - flowbuffer_policy.contract_threshold = global_scope()->Lookup( + flowbuffer_policy.contract_threshold = global_scope()->Find( "BinPAC::flowbuffer_contract_threshold")->GetVal()->AsCount(); binpac::init(&flowbuffer_policy); @@ -685,7 +685,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, if ( options.pcap_filter ) { - ID* id = global_scope()->Lookup("cmd_line_bpf_filter"); + const auto& id = global_scope()->Find("cmd_line_bpf_filter"); if ( ! id ) reporter->InternalError("global cmd_line_bpf_filter not defined"); @@ -769,7 +769,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, // Print the ID. if ( options.identifier_to_print ) { - ID* id = global_scope()->Lookup(*options.identifier_to_print); + const auto& id = global_scope()->Find(*options.identifier_to_print); if ( ! id ) reporter->FatalError("No such ID: %s\n", options.identifier_to_print->data()); diff --git a/src/zeek.bif b/src/zeek.bif index ecfd522bc8..cd202df1d7 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1975,7 +1975,7 @@ function global_ids%(%): id_table ## the string ``""`` or ``""`` is returned. function lookup_ID%(id: string%) : any %{ - ID* i = global_scope()->Lookup(id->CheckString()); + const auto& i = global_scope()->Find(id->CheckString()); if ( ! i ) return make_intrusive(""); @@ -1998,7 +1998,7 @@ function record_fields%(rec: any%): record_field_table if ( rec->GetType()->Tag() == TYPE_STRING ) { - auto id = global_scope()->Lookup(rec->AsStringVal()->ToStdString()); + const auto& id = global_scope()->Find(rec->AsStringVal()->ToStdString()); if ( ! id || ! id->IsType() || id->GetType()->Tag() != TYPE_RECORD ) { diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index 0861116902..7249f141d3 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -257,13 +257,13 @@ void ScriptInfo::DoInitPostScript() // so just manually associating them with scripts for now. if ( name == "base/frameworks/input/main.zeek" ) { - auto id = global_scope()->Lookup("Input::Reader"); - types.push_back(new IdentifierInfo({NewRef{}, id}, this)); + const auto& id = global_scope()->Find("Input::Reader"); + types.push_back(new IdentifierInfo(id, this)); } else if ( name == "base/frameworks/logging/main.zeek" ) { - auto id = global_scope()->Lookup("Log::Writer"); - types.push_back(new IdentifierInfo({NewRef{}, id}, this)); + const auto& id = global_scope()->Find("Log::Writer"); + types.push_back(new IdentifierInfo(id, this)); } } From 0af7f8141b8030b868464761d8a58ddcd44adb3b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 12 May 2020 22:41:52 -0700 Subject: [PATCH 049/151] Change lookup_ID() to return a const-reference --- src/Debug.cc | 2 +- src/EventHandler.cc | 4 ++-- src/Func.cc | 2 +- src/Scope.cc | 9 +++++---- src/Scope.h | 8 ++++---- src/Stmt.cc | 2 +- src/Var.cc | 14 +++++++------- src/parse.y | 13 ++++++++----- src/scan.l | 6 +++--- 9 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/Debug.cc b/src/Debug.cc index b28d03a7e2..3637516850 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -197,7 +197,7 @@ void get_first_statement(Stmt* list, Stmt*& first, Location& loc) static void parse_function_name(vector& result, ParseLocationRec& plr, const string& s) { // function name - auto id = lookup_ID(s.c_str(), current_module.c_str()); + const auto& id = lookup_ID(s.c_str(), current_module.c_str()); if ( ! id ) { diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 1f8edb162b..b4ccbd11fc 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -39,8 +39,8 @@ FuncType* EventHandler::FType(bool check_export) if ( type ) return type; - auto id = lookup_ID(name, current_module.c_str(), false, false, - check_export); + const auto& id = lookup_ID(name, current_module.c_str(), false, false, + check_export); if ( ! id ) return nullptr; diff --git a/src/Func.cc b/src/Func.cc index 51a6313998..12a2d4eef8 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -587,7 +587,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, name = make_full_var_name(GLOBAL_MODULE_NAME, arg_name); is_pure = arg_is_pure; - auto id = lookup_ID(Name(), GLOBAL_MODULE_NAME, false); + const auto& id = lookup_ID(Name(), GLOBAL_MODULE_NAME, false); if ( ! id ) reporter->InternalError("built-in function %s missing", Name()); if ( id->HasVal() ) diff --git a/src/Scope.cc b/src/Scope.cc index 5138361aed..8db868a571 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -117,9 +117,9 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const } -IntrusivePtr lookup_ID(const char* name, const char* curr_module, - bool no_global, bool same_module_only, - bool check_export) +const IntrusivePtr& lookup_ID(const char* name, const char* curr_module, + bool no_global, bool same_module_only, + bool check_export) { std::string fullname = make_full_var_name(curr_module, name); @@ -148,7 +148,8 @@ IntrusivePtr lookup_ID(const char* name, const char* curr_module, return global_scope()->Find(globalname); } - return nullptr; + static IntrusivePtr nil; + return nil; } IntrusivePtr install_ID(const char* name, const char* module_name, diff --git a/src/Scope.h b/src/Scope.h index 6687be3bfd..c83d706b42 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -90,10 +90,10 @@ protected: extern bool in_debug; // If no_global is true, don't search in the default "global" namespace. -extern IntrusivePtr lookup_ID(const char* name, const char* module, - bool no_global = false, - bool same_module_only = false, - bool check_export = true); +extern const IntrusivePtr& lookup_ID(const char* name, const char* module, + bool no_global = false, + bool same_module_only = false, + bool check_export = true); extern IntrusivePtr install_ID(const char* name, const char* module_name, bool is_global, bool is_export); diff --git a/src/Stmt.cc b/src/Stmt.cc index e085a95f19..9dda3e1bdd 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -186,7 +186,7 @@ static BroFile* print_stdout = nullptr; static IntrusivePtr lookup_enum_val(const char* module_name, const char* name) { - auto id = lookup_ID(name, module_name); + const auto& id = lookup_ID(name, module_name); assert(id); assert(id->IsEnumConst()); diff --git a/src/Var.cc b/src/Var.cc index 13cc3c7ee7..5c5c5e31e5 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -688,13 +688,13 @@ Val* internal_const_val(const char* name) Val* opt_internal_val(const char* name) { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); return id ? id->GetVal().get() : nullptr; } double opt_internal_double(const char* name) { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return 0.0; const auto& v = id->GetVal(); return v ? v->InternalDouble() : 0.0; @@ -702,7 +702,7 @@ double opt_internal_double(const char* name) bro_int_t opt_internal_int(const char* name) { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return 0; const auto& v = id->GetVal(); return v ? v->InternalInt() : 0; @@ -710,7 +710,7 @@ bro_int_t opt_internal_int(const char* name) bro_uint_t opt_internal_unsigned(const char* name) { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return 0; const auto& v = id->GetVal(); return v ? v->InternalUnsigned() : 0; @@ -718,7 +718,7 @@ bro_uint_t opt_internal_unsigned(const char* name) StringVal* opt_internal_string(const char* name) { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return nullptr; const auto& v = id->GetVal(); return v ? v->AsStringVal() : nullptr; @@ -726,7 +726,7 @@ StringVal* opt_internal_string(const char* name) TableVal* opt_internal_table(const char* name) { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return nullptr; const auto& v = id->GetVal(); return v ? v->AsTableVal() : nullptr; @@ -734,7 +734,7 @@ TableVal* opt_internal_table(const char* name) ListVal* internal_list_val(const char* name) { - auto id = lookup_ID(name, GLOBAL_MODULE_NAME); + const auto& id = lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) return nullptr; diff --git a/src/parse.y b/src/parse.y index 5ed3aa4797..fc00faa925 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1599,7 +1599,7 @@ event: TOK_ID '(' opt_expr_list ')' { set_location(@1, @4); - auto id = lookup_ID($1, current_module.c_str()); + const auto& id = lookup_ID($1, current_module.c_str()); if ( id ) { @@ -1769,7 +1769,8 @@ local_id: TOK_ID { set_location(@1); - $$ = lookup_ID($1, current_module.c_str()).release(); + auto id = lookup_ID($1, current_module.c_str()); + $$ = id.release(); if ( $$ ) { @@ -1805,8 +1806,9 @@ global_or_event_id: TOK_ID { set_location(@1); - $$ = lookup_ID($1, current_module.c_str(), false, - defining_global_ID).release(); + auto id = lookup_ID($1, current_module.c_str(), false, + defining_global_ID); + $$ = id.release(); if ( $$ ) { @@ -1842,7 +1844,8 @@ resolve_id: TOK_ID { set_location(@1); - $$ = lookup_ID($1, current_module.c_str()).release(); + auto id = lookup_ID($1, current_module.c_str()); + $$ = id.release(); if ( ! $$ ) reporter->Error("identifier not defined: %s", $1); diff --git a/src/scan.l b/src/scan.l index fd23c6e5c8..54cacdb52c 100644 --- a/src/scan.l +++ b/src/scan.l @@ -774,7 +774,7 @@ void do_atifdef(const char* id) { ++current_depth; - auto i = lookup_ID(id, current_module.c_str()); + const auto& i = lookup_ID(id, current_module.c_str()); if ( ! i ) { @@ -787,7 +787,7 @@ void do_atifndef(const char *id) { ++current_depth; - auto i = lookup_ID(id, current_module.c_str()); + const auto& i = lookup_ID(id, current_module.c_str()); if ( i ) { @@ -1000,7 +1000,7 @@ int yywrap() // string type.) If no type is found, the value // is left unchanged. std::string opt_quote; // no optional quote by default - auto param_id = lookup_ID(param, GLOBAL_MODULE_NAME); + const auto& param_id = lookup_ID(param, GLOBAL_MODULE_NAME); Val* v = param_id ? param_id->GetVal().get() : nullptr; if ( v && v->GetType() && v->GetType()->Tag() == TYPE_STRING ) From 86cbab3b7f30986a3dccec268dc8501783724f39 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 12 May 2020 23:01:09 -0700 Subject: [PATCH 050/151] Change Scope::Find() and Scope::Remove() to use std::string_view --- src/Scope.cc | 29 ++++++++++++++++++++++++++--- src/Scope.h | 34 +++++----------------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/Scope.cc b/src/Scope.cc index 8db868a571..d6c0c343e1 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -14,7 +14,7 @@ typedef PList scope_list; static scope_list scopes; static Scope* top_scope; - +static IntrusivePtr nil_id; Scope::Scope(IntrusivePtr id, attr_list* al) : scope_id(std::move(id)) @@ -57,6 +57,30 @@ Scope::~Scope() } } +const IntrusivePtr& Scope::Find(std::string_view name) const + { + auto entry = local.find(name); + + if ( entry != local.end() ) + return entry->second; + + return nil_id; + } + +IntrusivePtr Scope::Remove(std::string_view name) + { + auto entry = local.find(name); + + if ( entry != local.end() ) + { + auto id = std::move(entry->second); + local.erase(entry); + return id; + } + + return nullptr; + } + ID* Scope::GenerateTemporary(const char* name) { return new ID(name, SCOPE_FUNCTION, false); @@ -148,8 +172,7 @@ const IntrusivePtr& lookup_ID(const char* name, const char* curr_module, return global_scope()->Find(globalname); } - static IntrusivePtr nil; - return nil; + return nil_id; } IntrusivePtr install_ID(const char* name, const char* module_name, diff --git a/src/Scope.h b/src/Scope.h index c83d706b42..5201d1b5e0 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -4,6 +4,7 @@ #include #include +#include #include #include "Obj.h" @@ -21,42 +22,17 @@ public: explicit Scope(IntrusivePtr id, attr_list* al); ~Scope() override; - template - const IntrusivePtr& Find(N&& name) const - { - static IntrusivePtr nil; - const auto& entry = local.find(std::forward(name)); - - if ( entry != local.end() ) - return entry->second; - - return nil; - } + const IntrusivePtr& Find(std::string_view name) const; template [[deprecated("Remove in v4.1. Use Find().")]] ID* Lookup(N&& name) const - { - return Find(name).get(); - } + { return Find(name).get(); } template void Insert(N&& name, I&& id) { local[std::forward(name)] = std::forward(id); } - template - IntrusivePtr Remove(N&& name) - { - const auto& entry = local.find(std::forward(name)); - - if ( entry != local.end() ) - { - auto id = std::move(entry->second); - local.erase(entry); - return id; - } - - return nullptr; - } + IntrusivePtr Remove(std::string_view name); ID* ScopeID() const { return scope_id.get(); } attr_list* Attrs() const { return attrs; } @@ -82,7 +58,7 @@ protected: IntrusivePtr scope_id; attr_list* attrs; IntrusivePtr return_type; - std::map> local; + std::map, std::less<>> local; id_list* inits; }; From 3bcf55ce412a37a817e5a5169ebed09df357cd5b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 12 May 2020 23:24:46 -0700 Subject: [PATCH 051/151] Change zeek::id::lookup functions to use std::string_view --- src/ID.cc | 25 +++++++++++++++---------- src/ID.h | 15 ++++++++------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/ID.cc b/src/ID.cc index bf8972f324..da0bc8e6ae 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -31,45 +31,49 @@ IntrusivePtr zeek::id::count_set; IntrusivePtr zeek::id::string_vec; IntrusivePtr zeek::id::index_vec; -const IntrusivePtr& zeek::id::lookup(const char* name) +const IntrusivePtr& zeek::id::lookup(std::string_view name) { return global_scope()->Find(name); } -const IntrusivePtr& zeek::id::lookup_type(const char* name) +const IntrusivePtr& zeek::id::lookup_type(std::string_view name) { auto id = global_scope()->Find(name); if ( ! id ) - reporter->InternalError("Failed to find type named: %s", name); + reporter->InternalError("Failed to find type named: %s", + std::string(name).data()); return id->GetType(); } -const IntrusivePtr& zeek::id::lookup_val(const char* name) +const IntrusivePtr& zeek::id::lookup_val(std::string_view name) { auto id = global_scope()->Find(name); if ( ! id ) - reporter->InternalError("Failed to find variable named: %s", name); + reporter->InternalError("Failed to find variable named: %s", + std::string(name).data()); return id->GetVal(); } -const IntrusivePtr& zeek::id::lookup_const(const char* name) +const IntrusivePtr& zeek::id::lookup_const(std::string_view name) { auto id = global_scope()->Find(name); if ( ! id ) - reporter->InternalError("Failed to find variable named: %s", name); + reporter->InternalError("Failed to find variable named: %s", + std::string(name).data()); if ( ! id->IsConst() ) - reporter->InternalError("Variable is not 'const', but expected to be: %s", name); + reporter->InternalError("Variable is not 'const', but expected to be: %s", + std::string(name).data()); return id->GetVal(); } -IntrusivePtr zeek::id::lookup_func(const char* name) +IntrusivePtr zeek::id::lookup_func(std::string_view name) { const auto& v = zeek::id::lookup_val(name); @@ -77,7 +81,8 @@ IntrusivePtr zeek::id::lookup_func(const char* name) return nullptr; if ( ! IsFunc(v->GetType()->Tag()) ) - reporter->InternalError("Expected variable '%s' to be a function", name); + reporter->InternalError("Expected variable '%s' to be a function", + std::string(name).data()); return {NewRef{}, v->AsFunc()}; } diff --git a/src/ID.h b/src/ID.h index d80be7f7c9..7582dd5c81 100644 --- a/src/ID.h +++ b/src/ID.h @@ -10,6 +10,7 @@ #include #include +#include #include class Val; @@ -165,7 +166,7 @@ namespace zeek { namespace id { * @return The identifier, which may reference a nil object if no such * name exists. */ -const IntrusivePtr& lookup(const char* name); +const IntrusivePtr& lookup(std::string_view name); /** * Lookup an ID by its name and return its type. A fatal occurs if the ID @@ -173,7 +174,7 @@ const IntrusivePtr& lookup(const char* name); * @param name The identifier name to lookup * @return The type of the identifier. */ -const IntrusivePtr& lookup_type(const char* name); +const IntrusivePtr& lookup_type(std::string_view name); /** * Lookup an ID by its name and return its type (as cast to @c T). @@ -182,7 +183,7 @@ const IntrusivePtr& lookup_type(const char* name); * @return The type of the identifier. */ template -IntrusivePtr lookup_type(const char* name) +IntrusivePtr lookup_type(std::string_view name) { return cast_intrusive(lookup_type(name)); } /** @@ -191,7 +192,7 @@ IntrusivePtr lookup_type(const char* name) * @param name The identifier name to lookup * @return The current value of the identifier */ -const IntrusivePtr& lookup_val(const char* name); +const IntrusivePtr& lookup_val(std::string_view name); /** * Lookup an ID by its name and return its value (as cast to @c T). @@ -200,7 +201,7 @@ const IntrusivePtr& lookup_val(const char* name); * @return The current value of the identifier. */ template -IntrusivePtr lookup_val(const char* name) +IntrusivePtr lookup_val(std::string_view name) { return cast_intrusive(lookup_val(name)); } /** @@ -209,7 +210,7 @@ IntrusivePtr lookup_val(const char* name) * @param name The identifier name to lookup * @return The current value of the identifier */ -const IntrusivePtr& lookup_const(const char* name); +const IntrusivePtr& lookup_const(std::string_view name); /** * Lookup an ID by its name and return the function it references. @@ -217,7 +218,7 @@ const IntrusivePtr& lookup_const(const char* name); * @param name The identifier name to lookup * @return The current function value the identifier references. */ -IntrusivePtr lookup_func(const char* name); +IntrusivePtr lookup_func(std::string_view name); extern IntrusivePtr conn_id; extern IntrusivePtr endpoint; From c509149c86002af3040bff7ff7b470156afda420 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 13 May 2020 11:43:36 -0700 Subject: [PATCH 052/151] Remove signal_val declaration from Var.h --- src/Net.cc | 4 +++- src/Var.h | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Net.cc b/src/Net.cc index 9be8191000..9f8f28ba28 100644 --- a/src/Net.cc +++ b/src/Net.cc @@ -28,7 +28,7 @@ extern "C" { #include "Sessions.h" #include "Event.h" #include "Timer.h" -#include "Var.h" +#include "ID.h" #include "Reporter.h" #include "Scope.h" #include "Anon.h" @@ -331,6 +331,8 @@ void net_run() current_dispatched = 0; current_iosrc = nullptr; + extern int signal_val; + if ( signal_val == SIGTERM || signal_val == SIGINT ) // We received a signal while processing the // current packet and its related events. diff --git a/src/Var.h b/src/Var.h index 86c4928866..840c143c79 100644 --- a/src/Var.h +++ b/src/Var.h @@ -67,5 +67,3 @@ extern BroType* internal_type(const char* name); extern Func* internal_func(const char* name); extern EventHandlerPtr internal_handler(const char* name); - -extern int signal_val; // 0 if no signal pending From f1e8289caa056be66854327df219e21126806024 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 13 May 2020 12:52:09 -0700 Subject: [PATCH 053/151] Deprecate remaining "opt_internal" functions in Var.h --- src/Discard.cc | 2 +- src/NetVar.cc | 155 +++++++++++++++++++++++-------------------------- src/NetVar.h | 2 - src/Obj.cc | 2 +- src/Var.h | 7 +++ 5 files changed, 83 insertions(+), 85 deletions(-) diff --git a/src/Discard.cc b/src/Discard.cc index b41a8a9946..20a40b0590 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -21,7 +21,7 @@ Discarder::Discarder() check_udp = zeek::id::lookup_func("discarder_check_udp"); check_icmp = zeek::id::lookup_func("discarder_check_icmp"); - discarder_maxlen = static_cast(opt_internal_int("discarder_maxlen")); + discarder_maxlen = static_cast(zeek::id::lookup_val("discarder_maxlen")->AsCount()); } Discarder::~Discarder() diff --git a/src/NetVar.cc b/src/NetVar.cc index 9d984ce871..3d39a08da6 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -149,8 +149,6 @@ Val* pkt_profile_file; int load_sample_freq; -double gap_report_freq; - int packet_filter_default; int sig_max_group_size; @@ -168,8 +166,6 @@ TableVal* likely_server_ports; int check_for_unused_event_handlers; -int suppress_local_output; - double timer_mgr_inactivity_timeout; StringVal* trace_output_file; @@ -202,22 +198,14 @@ void init_event_handlers() void init_general_global_var() { - table_expire_interval = opt_internal_double("table_expire_interval"); - table_expire_delay = opt_internal_double("table_expire_delay"); - table_incremental_step = opt_internal_int("table_incremental_step"); - - packet_filter_default = opt_internal_int("packet_filter_default"); - - sig_max_group_size = opt_internal_int("sig_max_group_size"); - - check_for_unused_event_handlers = - opt_internal_int("check_for_unused_event_handlers"); - - suppress_local_output = opt_internal_int("suppress_local_output"); - - record_all_packets = opt_internal_int("record_all_packets"); - - bits_per_uid = opt_internal_unsigned("bits_per_uid"); + table_expire_interval = zeek::id::lookup_val("table_expire_interval")->AsInterval(); + table_expire_delay = zeek::id::lookup_val("table_expire_delay")->AsInterval(); + table_incremental_step = zeek::id::lookup_val("table_incremental_step")->AsCount(); + packet_filter_default = zeek::id::lookup_val("packet_filter_default")->AsBool(); + sig_max_group_size = zeek::id::lookup_val("sig_max_group_size")->AsCount(); + check_for_unused_event_handlers = zeek::id::lookup_val("check_for_unused_event_handlers")->AsBool(); + record_all_packets = zeek::id::lookup_val("record_all_packets")->AsBool(); + bits_per_uid = zeek::id::lookup_val("bits_per_uid")->AsCount(); } extern void zeek_legacy_netvar_init(); @@ -232,38 +220,35 @@ void init_net_var() zeek::id::detail::init(); zeek_legacy_netvar_init(); - ignore_checksums = opt_internal_int("ignore_checksums"); - partial_connection_ok = opt_internal_int("partial_connection_ok"); - tcp_SYN_ack_ok = opt_internal_int("tcp_SYN_ack_ok"); - tcp_match_undelivered = opt_internal_int("tcp_match_undelivered"); + ignore_checksums = zeek::id::lookup_val("ignore_checksums")->AsBool(); + partial_connection_ok = zeek::id::lookup_val("partial_connection_ok")->AsBool(); + tcp_SYN_ack_ok = zeek::id::lookup_val("tcp_SYN_ack_ok")->AsBool(); + tcp_match_undelivered = zeek::id::lookup_val("tcp_match_undelivered")->AsBool(); - encap_hdr_size = opt_internal_int("encap_hdr_size"); + encap_hdr_size = zeek::id::lookup_val("encap_hdr_size")->AsCount(); - frag_timeout = opt_internal_double("frag_timeout"); + frag_timeout = zeek::id::lookup_val("frag_timeout")->AsInterval(); - tcp_SYN_timeout = opt_internal_double("tcp_SYN_timeout"); - tcp_session_timer = opt_internal_double("tcp_session_timer"); - tcp_connection_linger = opt_internal_double("tcp_connection_linger"); - tcp_attempt_delay = opt_internal_double("tcp_attempt_delay"); - tcp_close_delay = opt_internal_double("tcp_close_delay"); - tcp_reset_delay = opt_internal_double("tcp_reset_delay"); - tcp_partial_close_delay = opt_internal_double("tcp_partial_close_delay"); + tcp_SYN_timeout = zeek::id::lookup_val("tcp_SYN_timeout")->AsInterval(); + tcp_session_timer = zeek::id::lookup_val("tcp_session_timer")->AsInterval(); + tcp_connection_linger = zeek::id::lookup_val("tcp_connection_linger")->AsInterval(); + tcp_attempt_delay = zeek::id::lookup_val("tcp_attempt_delay")->AsInterval(); + tcp_close_delay = zeek::id::lookup_val("tcp_close_delay")->AsInterval(); + tcp_reset_delay = zeek::id::lookup_val("tcp_reset_delay")->AsInterval(); + tcp_partial_close_delay = zeek::id::lookup_val("tcp_partial_close_delay")->AsInterval(); - tcp_max_initial_window = opt_internal_int("tcp_max_initial_window"); - tcp_max_above_hole_without_any_acks = - opt_internal_int("tcp_max_above_hole_without_any_acks"); - tcp_excessive_data_without_further_acks = - opt_internal_int("tcp_excessive_data_without_further_acks"); - tcp_max_old_segments = opt_internal_int("tcp_max_old_segments"); + tcp_max_initial_window = zeek::id::lookup_val("tcp_max_initial_window")->AsCount(); + tcp_max_above_hole_without_any_acks = zeek::id::lookup_val("tcp_max_above_hole_without_any_acks")->AsCount(); + tcp_excessive_data_without_further_acks = zeek::id::lookup_val("tcp_excessive_data_without_further_acks")->AsCount(); + tcp_max_old_segments = zeek::id::lookup_val("tcp_max_old_segments")->AsCount(); - non_analyzed_lifetime = opt_internal_double("non_analyzed_lifetime"); - tcp_inactivity_timeout = opt_internal_double("tcp_inactivity_timeout"); - udp_inactivity_timeout = opt_internal_double("udp_inactivity_timeout"); - icmp_inactivity_timeout = opt_internal_double("icmp_inactivity_timeout"); + non_analyzed_lifetime = zeek::id::lookup_val("non_analyzed_lifetime")->AsInterval(); + tcp_inactivity_timeout = zeek::id::lookup_val("tcp_inactivity_timeout")->AsInterval(); + udp_inactivity_timeout = zeek::id::lookup_val("udp_inactivity_timeout")->AsInterval(); + icmp_inactivity_timeout = zeek::id::lookup_val("icmp_inactivity_timeout")->AsInterval(); - tcp_storm_thresh = opt_internal_int("tcp_storm_thresh"); - tcp_storm_interarrival_thresh = - opt_internal_double("tcp_storm_interarrival_thresh"); + tcp_storm_thresh = zeek::id::lookup_val("tcp_storm_thresh")->AsCount(); + tcp_storm_interarrival_thresh = zeek::id::lookup_val("tcp_storm_interarrival_thresh")->AsInterval(); tcp_content_deliver_all_orig = bool(zeek::id::lookup_val("tcp_content_deliver_all_orig")->AsBool()); @@ -277,52 +262,60 @@ void init_net_var() udp_content_delivery_ports_use_resp = bool(zeek::id::lookup_val("udp_content_delivery_ports_use_resp")->AsBool()); - dns_session_timeout = opt_internal_double("dns_session_timeout"); - rpc_timeout = opt_internal_double("rpc_timeout"); + dns_session_timeout = zeek::id::lookup_val("dns_session_timeout")->AsInterval(); + rpc_timeout = zeek::id::lookup_val("rpc_timeout")->AsInterval(); - watchdog_interval = int(opt_internal_double("watchdog_interval")); + watchdog_interval = int(zeek::id::lookup_val("watchdog_interval")->AsInterval()); - max_timer_expires = opt_internal_int("max_timer_expires"); + max_timer_expires = zeek::id::lookup_val("max_timer_expires")->AsCount(); - mime_segment_length = opt_internal_int("mime_segment_length"); - mime_segment_overlap_length = opt_internal_int("mime_segment_overlap_length"); + mime_segment_length = zeek::id::lookup_val("mime_segment_length")->AsCount(); + mime_segment_overlap_length = zeek::id::lookup_val("mime_segment_overlap_length")->AsCount(); - http_entity_data_delivery_size = opt_internal_int("http_entity_data_delivery_size"); - truncate_http_URI = opt_internal_int("truncate_http_URI"); + http_entity_data_delivery_size = zeek::id::lookup_val("http_entity_data_delivery_size")->AsCount(); + truncate_http_URI = zeek::id::lookup_val("truncate_http_URI")->AsInt(); - dns_skip_all_auth = opt_internal_int("dns_skip_all_auth"); - dns_skip_all_addl = opt_internal_int("dns_skip_all_addl"); - dns_max_queries = opt_internal_int("dns_max_queries"); + dns_skip_all_auth = zeek::id::lookup_val("dns_skip_all_auth")->AsBool(); + dns_skip_all_addl = zeek::id::lookup_val("dns_skip_all_addl")->AsBool(); + dns_max_queries = zeek::id::lookup_val("dns_max_queries")->AsCount(); - stp_delta = opt_internal_double("stp_delta"); - stp_idle_min = opt_internal_double("stp_idle_min"); + stp_delta = 0.0; + if ( const auto& v = zeek::id::lookup_val("stp_delta") ) stp_delta = v->AsInterval(); + stp_idle_min = 0.0; + if ( const auto& v = zeek::id::lookup_val("stp_idle_min") ) stp_delta = v->AsInterval(); - orig_addr_anonymization = opt_internal_int("orig_addr_anonymization"); - resp_addr_anonymization = opt_internal_int("resp_addr_anonymization"); - other_addr_anonymization = opt_internal_int("other_addr_anonymization"); + orig_addr_anonymization = 0; + if ( const auto& id = zeek::id::lookup("orig_addr_anonymization") ) + if ( const auto& v = id->GetVal() ) + orig_addr_anonymization = v->AsInt(); + resp_addr_anonymization = 0; + if ( const auto& id = zeek::id::lookup("resp_addr_anonymization") ) + if ( const auto& v = id->GetVal() ) + resp_addr_anonymization = v->AsInt(); + other_addr_anonymization = 0; + if ( const auto& id = zeek::id::lookup("other_addr_anonymization") ) + if ( const auto& v = id->GetVal() ) + other_addr_anonymization = v->AsInt(); - connection_status_update_interval = - opt_internal_double("connection_status_update_interval"); + connection_status_update_interval = 0.0; + if ( const auto& id = zeek::id::lookup("connection_status_update_interval") ) + if ( const auto& v = id->GetVal() ) + connection_status_update_interval = v->AsInterval(); - expensive_profiling_multiple = - opt_internal_int("expensive_profiling_multiple"); - profiling_interval = opt_internal_double("profiling_interval"); - segment_profiling = opt_internal_int("segment_profiling"); + expensive_profiling_multiple = zeek::id::lookup_val("expensive_profiling_multiple")->AsCount(); + profiling_interval = zeek::id::lookup_val("profiling_interval")->AsInterval(); + segment_profiling = zeek::id::lookup_val("segment_profiling")->AsBool(); - pkt_profile_mode = opt_internal_int("pkt_profile_mode"); - pkt_profile_freq = opt_internal_double("pkt_profile_freq"); + pkt_profile_mode = zeek::id::lookup_val("pkt_profile_mode")->InternalInt(); + pkt_profile_freq = zeek::id::lookup_val("pkt_profile_freq")->AsDouble(); - load_sample_freq = opt_internal_int("load_sample_freq"); + load_sample_freq = zeek::id::lookup_val("load_sample_freq")->AsCount(); - gap_report_freq = opt_internal_double("gap_report_freq"); + dpd_reassemble_first_packets = zeek::id::lookup_val("dpd_reassemble_first_packets")->AsBool(); + dpd_buffer_size = zeek::id::lookup_val("dpd_buffer_size")->AsCount(); + dpd_match_only_beginning = zeek::id::lookup_val("dpd_match_only_beginning")->AsBool(); + dpd_late_match_stop = zeek::id::lookup_val("dpd_late_match_stop")->AsBool(); + dpd_ignore_ports = zeek::id::lookup_val("dpd_ignore_ports")->AsBool(); - dpd_reassemble_first_packets = - opt_internal_int("dpd_reassemble_first_packets"); - dpd_buffer_size = opt_internal_int("dpd_buffer_size"); - dpd_match_only_beginning = opt_internal_int("dpd_match_only_beginning"); - dpd_late_match_stop = opt_internal_int("dpd_late_match_stop"); - dpd_ignore_ports = opt_internal_int("dpd_ignore_ports"); - - timer_mgr_inactivity_timeout = - opt_internal_double("timer_mgr_inactivity_timeout"); + timer_mgr_inactivity_timeout = zeek::id::lookup_val("timer_mgr_inactivity_timeout")->AsInterval(); } diff --git a/src/NetVar.h b/src/NetVar.h index 2d37cb960c..a9d286d0f0 100644 --- a/src/NetVar.h +++ b/src/NetVar.h @@ -228,8 +228,6 @@ extern TableVal* likely_server_ports; extern int check_for_unused_event_handlers; -extern int suppress_local_output; - extern double timer_mgr_inactivity_timeout; [[deprecated("Remove in v4.1. Perform your own lookup.")]] diff --git a/src/Obj.cc b/src/Obj.cc index 89edc8edff..63f22f4506 100644 --- a/src/Obj.cc +++ b/src/Obj.cc @@ -90,7 +90,7 @@ void BroObj::BadTag(const char* msg, const char* t1, const char* t2) const ODesc d; DoMsg(&d, out); - reporter->FatalError("%s", d.Description()); + reporter->FatalErrorWithCore("%s", d.Description()); reporter->PopLocation(); } diff --git a/src/Var.h b/src/Var.h index 840c143c79..e7782836ba 100644 --- a/src/Var.h +++ b/src/Var.h @@ -49,11 +49,18 @@ extern Val* internal_const_val(const char* name); // internal error if not const [[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] extern Val* opt_internal_val(const char* name); // returns nil if not defined +[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] extern double opt_internal_double(const char* name); + +[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] extern bro_int_t opt_internal_int(const char* name); + +[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] extern bro_uint_t opt_internal_unsigned(const char* name); + [[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] extern StringVal* opt_internal_string(const char* name); + [[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] extern TableVal* opt_internal_table(const char* name); // nil if not defined From 78e3267c44d1c6d959cdd4c5b9f2716bf99d2e12 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 13 May 2020 18:26:54 -0700 Subject: [PATCH 054/151] Deprecate internal_handler(), replace with EventRegistry::Register() Added a couple explicit event declarations that were missing: "net_done" and "dns_mapping_name_changed". --- aux/bifcl | 2 +- doc | 2 +- scripts/base/init-bare.zeek | 6 +++--- src/DNS_Mgr.cc | 14 ++------------ src/DNS_Mgr.h | 8 -------- src/EventRegistry.cc | 20 ++++++++++++++++++++ src/EventRegistry.h | 8 ++++++++ src/Var.cc | 16 +--------------- src/Var.h | 1 + src/bro-bif.h | 2 +- src/event.bif | 32 ++++++++++++++++++++++++++++++++ src/input/Manager.cc | 2 +- src/zeek-setup.cc | 7 +------ 13 files changed, 72 insertions(+), 48 deletions(-) diff --git a/aux/bifcl b/aux/bifcl index 071a1517a7..970c09875a 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 071a1517a73bde131da42fe35cac05a3503340be +Subproject commit 970c09875a4bcfb61981d7b629e732f9a0f322ef diff --git a/doc b/doc index ddc898c4a7..39462e3651 160000 --- a/doc +++ b/doc @@ -1 +1 @@ -Subproject commit ddc898c4a7ccea56f7ed74504a00e905639d7ddf +Subproject commit 39462e3651facf49a71f6abaa80b3b0e5f313bf6 diff --git a/scripts/base/init-bare.zeek b/scripts/base/init-bare.zeek index 2a90d7a339..a02a676df9 100644 --- a/scripts/base/init-bare.zeek +++ b/scripts/base/init-bare.zeek @@ -1870,9 +1870,6 @@ type gtp_delete_pdp_ctx_response_elements: record { @load base/frameworks/supervisor/api @load base/bif/supervisor.bif -global done_with_network = F; -event net_done(t: time) { done_with_network = T; } - ## Internal function. function add_interface(iold: string, inew: string): string { @@ -5272,3 +5269,6 @@ const bits_per_uid: count = 96 &redef; ## to generate installation-unique file IDs (the *id* field of :zeek:see:`fa_file`). const digest_salt = "Please change this value." &redef; +global done_with_network = F; +event net_done(t: time) + { done_with_network = T; } diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index c834ba7c80..a69ebbe4ce 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -36,7 +36,8 @@ #include "Event.h" #include "Net.h" #include "Val.h" -#include "Var.h" +#include "NetVar.h" +#include "ID.h" #include "Reporter.h" #include "IntrusivePtr.h" #include "iosource/Manager.h" @@ -380,10 +381,6 @@ DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode) mode = arg_mode; - dns_mapping_valid = dns_mapping_unverified = dns_mapping_new_name = - dns_mapping_lost_name = dns_mapping_name_changed = - dns_mapping_altered = nullptr; - dm_rec = nullptr; cache_name = dir = nullptr; @@ -455,13 +452,6 @@ void DNS_Mgr::InitSource() void DNS_Mgr::InitPostScript() { - dns_mapping_valid = internal_handler("dns_mapping_valid"); - dns_mapping_unverified = internal_handler("dns_mapping_unverified"); - dns_mapping_new_name = internal_handler("dns_mapping_new_name"); - dns_mapping_lost_name = internal_handler("dns_mapping_lost_name"); - dns_mapping_name_changed = internal_handler("dns_mapping_name_changed"); - dns_mapping_altered = internal_handler("dns_mapping_altered"); - dm_rec = zeek::id::lookup_type("dns_mapping")->AsRecordType(); // Registering will call Init() diff --git a/src/DNS_Mgr.h b/src/DNS_Mgr.h index c0a3370487..3b386fb07d 100644 --- a/src/DNS_Mgr.h +++ b/src/DNS_Mgr.h @@ -149,14 +149,6 @@ protected: bool did_init; - // DNS-related events. - EventHandlerPtr dns_mapping_valid; - EventHandlerPtr dns_mapping_unverified; - EventHandlerPtr dns_mapping_new_name; - EventHandlerPtr dns_mapping_lost_name; - EventHandlerPtr dns_mapping_name_changed; - EventHandlerPtr dns_mapping_altered; - RecordType* dm_rec; typedef std::list CallbackList; diff --git a/src/EventRegistry.cc b/src/EventRegistry.cc index 7dbae7a83b..5bd2654924 100644 --- a/src/EventRegistry.cc +++ b/src/EventRegistry.cc @@ -6,6 +6,26 @@ EventRegistry::EventRegistry() = default; EventRegistry::~EventRegistry() noexcept = default; +EventHandlerPtr EventRegistry::Register(const char* name) + { + // If there already is an entry in the registry, we have a + // local handler on the script layer. + EventHandler* h = event_registry->Lookup(name); + + if ( h ) + { + h->SetUsed(); + return h; + } + + h = new EventHandler(name); + event_registry->Register(h); + + h->SetUsed(); + + return h; + } + void EventRegistry::Register(EventHandlerPtr handler) { handlers[std::string(handler->Name())] = std::unique_ptr(handler.Ptr()); diff --git a/src/EventRegistry.h b/src/EventRegistry.h index 31b859986b..7b8055ec51 100644 --- a/src/EventRegistry.h +++ b/src/EventRegistry.h @@ -17,6 +17,14 @@ public: EventRegistry(); ~EventRegistry() noexcept; + /** + * Performs a lookup for an existing event handler and returns it + * if one exists, or else creates one, registers it, and returns it. + * @param name The name of the event handler to lookup/register. + * @return The event handler. + */ + EventHandlerPtr Register(const char* name); + void Register(EventHandlerPtr handler); // Return nil if unknown. diff --git a/src/Var.cc b/src/Var.cc index 5c5c5e31e5..a58a1dbe4c 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -776,19 +776,5 @@ Func* internal_func(const char* name) EventHandlerPtr internal_handler(const char* name) { - // If there already is an entry in the registry, we have a - // local handler on the script layer. - EventHandler* h = event_registry->Lookup(name); - if ( h ) - { - h->SetUsed(); - return h; - } - - h = new EventHandler(name); - event_registry->Register(h); - - h->SetUsed(); - - return h; + return event_registry->Register(name); } diff --git a/src/Var.h b/src/Var.h index e7782836ba..49a60e32e3 100644 --- a/src/Var.h +++ b/src/Var.h @@ -73,4 +73,5 @@ extern BroType* internal_type(const char* name); [[deprecated("Remove in v4.1. Use zeek::id::lookup_func().")]] extern Func* internal_func(const char* name); +[[deprecated("Remove in v4.1. Use event_registry->Register().")]] extern EventHandlerPtr internal_handler(const char* name); diff --git a/src/bro-bif.h b/src/bro-bif.h index 92702907f3..30a694b7ef 100644 --- a/src/bro-bif.h +++ b/src/bro-bif.h @@ -8,4 +8,4 @@ #include "Event.h" #include "Reporter.h" #include "ID.h" -#include "Var.h" // for internal_handler() +#include "EventRegistry.h" diff --git a/src/event.bif b/src/event.bif index e894d2f5e3..78bdefc0f9 100644 --- a/src/event.bif +++ b/src/event.bif @@ -61,6 +61,24 @@ event zeek_init%(%); ## is not generated. event zeek_done%(%); +## Generated as one of the first steps of Zeek's main-loop termination, just +## before it starts to flush any remaining events/timers/state. The event +## engine generates this event when Zeek is about to terminate, either due to +## having exhausted reading its input trace file(s), receiving a termination +## signal, or because Zeek was run without a network input source and has +## finished executing any global statements. This event comes before +## :zeek:see:`zeek_init`. +## +## t: The time at with the Zeek-termination process started. +## +## .. zeek:see:: zeek_init zeek_done +## +## .. note:: +## +## If Zeek terminates due to an invocation of :zeek:id:`exit`, then this event +## is not generated. +event net_done%(t: time%); + ## Generated when network time is initialized. The event engine generates this ## event after the network time has been determined but before processing of ## packets is started. @@ -820,6 +838,20 @@ event dns_mapping_new_name%(dm: dns_mapping%); ## dns_mapping_valid event dns_mapping_lost_name%(dm: dns_mapping%); +## Generated when an internal DNS lookup returns a different host name than +## in the past. Zeek keeps an internal DNS cache for host names +## and IP addresses it has already resolved. This event is generated when +## on a subsequent lookup we receive an answer that has a different host +## string than we already have in the cache. +## +## prev: A record describing the old resolver result. +# +## latest: A record describing the new resolver result. +## +## .. zeek:see:: dns_mapping_altered dns_mapping_new_name dns_mapping_unverified +## dns_mapping_valid +event dns_mapping_name_changed%(prev: dns_mapping, latest: dns_mapping%); + ## Generated when an internal DNS lookup produced a different result than in ## the past. Zeek keeps an internal DNS cache for host names and IP addresses ## it has already resolved. This event is generated when a subsequent lookup diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 7034225a48..d31838ba2b 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -192,7 +192,7 @@ Manager::AnalysisStream::~AnalysisStream() Manager::Manager() : plugin::ComponentManager("Input", "Reader") { - end_of_data = internal_handler("Input::end_of_data"); + end_of_data = event_registry->Register("Input::end_of_data"); } Manager::~Manager() diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 30d0486a6f..d995971d32 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -101,7 +101,6 @@ trigger::Manager* trigger_mgr = nullptr; std::vector zeek_script_prefixes; Stmt* stmts; -EventHandlerPtr net_done = nullptr; RuleMatcher* rule_matcher = nullptr; EventRegistry* event_registry = nullptr; ProfileLogger* profiling_logger = nullptr; @@ -269,7 +268,6 @@ void terminate_bro() brofiler.WriteStats(); - EventHandlerPtr zeek_done = internal_handler("zeek_done"); if ( zeek_done ) mgr.Enqueue(zeek_done, zeek::Args{}); @@ -740,8 +738,6 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, if ( dns_type != DNS_PRIME ) net_init(options.interface, options.pcap_file, options.pcap_output_file, options.use_watchdog); - net_done = internal_handler("net_done"); - if ( ! g_policy_debug ) { (void) setsignal(SIGTERM, sig_handler); @@ -797,8 +793,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, // we don't have any other source for it. net_update_time(current_time()); - EventHandlerPtr zeek_init = internal_handler("zeek_init"); - if ( zeek_init ) //### this should be a function + if ( zeek_init ) mgr.Enqueue(zeek_init, zeek::Args{}); EventRegistry::string_list dead_handlers = From dca587c6043ba96c7fe86a7b303c1ae7025af019 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 13 May 2020 18:42:08 -0700 Subject: [PATCH 055/151] Change EventRegistry/EventHandler methods to use std::string{_view} --- src/EventHandler.cc | 7 +++---- src/EventHandler.h | 6 +++--- src/EventRegistry.cc | 10 +++++----- src/EventRegistry.h | 9 +++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index b4ccbd11fc..f9c3e72d47 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -10,9 +10,9 @@ #include "broker/Manager.h" #include "broker/Data.h" -EventHandler::EventHandler(const char* arg_name) +EventHandler::EventHandler(std::string arg_name) { - name = copy_string(arg_name); + name = std::move(arg_name); used = false; local = nullptr; type = nullptr; @@ -24,7 +24,6 @@ EventHandler::EventHandler(const char* arg_name) EventHandler::~EventHandler() { Unref(local); - delete [] name; } EventHandler::operator bool() const @@ -39,7 +38,7 @@ FuncType* EventHandler::FType(bool check_export) if ( type ) return type; - const auto& id = lookup_ID(name, current_module.c_str(), false, false, + const auto& id = lookup_ID(name.data(), current_module.c_str(), false, false, check_export); if ( ! id ) diff --git a/src/EventHandler.h b/src/EventHandler.h index 59773560f6..6844662b22 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -13,10 +13,10 @@ class FuncType; class EventHandler { public: - explicit EventHandler(const char* name); + explicit EventHandler(std::string name); ~EventHandler(); - const char* Name() { return name; } + const char* Name() { return name.data(); } Func* LocalHandler() { return local; } FuncType* FType(bool check_export = true); @@ -55,7 +55,7 @@ public: private: void NewEvent(const zeek::Args& vl); // Raise new_event() meta event. - const char* name; + std::string name; Func* local; FuncType* type; bool used; // this handler is indeed used somewhere diff --git a/src/EventRegistry.cc b/src/EventRegistry.cc index 5bd2654924..ea6f3a0ca2 100644 --- a/src/EventRegistry.cc +++ b/src/EventRegistry.cc @@ -6,7 +6,7 @@ EventRegistry::EventRegistry() = default; EventRegistry::~EventRegistry() noexcept = default; -EventHandlerPtr EventRegistry::Register(const char* name) +EventHandlerPtr EventRegistry::Register(std::string_view name) { // If there already is an entry in the registry, we have a // local handler on the script layer. @@ -18,7 +18,7 @@ EventHandlerPtr EventRegistry::Register(const char* name) return h; } - h = new EventHandler(name); + h = new EventHandler(std::string(name)); event_registry->Register(h); h->SetUsed(); @@ -31,7 +31,7 @@ void EventRegistry::Register(EventHandlerPtr handler) handlers[std::string(handler->Name())] = std::unique_ptr(handler.Ptr()); } -EventHandler* EventRegistry::Lookup(const std::string& name) +EventHandler* EventRegistry::Lookup(std::string_view name) { auto it = handlers.find(name); if ( it != handlers.end() ) @@ -106,7 +106,7 @@ void EventRegistry::PrintDebug() } } -void EventRegistry::SetErrorHandler(const std::string& name) +void EventRegistry::SetErrorHandler(std::string_view name) { EventHandler* eh = Lookup(name); @@ -117,6 +117,6 @@ void EventRegistry::SetErrorHandler(const std::string& name) } reporter->InternalWarning("unknown event handler '%s' in SetErrorHandler()", - name.c_str()); + std::string(name).c_str()); } diff --git a/src/EventRegistry.h b/src/EventRegistry.h index 7b8055ec51..13f3fcc5c4 100644 --- a/src/EventRegistry.h +++ b/src/EventRegistry.h @@ -5,6 +5,7 @@ #include #include #include +#include #include class EventHandler; @@ -23,12 +24,12 @@ public: * @param name The name of the event handler to lookup/register. * @return The event handler. */ - EventHandlerPtr Register(const char* name); + EventHandlerPtr Register(std::string_view name); void Register(EventHandlerPtr handler); // Return nil if unknown. - EventHandler* Lookup(const std::string& name); + EventHandler* Lookup(std::string_view name); // Returns a list of all local handlers that match the given pattern. // Passes ownership of list. @@ -38,7 +39,7 @@ public: // Marks a handler as handling errors. Error handler will not be called // recursively to avoid infinite loops in case they trigger an error // themselves. - void SetErrorHandler(const std::string& name); + void SetErrorHandler(std::string_view name); string_list UnusedHandlers(); string_list UsedHandlers(); @@ -47,7 +48,7 @@ public: void PrintDebug(); private: - std::map> handlers; + std::map, std::less<>> handlers; }; extern EventRegistry* event_registry; From eedeb07550bf19d7396f1df6eb39565797bc778d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 13 May 2020 20:21:51 -0700 Subject: [PATCH 056/151] Deprecate all BroType* in BifType:: namespace Replaced with equivalently named IntrusivePtr in zeek::BifType:: --- NEWS | 4 ++ aux/bifcl | 2 +- src/TunnelEncapsulation.cc | 4 +- src/Val.cc | 8 +-- .../protocol/dce-rpc/dce_rpc-analyzer.pac | 2 +- src/analyzer/protocol/dhcp/dhcp-analyzer.pac | 4 +- src/analyzer/protocol/dhcp/dhcp-options.pac | 20 +++--- src/analyzer/protocol/ftp/functions.bif | 4 +- .../protocol/gtpv1/gtpv1-analyzer.pac | 24 +++---- src/analyzer/protocol/krb/krb-analyzer.pac | 12 ++-- src/analyzer/protocol/krb/krb-padata.pac | 8 +-- src/analyzer/protocol/krb/krb-types.pac | 6 +- .../protocol/modbus/modbus-analyzer.pac | 14 ++--- .../protocol/mqtt/commands/connack.pac | 2 +- .../protocol/mqtt/commands/connect.pac | 2 +- .../protocol/mqtt/commands/publish.pac | 2 +- src/analyzer/protocol/ntlm/ntlm-analyzer.pac | 12 ++-- src/analyzer/protocol/ntp/ntp-analyzer.pac | 8 +-- .../protocol/radius/radius-analyzer.pac | 6 +- src/analyzer/protocol/rdp/rdp-analyzer.pac | 12 ++-- src/analyzer/protocol/rpc/MOUNT.cc | 14 ++--- src/analyzer/protocol/rpc/NFS.cc | 62 +++++++++---------- src/analyzer/protocol/rpc/Portmap.cc | 2 +- src/analyzer/protocol/rpc/RPC.cc | 4 +- src/analyzer/protocol/smb/smb-time.pac | 2 +- .../protocol/smb/smb1-com-negotiate.pac | 16 ++--- .../smb/smb1-com-session-setup-andx.pac | 8 +-- .../smb/smb1-com-transaction-secondary.pac | 2 +- .../smb/smb1-com-transaction2-secondary.pac | 2 +- .../protocol/smb/smb1-com-transaction2.pac | 4 +- src/analyzer/protocol/smb/smb1-protocol.pac | 2 +- src/analyzer/protocol/smb/smb2-com-close.pac | 2 +- src/analyzer/protocol/smb/smb2-com-create.pac | 4 +- .../protocol/smb/smb2-com-negotiate.pac | 4 +- .../protocol/smb/smb2-com-session-setup.pac | 6 +- .../protocol/smb/smb2-com-set-info.pac | 6 +- .../smb/smb2-com-transform-header.pac | 2 +- .../protocol/smb/smb2-com-tree-connect.pac | 2 +- src/analyzer/protocol/smb/smb2-protocol.pac | 14 ++--- src/analyzer/protocol/snmp/snmp-analyzer.pac | 22 +++---- src/analyzer/protocol/ssh/ssh-analyzer.pac | 10 +-- .../protocol/ssl/tls-handshake-analyzer.pac | 10 +-- src/analyzer/protocol/tcp/TCP.cc | 4 +- src/broker/Data.cc | 34 +++++----- src/broker/Manager.cc | 4 +- src/broker/Store.h | 6 +- src/broker/comm.bif | 2 +- src/broker/data.bif | 34 +++++----- src/file_analysis/AnalyzerSet.cc | 2 +- .../analyzer/extract/functions.bif | 4 +- src/file_analysis/analyzer/pe/pe-analyzer.pac | 8 +-- .../analyzer/unified2/unified2-analyzer.pac | 6 +- src/file_analysis/analyzer/x509/X509.cc | 6 +- src/file_analysis/analyzer/x509/X509Common.cc | 2 +- src/file_analysis/analyzer/x509/functions.bif | 2 +- src/file_analysis/file_analysis.bif | 8 +-- src/input/Manager.cc | 60 +++++++++--------- src/iosource/Packet.cc | 6 +- src/logging/Manager.cc | 6 +- src/supervisor/Supervisor.cc | 12 ++-- src/supervisor/supervisor.bif | 4 +- src/zeek.bif | 4 +- 62 files changed, 287 insertions(+), 283 deletions(-) diff --git a/NEWS b/NEWS index 9ccc59bc80..fe2629d8a7 100644 --- a/NEWS +++ b/NEWS @@ -176,6 +176,10 @@ Deprecated Functionality - ``Scope::Lookup()`` is deprecated, use ``Scope::Find()``. +- All generated ``BroType*`` names in the ``BifType::`` namespaces are + deprecated, but there's an equivalent name in ``zeek::BifType::`` of + ``IntrusivePtr`` type to use instead. + Zeek 3.1.0 ========== diff --git a/aux/bifcl b/aux/bifcl index 970c09875a..5afd05f72b 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 970c09875a4bcfb61981d7b629e732f9a0f322ef +Subproject commit 5afd05f72b52bd40637546203749fb7bed8dbc4d diff --git a/src/TunnelEncapsulation.cc b/src/TunnelEncapsulation.cc index 61a4e7bbbb..1b36a3f898 100644 --- a/src/TunnelEncapsulation.cc +++ b/src/TunnelEncapsulation.cc @@ -18,7 +18,7 @@ EncapsulatingConn::EncapsulatingConn(Connection* c, BifEnum::Tunnel::Type t) IntrusivePtr EncapsulatingConn::ToVal() const { - auto rv = make_intrusive(BifType::Record::Tunnel::EncapsulatingConn); + auto rv = make_intrusive(zeek::BifType::Record::Tunnel::EncapsulatingConn); auto id_val = make_intrusive(zeek::id::conn_id); id_val->Assign(0, make_intrusive(src_addr)); @@ -26,7 +26,7 @@ IntrusivePtr EncapsulatingConn::ToVal() const id_val->Assign(2, make_intrusive(dst_addr)); id_val->Assign(3, val_mgr->Port(ntohs(dst_port), proto)); rv->Assign(0, std::move(id_val)); - rv->Assign(1, BifType::Enum::Tunnel::Type->GetVal(type)); + rv->Assign(1, zeek::BifType::Enum::Tunnel::Type->GetVal(type)); rv->Assign(2, make_intrusive(uid.Base62("C").c_str())); diff --git a/src/Val.cc b/src/Val.cc index 7b5962f403..e721f42dc0 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2033,16 +2033,16 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe switch ( tpe ) { case ELEMENT_NEW: - vl.emplace_back(BifType::Enum::TableChange->GetVal(BifEnum::TableChange::TABLE_ELEMENT_NEW)); + vl.emplace_back(zeek::BifType::Enum::TableChange->GetVal(BifEnum::TableChange::TABLE_ELEMENT_NEW)); break; case ELEMENT_CHANGED: - vl.emplace_back(BifType::Enum::TableChange->GetVal(BifEnum::TableChange::TABLE_ELEMENT_CHANGED)); + vl.emplace_back(zeek::BifType::Enum::TableChange->GetVal(BifEnum::TableChange::TABLE_ELEMENT_CHANGED)); break; case ELEMENT_REMOVED: - vl.emplace_back(BifType::Enum::TableChange->GetVal(BifEnum::TableChange::TABLE_ELEMENT_REMOVED)); + vl.emplace_back(zeek::BifType::Enum::TableChange->GetVal(BifEnum::TableChange::TABLE_ELEMENT_REMOVED)); break; case ELEMENT_EXPIRED: - vl.emplace_back(BifType::Enum::TableChange->GetVal(BifEnum::TableChange::TABLE_ELEMENT_EXPIRED)); + vl.emplace_back(zeek::BifType::Enum::TableChange->GetVal(BifEnum::TableChange::TABLE_ELEMENT_EXPIRED)); } for ( const auto& v : lv->Vals() ) diff --git a/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac b/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac index de06b8e29b..7dfff77119 100644 --- a/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac +++ b/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac @@ -42,7 +42,7 @@ refine connection DCE_RPC_Conn += { ${header.is_orig}, fid, ${header.PTYPE}, - BifType::Enum::DCE_RPC::PType->GetVal(${header.PTYPE})); + zeek::BifType::Enum::DCE_RPC::PType->GetVal(${header.PTYPE})); } return true; %} diff --git a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac index eb0e5ac7a7..e8994436f8 100644 --- a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac +++ b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac @@ -19,7 +19,7 @@ refine flow DHCP_Flow += { %{ if ( ! options ) { - options = make_intrusive(BifType::Record::DHCP::Options); + options = make_intrusive(zeek::BifType::Record::DHCP::Options); all_options = make_intrusive(zeek::id::index_vec); options->Assign(0, all_options); } @@ -53,7 +53,7 @@ refine flow DHCP_Flow += { std::string mac_str = fmt_mac(${msg.chaddr}.data(), ${msg.chaddr}.length()); double secs = static_cast(${msg.secs}); - auto dhcp_msg_val = make_intrusive(BifType::Record::DHCP::Msg); + auto dhcp_msg_val = make_intrusive(zeek::BifType::Record::DHCP::Msg); dhcp_msg_val->Assign(0, val_mgr->Count(${msg.op})); dhcp_msg_val->Assign(1, val_mgr->Count(${msg.type})); dhcp_msg_val->Assign(2, val_mgr->Count(${msg.xid})); diff --git a/src/analyzer/protocol/dhcp/dhcp-options.pac b/src/analyzer/protocol/dhcp/dhcp-options.pac index eb0be08e4c..2ebb439575 100644 --- a/src/analyzer/protocol/dhcp/dhcp-options.pac +++ b/src/analyzer/protocol/dhcp/dhcp-options.pac @@ -57,7 +57,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_router_option(v: OptionValue): bool %{ - auto router_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); + auto router_list = make_intrusive(zeek::BifType::Vector::DHCP::Addrs); int num_routers = ${v.router_list}->size(); vector* rlist = ${v.router_list}; @@ -91,7 +91,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_timeserver_option(v: OptionValue): bool %{ - auto timeserver_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); + auto timeserver_list = make_intrusive(zeek::BifType::Vector::DHCP::Addrs); int num_servers = ${v.timeserver_list}->size(); vector* rlist = ${v.timeserver_list}; @@ -125,7 +125,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_nameserver_option(v: OptionValue): bool %{ - auto nameserver_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); + auto nameserver_list = make_intrusive(zeek::BifType::Vector::DHCP::Addrs); int num_servers = ${v.nameserver_list}->size(); vector* rlist = ${v.nameserver_list}; @@ -159,7 +159,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_dns_server_option(v: OptionValue): bool %{ - auto server_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); + auto server_list = make_intrusive(zeek::BifType::Vector::DHCP::Addrs); int num_servers = ${v.dns_server_list}->size(); vector* rlist = ${v.dns_server_list}; @@ -298,7 +298,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_ntpserver_option(v: OptionValue): bool %{ - auto ntpserver_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); + auto ntpserver_list = make_intrusive(zeek::BifType::Vector::DHCP::Addrs); int num_servers = ${v.ntpserver_list}->size(); vector* rlist = ${v.ntpserver_list}; @@ -356,7 +356,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_nbns_option(v: OptionValue): bool %{ - auto server_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::Addrs}); + auto server_list = make_intrusive(zeek::BifType::Vector::DHCP::Addrs); int num_servers = ${v.nbns}->size(); vector* rlist = ${v.nbns}; @@ -625,7 +625,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_client_id_option(v: OptionValue): bool %{ - RecordVal* client_id = new RecordVal(BifType::Record::DHCP::ClientID); + RecordVal* client_id = new RecordVal(zeek::BifType::Record::DHCP::ClientID); client_id->Assign(0, val_mgr->Count(${v.client_id.hwtype})); client_id->Assign(1, make_intrusive(fmt_mac(${v.client_id.hwaddr}.begin(), ${v.client_id.hwaddr}.length()))); @@ -685,7 +685,7 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_client_fqdn_option(v: OptionValue): bool %{ - RecordVal* client_fqdn = new RecordVal(BifType::Record::DHCP::ClientFQDN); + RecordVal* client_fqdn = new RecordVal(zeek::BifType::Record::DHCP::ClientFQDN); client_fqdn->Assign(0, val_mgr->Count(${v.client_fqdn.flags})); client_fqdn->Assign(1, val_mgr->Count(${v.client_fqdn.rcode1})); client_fqdn->Assign(2, val_mgr->Count(${v.client_fqdn.rcode2})); @@ -743,14 +743,14 @@ refine flow DHCP_Flow += { function process_relay_agent_inf_option(v: OptionValue): bool %{ - auto relay_agent_sub_opt = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::DHCP::SubOpts}); + auto relay_agent_sub_opt = make_intrusive(zeek::BifType::Vector::DHCP::SubOpts); uint16 i = 0; for ( auto ptrsubopt = ${v.relay_agent_inf}->begin(); ptrsubopt != ${v.relay_agent_inf}->end(); ++ptrsubopt ) { - auto r = new RecordVal(BifType::Record::DHCP::SubOpt); + auto r = new RecordVal(zeek::BifType::Record::DHCP::SubOpt); r->Assign(0, val_mgr->Count((*ptrsubopt)->code())); r->Assign(1, to_stringval((*ptrsubopt)->value())); diff --git a/src/analyzer/protocol/ftp/functions.bif b/src/analyzer/protocol/ftp/functions.bif index 6dff964042..204481b575 100644 --- a/src/analyzer/protocol/ftp/functions.bif +++ b/src/analyzer/protocol/ftp/functions.bif @@ -6,7 +6,7 @@ type ftp_port: record; static IntrusivePtr parse_port(const char* line) { - auto r = make_intrusive(BifType::Record::ftp_port); + auto r = make_intrusive(zeek::BifType::Record::ftp_port); int bytes[6]; if ( line && sscanf(line, "%d,%d,%d,%d,%d,%d", @@ -49,7 +49,7 @@ static IntrusivePtr parse_port(const char* line) static IntrusivePtr parse_eftp(const char* line) { - auto r = make_intrusive(BifType::Record::ftp_port); + auto r = make_intrusive(zeek::BifType::Record::ftp_port); int net_proto = 0; // currently not used IPAddr addr; // unspecified IPv6 address (all 128 bits zero) diff --git a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac index d7e9ca9010..6b06e0383a 100644 --- a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac +++ b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac @@ -6,7 +6,7 @@ %code{ IntrusivePtr BuildGTPv1Hdr(const GTPv1_Header* pdu) { - auto rv = make_intrusive(BifType::Record::gtpv1_hdr); + auto rv = make_intrusive(zeek::BifType::Record::gtpv1_hdr); rv->Assign(0, val_mgr->Count(pdu->version())); rv->Assign(1, val_mgr->Bool(pdu->pt_flag())); @@ -35,7 +35,7 @@ static IntrusivePtr BuildIMSI(const InformationElement* ie) static IntrusivePtr BuildRAI(const InformationElement* ie) { - auto ev = make_intrusive(BifType::Record::gtp_rai); + auto ev = make_intrusive(zeek::BifType::Record::gtp_rai); ev->Assign(0, val_mgr->Count(ie->rai()->mcc())); ev->Assign(1, val_mgr->Count(ie->rai()->mnc())); ev->Assign(2, val_mgr->Count(ie->rai()->lac())); @@ -85,7 +85,7 @@ static IntrusivePtr BuildTraceType(const InformationElement* ie) Val* BuildEndUserAddr(const InformationElement* ie) { - RecordVal* ev = new RecordVal(BifType::Record::gtp_end_user_addr); + RecordVal* ev = new RecordVal(zeek::BifType::Record::gtp_end_user_addr); ev->Assign(0, val_mgr->Count(ie->end_user_addr()->pdp_type_org())); ev->Assign(1, val_mgr->Count(ie->end_user_addr()->pdp_type_num())); @@ -130,7 +130,7 @@ Val* BuildProtoConfigOptions(const InformationElement* ie) Val* BuildGSN_Addr(const InformationElement* ie) { - RecordVal* ev = new RecordVal(BifType::Record::gtp_gsn_addr); + RecordVal* ev = new RecordVal(zeek::BifType::Record::gtp_gsn_addr); int len = ie->gsn_addr()->value().length(); const uint8* d = ie->gsn_addr()->value().data(); @@ -156,7 +156,7 @@ Val* BuildMSISDN(const InformationElement* ie) Val* BuildQoS_Profile(const InformationElement* ie) { - RecordVal* ev = new RecordVal(BifType::Record::gtp_qos_profile); + RecordVal* ev = new RecordVal(zeek::BifType::Record::gtp_qos_profile); const u_char* d = (const u_char*) ie->qos_profile()->data().data(); int len = ie->qos_profile()->data().length(); @@ -190,7 +190,7 @@ Val* BuildOMC_ID(const InformationElement* ie) Val* BuildPrivateExt(const InformationElement* ie) { - RecordVal* ev = new RecordVal(BifType::Record::gtp_private_extension); + RecordVal* ev = new RecordVal(zeek::BifType::Record::gtp_private_extension); const uint8* d = ie->private_ext()->value().data(); int len = ie->private_ext()->value().length(); @@ -238,7 +238,7 @@ void CreatePDP_Request(const BroAnalyzer& a, const GTPv1_Header* pdu) if ( ! ::gtpv1_create_pdp_ctx_request ) return; auto rv = make_intrusive( - BifType::Record::gtp_create_pdp_ctx_request_elements); + zeek::BifType::Record::gtp_create_pdp_ctx_request_elements); const vector * v = pdu->create_pdp_ctx_request(); @@ -338,7 +338,7 @@ void CreatePDP_Response(const BroAnalyzer& a, const GTPv1_Header* pdu) return; auto rv = make_intrusive( - BifType::Record::gtp_create_pdp_ctx_response_elements); + zeek::BifType::Record::gtp_create_pdp_ctx_response_elements); const vector * v = pdu->create_pdp_ctx_response(); @@ -407,7 +407,7 @@ void UpdatePDP_Request(const BroAnalyzer& a, const GTPv1_Header* pdu) return; auto rv = make_intrusive( - BifType::Record::gtp_update_pdp_ctx_request_elements); + zeek::BifType::Record::gtp_update_pdp_ctx_request_elements); const vector * v = pdu->update_pdp_ctx_request(); @@ -485,7 +485,7 @@ void UpdatePDP_Response(const BroAnalyzer& a, const GTPv1_Header* pdu) return; auto rv = make_intrusive( - BifType::Record::gtp_update_pdp_ctx_response_elements); + zeek::BifType::Record::gtp_update_pdp_ctx_response_elements); const vector * v = pdu->update_pdp_ctx_response(); @@ -545,7 +545,7 @@ void DeletePDP_Request(const BroAnalyzer& a, const GTPv1_Header* pdu) return; auto rv = make_intrusive( - BifType::Record::gtp_delete_pdp_ctx_request_elements); + zeek::BifType::Record::gtp_delete_pdp_ctx_request_elements); const vector * v = pdu->delete_pdp_ctx_request(); @@ -579,7 +579,7 @@ void DeletePDP_Response(const BroAnalyzer& a, const GTPv1_Header* pdu) return; auto rv = make_intrusive( - BifType::Record::gtp_delete_pdp_ctx_response_elements); + zeek::BifType::Record::gtp_delete_pdp_ctx_response_elements); const vector * v = pdu->delete_pdp_ctx_response(); diff --git a/src/analyzer/protocol/krb/krb-analyzer.pac b/src/analyzer/protocol/krb/krb-analyzer.pac index b45dea41b4..d36f721b44 100644 --- a/src/analyzer/protocol/krb/krb-analyzer.pac +++ b/src/analyzer/protocol/krb/krb-analyzer.pac @@ -8,7 +8,7 @@ bool proc_error_arguments(RecordVal* rv, const std::vector* args %code{ RecordVal* proc_krb_kdc_options(const KRB_KDC_Options* opts) { - RecordVal* rv = new RecordVal(BifType::Record::KRB::KDC_Options); + RecordVal* rv = new RecordVal(zeek::BifType::Record::KRB::KDC_Options); rv->Assign(0, val_mgr->Bool(opts->forwardable())); rv->Assign(1, val_mgr->Bool(opts->forwarded())); @@ -29,7 +29,7 @@ RecordVal* proc_krb_kdc_options(const KRB_KDC_Options* opts) RecordVal* proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer) { - RecordVal* rv = new RecordVal(BifType::Record::KRB::KDC_Request); + RecordVal* rv = new RecordVal(zeek::BifType::Record::KRB::KDC_Request); rv->Assign(0, asn1_integer_to_val(msg->pvno()->data(), TYPE_COUNT)); rv->Assign(1, asn1_integer_to_val(msg->msg_type()->data(), TYPE_COUNT)); @@ -203,7 +203,7 @@ refine connection KRB_Conn += { auto msg_type = binary_to_int64(${msg.msg_type.data.content}); auto make_arg = [this, msg]() -> IntrusivePtr { - auto rv = make_intrusive(BifType::Record::KRB::KDC_Response); + auto rv = make_intrusive(zeek::BifType::Record::KRB::KDC_Response); rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)); rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)); @@ -244,7 +244,7 @@ refine connection KRB_Conn += { bro_analyzer()->ProtocolConfirmation(); if ( krb_error ) { - auto rv = make_intrusive(BifType::Record::KRB::Error_Msg); + auto rv = make_intrusive(zeek::BifType::Record::KRB::Error_Msg); proc_error_arguments(rv.get(), ${msg.args1}, 0); rv->Assign(4, asn1_integer_to_val(${msg.error_code}, TYPE_COUNT)); proc_error_arguments(rv.get(), ${msg.args2}, binary_to_int64(${msg.error_code.encoding.content})); @@ -258,7 +258,7 @@ refine connection KRB_Conn += { bro_analyzer()->ProtocolConfirmation(); if ( krb_ap_request ) { - auto rv = make_intrusive(BifType::Record::KRB::AP_Options); + auto rv = make_intrusive(zeek::BifType::Record::KRB::AP_Options); rv->Assign(0, val_mgr->Bool(${msg.ap_options.use_session_key})); rv->Assign(1, val_mgr->Bool(${msg.ap_options.mutual_required})); @@ -289,7 +289,7 @@ refine connection KRB_Conn += { bro_analyzer()->ProtocolConfirmation(); if ( krb_safe ) { - auto rv = make_intrusive(BifType::Record::KRB::SAFE_Msg); + auto rv = make_intrusive(zeek::BifType::Record::KRB::SAFE_Msg); rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)); rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)); diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index c5bc3f1b8c..7f77d5db0d 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -36,7 +36,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a break; case PA_PW_SALT: { - RecordVal * type_val = new RecordVal(BifType::Record::KRB::Type_Value); + RecordVal * type_val = new RecordVal(zeek::BifType::Record::KRB::Type_Value); type_val->Assign(0, val_mgr->Count(element->data_type())); type_val->Assign(1, to_stringval(element->pa_data_element()->pa_pw_salt()->encoding()->content())); vv->Assign(vv->Size(), type_val); @@ -44,7 +44,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a } case PA_ENCTYPE_INFO: { - RecordVal * type_val = new RecordVal(BifType::Record::KRB::Type_Value); + RecordVal * type_val = new RecordVal(zeek::BifType::Record::KRB::Type_Value); type_val->Assign(0, val_mgr->Count(element->data_type())); type_val->Assign(1, to_stringval(element->pa_data_element()->pf_enctype_info()->salt())); vv->Assign(vv->Size(), type_val); @@ -52,7 +52,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a } case PA_ENCTYPE_INFO2: { - RecordVal * type_val = new RecordVal(BifType::Record::KRB::Type_Value); + RecordVal * type_val = new RecordVal(zeek::BifType::Record::KRB::Type_Value); type_val->Assign(0, val_mgr->Count(element->data_type())); type_val->Assign(1, to_stringval(element->pa_data_element()->pf_enctype_info2()->salt())); vv->Assign(vv->Size(), type_val); @@ -110,7 +110,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a { if ( ! is_error && element->pa_data_element()->unknown()->meta()->length() > 0 ) { - RecordVal * type_val = new RecordVal(BifType::Record::KRB::Type_Value); + RecordVal * type_val = new RecordVal(zeek::BifType::Record::KRB::Type_Value); type_val->Assign(0, val_mgr->Count(element->data_type())); type_val->Assign(1, to_stringval(element->pa_data_element()->unknown()->content())); vv->Assign(vv->Size(), type_val); diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index 0802b98f1e..e7163596b2 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -47,7 +47,7 @@ VectorVal* proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) { - RecordVal* rv = new RecordVal(BifType::Record::KRB::Host_Address); + RecordVal* rv = new RecordVal(zeek::BifType::Record::KRB::Host_Address); const auto& addr_bytes = addr->address()->data()->content(); switch ( binary_to_int64(addr->addr_type()->encoding()->content()) ) @@ -85,7 +85,7 @@ RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) break; } - RecordVal* unk = new RecordVal(BifType::Record::KRB::Type_Value); + RecordVal* unk = new RecordVal(zeek::BifType::Record::KRB::Type_Value); unk->Assign(0, asn1_integer_to_val(addr->addr_type(), TYPE_COUNT)); unk->Assign(1, to_stringval(addr_bytes)); rv->Assign(2, unk); @@ -107,7 +107,7 @@ IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list) IntrusivePtr proc_ticket(const KRB_Ticket* ticket) { - auto rv = make_intrusive(BifType::Record::KRB::Ticket); + auto rv = make_intrusive(zeek::BifType::Record::KRB::Ticket); rv->Assign(0, asn1_integer_to_val(ticket->tkt_vno()->data(), TYPE_COUNT)); rv->Assign(1, to_stringval(ticket->realm()->data()->content())); diff --git a/src/analyzer/protocol/modbus/modbus-analyzer.pac b/src/analyzer/protocol/modbus/modbus-analyzer.pac index ac0c027d8f..52e9d41838 100644 --- a/src/analyzer/protocol/modbus/modbus-analyzer.pac +++ b/src/analyzer/protocol/modbus/modbus-analyzer.pac @@ -16,7 +16,7 @@ %code{ IntrusivePtr bytestring_to_coils(const bytestring& coils, uint quantity) { - auto modbus_coils = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusCoils}); + auto modbus_coils = make_intrusive(zeek::BifType::Vector::ModbusCoils); for ( uint i = 0; i < quantity; i++ ) { @@ -29,7 +29,7 @@ IntrusivePtr HeaderToVal(ModbusTCP_TransportHeader* header) { - auto modbus_header = make_intrusive(BifType::Record::ModbusHeaders); + auto modbus_header = make_intrusive(zeek::BifType::Record::ModbusHeaders); modbus_header->Assign(0, val_mgr->Count(header->tid())); modbus_header->Assign(1, val_mgr->Count(header->pid())); modbus_header->Assign(2, val_mgr->Count(header->uid())); @@ -209,7 +209,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_read_holding_registers_response ) { - auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); + auto t = make_intrusive(zeek::BifType::Vector::ModbusRegisters); for ( unsigned int i=0; i < ${message.registers}->size(); ++i ) { @@ -253,7 +253,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_read_input_registers_response ) { - auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); + auto t = make_intrusive(zeek::BifType::Vector::ModbusRegisters); for ( unsigned int i=0; i < (${message.registers})->size(); ++i ) { @@ -397,7 +397,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_write_multiple_registers_request ) { - auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); + auto t = make_intrusive(zeek::BifType::Vector::ModbusRegisters); for ( unsigned int i = 0; i < (${message.registers}->size()); ++i ) { @@ -582,7 +582,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_read_write_multiple_registers_request ) { - auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); + auto t = make_intrusive(zeek::BifType::Vector::ModbusRegisters); for ( unsigned int i = 0; i < ${message.write_register_values}->size(); ++i ) { @@ -614,7 +614,7 @@ refine flow ModbusTCP_Flow += { if ( ::modbus_read_write_multiple_registers_response ) { - auto t = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::ModbusRegisters}); + auto t = make_intrusive(zeek::BifType::Vector::ModbusRegisters); for ( unsigned int i = 0; i < ${message.registers}->size(); ++i ) { diff --git a/src/analyzer/protocol/mqtt/commands/connack.pac b/src/analyzer/protocol/mqtt/commands/connack.pac index a1d139f93e..98ac7c4122 100644 --- a/src/analyzer/protocol/mqtt/commands/connack.pac +++ b/src/analyzer/protocol/mqtt/commands/connack.pac @@ -15,7 +15,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_connack ) { - auto m = make_intrusive(BifType::Record::MQTT::ConnectAckMsg); + auto m = make_intrusive(zeek::BifType::Record::MQTT::ConnectAckMsg); m->Assign(0, val_mgr->Count(${msg.return_code})); m->Assign(1, val_mgr->Bool(${msg.session_present})); BifEvent::enqueue_mqtt_connack(connection()->bro_analyzer(), diff --git a/src/analyzer/protocol/mqtt/commands/connect.pac b/src/analyzer/protocol/mqtt/commands/connect.pac index a355097a63..4c4f5374a3 100644 --- a/src/analyzer/protocol/mqtt/commands/connect.pac +++ b/src/analyzer/protocol/mqtt/commands/connect.pac @@ -44,7 +44,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_connect ) { - auto m = make_intrusive(BifType::Record::MQTT::ConnectMsg); + auto m = make_intrusive(zeek::BifType::Record::MQTT::ConnectMsg); m->Assign(0, make_intrusive(${msg.protocol_name.str}.length(), reinterpret_cast(${msg.protocol_name.str}.begin()))); m->Assign(1, val_mgr->Count(${msg.protocol_version})); diff --git a/src/analyzer/protocol/mqtt/commands/publish.pac b/src/analyzer/protocol/mqtt/commands/publish.pac index 72bce23c65..ecb1d3e380 100644 --- a/src/analyzer/protocol/mqtt/commands/publish.pac +++ b/src/analyzer/protocol/mqtt/commands/publish.pac @@ -23,7 +23,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_publish ) { - auto m = make_intrusive(BifType::Record::MQTT::PublishMsg); + auto m = make_intrusive(zeek::BifType::Record::MQTT::PublishMsg); m->Assign(0, val_mgr->Bool(${msg.dup})); m->Assign(1, val_mgr->Count(${msg.qos})); m->Assign(2, val_mgr->Bool(${msg.retain})); diff --git a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac index 97c012814c..50d52c5a7d 100644 --- a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac +++ b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac @@ -15,7 +15,7 @@ refine connection NTLM_Conn += { function build_version_record(val: NTLM_Version): BroVal %{ - RecordVal* result = new RecordVal(BifType::Record::NTLM::Version); + RecordVal* result = new RecordVal(zeek::BifType::Record::NTLM::Version); result->Assign(0, val_mgr->Count(${val.major_version})); result->Assign(1, val_mgr->Count(${val.minor_version})); result->Assign(2, val_mgr->Count(${val.build_number})); @@ -26,7 +26,7 @@ refine connection NTLM_Conn += { function build_av_record(val: NTLM_AV_Pair_Sequence, len: uint16): BroVal %{ - RecordVal* result = new RecordVal(BifType::Record::NTLM::AVs); + RecordVal* result = new RecordVal(zeek::BifType::Record::NTLM::AVs); for ( uint i = 0; ; i++ ) { if ( i >= ${val.pairs}->size() ) @@ -78,7 +78,7 @@ refine connection NTLM_Conn += { function build_negotiate_flag_record(val: NTLM_Negotiate_Flags): BroVal %{ - RecordVal* flags = new RecordVal(BifType::Record::NTLM::NegotiateFlags); + RecordVal* flags = new RecordVal(zeek::BifType::Record::NTLM::NegotiateFlags); flags->Assign(0, val_mgr->Bool(${val.negotiate_56})); flags->Assign(1, val_mgr->Bool(${val.negotiate_key_exch})); flags->Assign(2, val_mgr->Bool(${val.negotiate_128})); @@ -110,7 +110,7 @@ refine connection NTLM_Conn += { if ( ! ntlm_negotiate ) return true; - auto result = make_intrusive(BifType::Record::NTLM::Negotiate); + auto result = make_intrusive(zeek::BifType::Record::NTLM::Negotiate); result->Assign(0, build_negotiate_flag_record(${val.flags})); if ( ${val}->has_domain_name() ) @@ -134,7 +134,7 @@ refine connection NTLM_Conn += { if ( ! ntlm_challenge ) return true; - auto result = make_intrusive(BifType::Record::NTLM::Challenge); + auto result = make_intrusive(zeek::BifType::Record::NTLM::Challenge); result->Assign(0, build_negotiate_flag_record(${val.flags})); if ( ${val}->has_target_name() ) @@ -158,7 +158,7 @@ refine connection NTLM_Conn += { if ( ! ntlm_authenticate ) return true; - auto result = make_intrusive(BifType::Record::NTLM::Authenticate); + auto result = make_intrusive(zeek::BifType::Record::NTLM::Authenticate); result->Assign(0, build_negotiate_flag_record(${val.flags})); if ( ${val}->has_domain_name() > 0 ) diff --git a/src/analyzer/protocol/ntp/ntp-analyzer.pac b/src/analyzer/protocol/ntp/ntp-analyzer.pac index afac5ce304..10e92a33a1 100644 --- a/src/analyzer/protocol/ntp/ntp-analyzer.pac +++ b/src/analyzer/protocol/ntp/ntp-analyzer.pac @@ -35,7 +35,7 @@ refine flow NTP_Flow += { # This builds the standard msg record function BuildNTPStdMsg(nsm: NTP_std_msg): BroVal %{ - RecordVal* rv = new RecordVal(BifType::Record::NTP::StandardMessage); + RecordVal* rv = new RecordVal(zeek::BifType::Record::NTP::StandardMessage); rv->Assign(0, val_mgr->Count(${nsm.stratum})); rv->Assign(1, make_intrusive(pow(2, ${nsm.poll}), TYPE_INTERVAL)); @@ -88,7 +88,7 @@ refine flow NTP_Flow += { # This builds the control msg record function BuildNTPControlMsg(ncm: NTP_control_msg): BroVal %{ - RecordVal* rv = new RecordVal(BifType::Record::NTP::ControlMessage); + RecordVal* rv = new RecordVal(zeek::BifType::Record::NTP::ControlMessage); rv->Assign(0, val_mgr->Count(${ncm.OpCode})); rv->Assign(1, val_mgr->Bool(${ncm.R})); @@ -113,7 +113,7 @@ refine flow NTP_Flow += { # This builds the mode7 msg record function BuildNTPMode7Msg(m7: NTP_mode7_msg): BroVal %{ - RecordVal* rv = new RecordVal(BifType::Record::NTP::Mode7Message); + RecordVal* rv = new RecordVal(zeek::BifType::Record::NTP::Mode7Message); rv->Assign(0, val_mgr->Count(${m7.request_code})); rv->Assign(1, val_mgr->Bool(${m7.auth_bit})); @@ -135,7 +135,7 @@ refine flow NTP_Flow += { if ( ! ntp_message ) return false; - auto rv = make_intrusive(BifType::Record::NTP::Message); + auto rv = make_intrusive(zeek::BifType::Record::NTP::Message); rv->Assign(0, val_mgr->Count(${msg.version})); rv->Assign(1, val_mgr->Count(${msg.mode})); diff --git a/src/analyzer/protocol/radius/radius-analyzer.pac b/src/analyzer/protocol/radius/radius-analyzer.pac index 059a61f58a..337b7a6364 100644 --- a/src/analyzer/protocol/radius/radius-analyzer.pac +++ b/src/analyzer/protocol/radius/radius-analyzer.pac @@ -7,14 +7,14 @@ refine flow RADIUS_Flow += { if ( ! radius_message ) return false; - auto result = make_intrusive(BifType::Record::RADIUS::Message); + auto result = make_intrusive(zeek::BifType::Record::RADIUS::Message); result->Assign(0, val_mgr->Count(${msg.code})); result->Assign(1, val_mgr->Count(${msg.trans_id})); result->Assign(2, to_stringval(${msg.authenticator})); if ( ${msg.attributes}->size() ) { - TableVal* attributes = new TableVal({NewRef{}, BifType::Table::RADIUS::Attributes}); + TableVal* attributes = new TableVal(zeek::BifType::Table::RADIUS::Attributes); for ( uint i = 0; i < ${msg.attributes}->size(); ++i ) { @@ -32,7 +32,7 @@ refine flow RADIUS_Flow += { else { - auto attribute_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::RADIUS::AttributeList}); + auto attribute_list = make_intrusive(zeek::BifType::Vector::RADIUS::AttributeList); attribute_list->Assign((unsigned int)0, std::move(val)); attributes->Assign(index.get(), std::move(attribute_list)); } diff --git a/src/analyzer/protocol/rdp/rdp-analyzer.pac b/src/analyzer/protocol/rdp/rdp-analyzer.pac index 4caa48393e..2e2de63afc 100644 --- a/src/analyzer/protocol/rdp/rdp-analyzer.pac +++ b/src/analyzer/protocol/rdp/rdp-analyzer.pac @@ -61,7 +61,7 @@ refine flow RDP_Flow += { if ( rdp_client_core_data ) { - auto ec_flags = make_intrusive(BifType::Record::RDP::EarlyCapabilityFlags); + auto ec_flags = make_intrusive(zeek::BifType::Record::RDP::EarlyCapabilityFlags); ec_flags->Assign(0, val_mgr->Bool(${ccore.SUPPORT_ERRINFO_PDU})); ec_flags->Assign(1, val_mgr->Bool(${ccore.WANT_32BPP_SESSION})); ec_flags->Assign(2, val_mgr->Bool(${ccore.SUPPORT_STATUSINFO_PDU})); @@ -72,7 +72,7 @@ refine flow RDP_Flow += { ec_flags->Assign(7, val_mgr->Bool(${ccore.SUPPORT_DYNAMIC_TIME_ZONE})); ec_flags->Assign(8, val_mgr->Bool(${ccore.SUPPORT_HEARTBEAT_PDU})); - auto ccd = make_intrusive(BifType::Record::RDP::ClientCoreData); + auto ccd = make_intrusive(zeek::BifType::Record::RDP::ClientCoreData); ccd->Assign(0, val_mgr->Count(${ccore.version_major})); ccd->Assign(1, val_mgr->Count(${ccore.version_minor})); ccd->Assign(2, val_mgr->Count(${ccore.desktop_width})); @@ -107,7 +107,7 @@ refine flow RDP_Flow += { if ( ! rdp_client_security_data ) return false; - auto csd = make_intrusive(BifType::Record::RDP::ClientSecurityData); + auto csd = make_intrusive(zeek::BifType::Record::RDP::ClientSecurityData); csd->Assign(0, val_mgr->Count(${csec.encryption_methods})); csd->Assign(1, val_mgr->Count(${csec.ext_encryption_methods})); @@ -124,11 +124,11 @@ refine flow RDP_Flow += { if ( ${cnetwork.channel_def_array}->size() ) { - auto channels = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::RDP::ClientChannelList}); + auto channels = make_intrusive(zeek::BifType::Vector::RDP::ClientChannelList); for ( uint i = 0; i < ${cnetwork.channel_def_array}->size(); ++i ) { - auto channel_def = make_intrusive(BifType::Record::RDP::ClientChannelDef); + auto channel_def = make_intrusive(zeek::BifType::Record::RDP::ClientChannelDef); channel_def->Assign(0, to_stringval(${cnetwork.channel_def_array[i].name})); channel_def->Assign(1, val_mgr->Count(${cnetwork.channel_def_array[i].options})); @@ -161,7 +161,7 @@ refine flow RDP_Flow += { if ( ! rdp_client_cluster_data ) return false; - auto ccld = make_intrusive(BifType::Record::RDP::ClientClusterData); + auto ccld = make_intrusive(zeek::BifType::Record::RDP::ClientClusterData); ccld->Assign(0, val_mgr->Count(${ccluster.flags})); ccld->Assign(1, val_mgr->Count(${ccluster.redir_session_id})); ccld->Assign(2, val_mgr->Bool(${ccluster.REDIRECTION_SUPPORTED})); diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index b8060730d4..501f5a8563 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -139,7 +139,7 @@ bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_statu // Otherwise DeliverRPC would complain about // excess_RPC. n = 0; - reply = BifType::Enum::MOUNT3::proc_t->GetVal(c->Proc()).release(); + reply = zeek::BifType::Enum::MOUNT3::proc_t->GetVal(c->Proc()).release(); event = mount_proc_not_implemented; } else @@ -199,9 +199,9 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, auxgids->Assign(i, val_mgr->Count(c->AuxGIDs()[i])); } - auto info = make_intrusive(BifType::Record::MOUNT3::info_t); - info->Assign(0, BifType::Enum::rpc_status->GetVal(rpc_status)); - info->Assign(1, BifType::Enum::MOUNT3::status_t->GetVal(mount_status)); + auto info = make_intrusive(zeek::BifType::Record::MOUNT3::info_t); + info->Assign(0, zeek::BifType::Enum::rpc_status->GetVal(rpc_status)); + info->Assign(1, zeek::BifType::Enum::MOUNT3::status_t->GetVal(mount_status)); info->Assign(2, make_intrusive(c->StartTime(), TYPE_TIME)); info->Assign(3, make_intrusive(c->LastTime() - c->StartTime(), TYPE_INTERVAL)); info->Assign(4, val_mgr->Count(c->RPCLen())); @@ -221,7 +221,7 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, EnumVal* MOUNT_Interp::mount3_auth_flavor(const u_char*& buf, int& n) { BifEnum::MOUNT3::auth_flavor_t t = (BifEnum::MOUNT3::auth_flavor_t)extract_XDR_uint32(buf, n); - return BifType::Enum::MOUNT3::auth_flavor_t->GetVal(t).release(); + return zeek::BifType::Enum::MOUNT3::auth_flavor_t->GetVal(t).release(); } StringVal* MOUNT_Interp::mount3_fh(const u_char*& buf, int& n) @@ -248,7 +248,7 @@ StringVal* MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) RecordVal* MOUNT_Interp::mount3_dirmntargs(const u_char*& buf, int& n) { - RecordVal* dirmntargs = new RecordVal(BifType::Record::MOUNT3::dirmntargs_t); + RecordVal* dirmntargs = new RecordVal(zeek::BifType::Record::MOUNT3::dirmntargs_t); dirmntargs->Assign(0, mount3_filename(buf, n)); return dirmntargs; } @@ -256,7 +256,7 @@ RecordVal* MOUNT_Interp::mount3_dirmntargs(const u_char*& buf, int& n) RecordVal* MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n, BifEnum::MOUNT3::status_t status) { - RecordVal* rep = new RecordVal(BifType::Record::MOUNT3::mnt_reply_t); + RecordVal* rep = new RecordVal(zeek::BifType::Record::MOUNT3::mnt_reply_t); if ( status == BifEnum::MOUNT3::MNT3_OK ) { diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index 2a60851e56..c57e1eba38 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -251,7 +251,7 @@ bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, // Otherwise DeliverRPC would complain about // excess_RPC. n = 0; - reply = BifType::Enum::NFS3::proc_t->GetVal(c->Proc()).release(); + reply = zeek::BifType::Enum::NFS3::proc_t->GetVal(c->Proc()).release(); event = nfs_proc_not_implemented; } else @@ -333,9 +333,9 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_ for ( size_t i = 0; i < c->AuxGIDs().size(); ++i ) auxgids->Assign(i, val_mgr->Count(c->AuxGIDs()[i])); - auto info = make_intrusive(BifType::Record::NFS3::info_t); - info->Assign(0, BifType::Enum::rpc_status->GetVal(rpc_status)); - info->Assign(1, BifType::Enum::NFS3::status_t->GetVal(nfs_status)); + auto info = make_intrusive(zeek::BifType::Record::NFS3::info_t); + info->Assign(0, zeek::BifType::Enum::rpc_status->GetVal(rpc_status)); + info->Assign(1, zeek::BifType::Enum::NFS3::status_t->GetVal(nfs_status)); info->Assign(2, make_intrusive(c->StartTime(), TYPE_TIME)); info->Assign(3, make_intrusive(c->LastTime()-c->StartTime(), TYPE_INTERVAL)); info->Assign(4, val_mgr->Count(c->RPCLen())); @@ -366,7 +366,7 @@ StringVal* NFS_Interp::nfs3_fh(const u_char*& buf, int& n) RecordVal* NFS_Interp::nfs3_sattr(const u_char*& buf, int& n) { - RecordVal* attrs = new RecordVal(BifType::Record::NFS3::sattr_t); + RecordVal* attrs = new RecordVal(zeek::BifType::Record::NFS3::sattr_t); attrs->Assign(0, nullptr); // mode int mode_set_it = extract_XDR_uint32(buf, n); @@ -397,7 +397,7 @@ RecordVal* NFS_Interp::nfs3_sattr(const u_char*& buf, int& n) RecordVal* NFS_Interp::nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal* rep = new RecordVal(BifType::Record::NFS3::sattr_reply_t); + RecordVal* rep = new RecordVal(zeek::BifType::Record::NFS3::sattr_reply_t); if ( status == BifEnum::NFS3::NFS3ERR_OK ) { @@ -415,7 +415,7 @@ RecordVal* NFS_Interp::nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS RecordVal* NFS_Interp::nfs3_fattr(const u_char*& buf, int& n) { - RecordVal* attrs = new RecordVal(BifType::Record::NFS3::fattr_t); + RecordVal* attrs = new RecordVal(zeek::BifType::Record::NFS3::fattr_t); attrs->Assign(0, nfs3_ftype(buf, n)); // file type attrs->Assign(1, ExtractUint32(buf, n)); // mode @@ -438,18 +438,18 @@ RecordVal* NFS_Interp::nfs3_fattr(const u_char*& buf, int& n) EnumVal* NFS_Interp::nfs3_time_how(const u_char*& buf, int& n) { BifEnum::NFS3::time_how_t t = (BifEnum::NFS3::time_how_t)extract_XDR_uint32(buf, n); - return BifType::Enum::NFS3::time_how_t->GetVal(t).release(); + return zeek::BifType::Enum::NFS3::time_how_t->GetVal(t).release(); } EnumVal* NFS_Interp::nfs3_ftype(const u_char*& buf, int& n) { BifEnum::NFS3::file_type_t t = (BifEnum::NFS3::file_type_t)extract_XDR_uint32(buf, n); - return BifType::Enum::NFS3::file_type_t->GetVal(t).release(); + return zeek::BifType::Enum::NFS3::file_type_t->GetVal(t).release(); } RecordVal* NFS_Interp::nfs3_wcc_attr(const u_char*& buf, int& n) { - RecordVal* attrs = new RecordVal(BifType::Record::NFS3::wcc_attr_t); + RecordVal* attrs = new RecordVal(zeek::BifType::Record::NFS3::wcc_attr_t); attrs->Assign(0, ExtractUint64(buf, n)); // size attrs->Assign(1, ExtractTime(buf, n)); // mtime @@ -471,7 +471,7 @@ StringVal *NFS_Interp::nfs3_filename(const u_char*& buf, int& n) RecordVal *NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n) { - RecordVal *diropargs = new RecordVal(BifType::Record::NFS3::diropargs_t); + RecordVal *diropargs = new RecordVal(zeek::BifType::Record::NFS3::diropargs_t); diropargs->Assign(0, nfs3_fh(buf, n)); diropargs->Assign(1, nfs3_filename(buf, n)); @@ -481,7 +481,7 @@ RecordVal *NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n) RecordVal* NFS_Interp::nfs3_symlinkdata(const u_char*& buf, int& n) { - RecordVal* symlinkdata = new RecordVal(BifType::Record::NFS3::symlinkdata_t); + RecordVal* symlinkdata = new RecordVal(zeek::BifType::Record::NFS3::symlinkdata_t); symlinkdata->Assign(0, nfs3_sattr(buf, n)); symlinkdata->Assign(1, nfs3_nfspath(buf, n)); @@ -491,7 +491,7 @@ RecordVal* NFS_Interp::nfs3_symlinkdata(const u_char*& buf, int& n) RecordVal *NFS_Interp::nfs3_renameopargs(const u_char*& buf, int& n) { - RecordVal *renameopargs = new RecordVal(BifType::Record::NFS3::renameopargs_t); + RecordVal *renameopargs = new RecordVal(zeek::BifType::Record::NFS3::renameopargs_t); renameopargs->Assign(0, nfs3_fh(buf, n)); renameopargs->Assign(1, nfs3_filename(buf, n)); @@ -533,12 +533,12 @@ RecordVal* NFS_Interp::nfs3_pre_op_attr(const u_char*& buf, int& n) EnumVal *NFS_Interp::nfs3_stable_how(const u_char*& buf, int& n) { BifEnum::NFS3::stable_how_t stable = (BifEnum::NFS3::stable_how_t)extract_XDR_uint32(buf, n); - return BifType::Enum::NFS3::stable_how_t->GetVal(stable).release(); + return zeek::BifType::Enum::NFS3::stable_how_t->GetVal(stable).release(); } RecordVal* NFS_Interp::nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(BifType::Record::NFS3::lookup_reply_t); + RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::lookup_reply_t); if ( status == BifEnum::NFS3::NFS3ERR_OK ) { @@ -557,7 +557,7 @@ RecordVal* NFS_Interp::nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NF RecordVal *NFS_Interp::nfs3_readargs(const u_char*& buf, int& n) { - RecordVal *readargs = new RecordVal(BifType::Record::NFS3::readargs_t); + RecordVal *readargs = new RecordVal(zeek::BifType::Record::NFS3::readargs_t); readargs->Assign(0, nfs3_fh(buf, n)); readargs->Assign(1, ExtractUint64(buf, n)); // offset @@ -569,7 +569,7 @@ RecordVal *NFS_Interp::nfs3_readargs(const u_char*& buf, int& n) RecordVal* NFS_Interp::nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, bro_uint_t offset) { - RecordVal *rep = new RecordVal(BifType::Record::NFS3::read_reply_t); + RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::read_reply_t); if (status == BifEnum::NFS3::NFS3ERR_OK) { @@ -591,7 +591,7 @@ RecordVal* NFS_Interp::nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3 RecordVal* NFS_Interp::nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(BifType::Record::NFS3::readlink_reply_t); + RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::readlink_reply_t); if (status == BifEnum::NFS3::NFS3ERR_OK) { @@ -608,7 +608,7 @@ RecordVal* NFS_Interp::nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum:: RecordVal* NFS_Interp::nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal* rep = new RecordVal(BifType::Record::NFS3::link_reply_t); + RecordVal* rep = new RecordVal(zeek::BifType::Record::NFS3::link_reply_t); if ( status == BifEnum::NFS3::NFS3ERR_OK ) { @@ -624,7 +624,7 @@ RecordVal* NFS_Interp::nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3 RecordVal* NFS_Interp::nfs3_symlinkargs(const u_char*& buf, int& n) { - RecordVal* symlinkargs = new RecordVal(BifType::Record::NFS3::symlinkargs_t); + RecordVal* symlinkargs = new RecordVal(zeek::BifType::Record::NFS3::symlinkargs_t); symlinkargs->Assign(0, nfs3_diropargs(buf, n)); symlinkargs->Assign(1, nfs3_symlinkdata(buf, n)); @@ -634,7 +634,7 @@ RecordVal* NFS_Interp::nfs3_symlinkargs(const u_char*& buf, int& n) RecordVal* NFS_Interp::nfs3_sattrargs(const u_char*& buf, int& n) { - RecordVal* sattrargs = new RecordVal(BifType::Record::NFS3::sattrargs_t); + RecordVal* sattrargs = new RecordVal(zeek::BifType::Record::NFS3::sattrargs_t); sattrargs->Assign(0, nfs3_fh(buf, n)); sattrargs->Assign(1, nfs3_sattr(buf, n)); @@ -644,7 +644,7 @@ RecordVal* NFS_Interp::nfs3_sattrargs(const u_char*& buf, int& n) RecordVal* NFS_Interp::nfs3_linkargs(const u_char*& buf, int& n) { - RecordVal* linkargs = new RecordVal(BifType::Record::NFS3::linkargs_t); + RecordVal* linkargs = new RecordVal(zeek::BifType::Record::NFS3::linkargs_t); linkargs->Assign(0, nfs3_fh(buf, n)); linkargs->Assign(1, nfs3_diropargs(buf, n)); @@ -656,7 +656,7 @@ RecordVal *NFS_Interp::nfs3_writeargs(const u_char*& buf, int& n) { uint32_t bytes; uint64_t offset; - RecordVal *writeargs = new RecordVal(BifType::Record::NFS3::writeargs_t); + RecordVal *writeargs = new RecordVal(zeek::BifType::Record::NFS3::writeargs_t); writeargs->Assign(0, nfs3_fh(buf, n)); offset = extract_XDR_uint64(buf, n); @@ -672,7 +672,7 @@ RecordVal *NFS_Interp::nfs3_writeargs(const u_char*& buf, int& n) RecordVal *NFS_Interp::nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(BifType::Record::NFS3::write_reply_t); + RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::write_reply_t); if ( status == BifEnum::NFS3::NFS3ERR_OK ) { @@ -697,7 +697,7 @@ RecordVal *NFS_Interp::nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS RecordVal* NFS_Interp::nfs3_newobj_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(BifType::Record::NFS3::newobj_reply_t); + RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::newobj_reply_t); if (status == BifEnum::NFS3::NFS3ERR_OK) { @@ -721,7 +721,7 @@ RecordVal* NFS_Interp::nfs3_newobj_reply(const u_char*& buf, int& n, BifEnum::NF RecordVal* NFS_Interp::nfs3_delobj_reply(const u_char*& buf, int& n) { - RecordVal *rep = new RecordVal(BifType::Record::NFS3::delobj_reply_t); + RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::delobj_reply_t); // wcc_data rep->Assign(0, nfs3_pre_op_attr(buf, n)); @@ -732,7 +732,7 @@ RecordVal* NFS_Interp::nfs3_delobj_reply(const u_char*& buf, int& n) RecordVal* NFS_Interp::nfs3_renameobj_reply(const u_char*& buf, int& n) { - RecordVal *rep = new RecordVal(BifType::Record::NFS3::renameobj_reply_t); + RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::renameobj_reply_t); // wcc_data rep->Assign(0, nfs3_pre_op_attr(buf, n)); @@ -745,7 +745,7 @@ RecordVal* NFS_Interp::nfs3_renameobj_reply(const u_char*& buf, int& n) RecordVal* NFS_Interp::nfs3_readdirargs(bool isplus, const u_char*& buf, int&n) { - RecordVal *args = new RecordVal(BifType::Record::NFS3::readdirargs_t); + RecordVal *args = new RecordVal(zeek::BifType::Record::NFS3::readdirargs_t); args->Assign(0, val_mgr->Bool(isplus)); args->Assign(1, nfs3_fh(buf, n)); @@ -762,14 +762,14 @@ RecordVal* NFS_Interp::nfs3_readdirargs(bool isplus, const u_char*& buf, int&n) RecordVal* NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char*& buf, int&n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(BifType::Record::NFS3::readdir_reply_t); + RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::readdir_reply_t); rep->Assign(0, val_mgr->Bool(isplus)); if ( status == BifEnum::NFS3::NFS3ERR_OK ) { unsigned pos; - auto entries = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::NFS3::direntry_vec_t}); + auto entries = make_intrusive(zeek::BifType::Vector::NFS3::direntry_vec_t); rep->Assign(1, nfs3_post_op_attr(buf,n)); // dir_attr rep->Assign(2, ExtractUint64(buf,n)); // cookieverf @@ -778,7 +778,7 @@ RecordVal* NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char*& buf, while ( extract_XDR_uint32(buf,n) ) { - RecordVal *entry = new RecordVal(BifType::Record::NFS3::direntry_t); + RecordVal *entry = new RecordVal(zeek::BifType::Record::NFS3::direntry_t); entry->Assign(0, ExtractUint64(buf,n)); // fileid entry->Assign(1, nfs3_filename(buf,n)); // fname entry->Assign(2, ExtractUint64(buf,n)); // cookie diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 9d6a938587..f185e4f67e 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -296,7 +296,7 @@ void PortmapperInterp::Event(EventHandlerPtr f, Val* request, BifEnum::rpc_statu } else { - vl.emplace_back(BifType::Enum::rpc_status->GetVal(status)); + vl.emplace_back(zeek::BifType::Enum::rpc_status->GetVal(status)); if ( request ) vl.emplace_back(AdoptRef{}, request); diff --git a/src/analyzer/protocol/rpc/RPC.cc b/src/analyzer/protocol/rpc/RPC.cc index 46240f8773..176bc33d5a 100644 --- a/src/analyzer/protocol/rpc/RPC.cc +++ b/src/analyzer/protocol/rpc/RPC.cc @@ -343,7 +343,7 @@ void RPC_Interpreter::Event_RPC_Dialogue(RPC_CallInfo* c, BifEnum::rpc_status st val_mgr->Count(c->Program()), val_mgr->Count(c->Version()), val_mgr->Count(c->Proc()), - BifType::Enum::rpc_status->GetVal(status), + zeek::BifType::Enum::rpc_status->GetVal(status), make_intrusive(c->StartTime(), TYPE_TIME), val_mgr->Count(c->CallLen()), val_mgr->Count(reply_len) @@ -369,7 +369,7 @@ void RPC_Interpreter::Event_RPC_Reply(uint32_t xid, BifEnum::rpc_status status, analyzer->EnqueueConnEvent(rpc_reply, analyzer->ConnVal(), val_mgr->Count(xid), - BifType::Enum::rpc_status->GetVal(status), + zeek::BifType::Enum::rpc_status->GetVal(status), val_mgr->Count(reply_len) ); } diff --git a/src/analyzer/protocol/smb/smb-time.pac b/src/analyzer/protocol/smb/smb-time.pac index a7ec9508eb..2fcc58f32e 100644 --- a/src/analyzer/protocol/smb/smb-time.pac +++ b/src/analyzer/protocol/smb/smb-time.pac @@ -32,7 +32,7 @@ IntrusivePtr time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz) IntrusivePtr SMB_BuildMACTimes(uint64_t modify, uint64_t access, uint64_t create, uint64_t change) { - auto r = make_intrusive(BifType::Record::SMB::MACTimes); + auto r = make_intrusive(zeek::BifType::Record::SMB::MACTimes); r->Assign(0, filetime2brotime(modify)); r->Assign(1, filetime2brotime(access)); r->Assign(2, filetime2brotime(create)); diff --git a/src/analyzer/protocol/smb/smb1-com-negotiate.pac b/src/analyzer/protocol/smb/smb1-com-negotiate.pac index 837dcf4ef7..8240848111 100644 --- a/src/analyzer/protocol/smb/smb1-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb1-com-negotiate.pac @@ -35,13 +35,13 @@ refine connection SMB_Conn += { %{ if ( smb1_negotiate_response ) { - auto response = make_intrusive(BifType::Record::SMB1::NegotiateResponse); + auto response = make_intrusive(zeek::BifType::Record::SMB1::NegotiateResponse); switch ( ${val.word_count} ) { case 0x01: { - auto core = make_intrusive(BifType::Record::SMB1::NegotiateResponseCore); + auto core = make_intrusive(zeek::BifType::Record::SMB1::NegotiateResponseCore); core->Assign(0, val_mgr->Count(${val.dialect_index})); response->Assign(0, std::move(core)); @@ -50,15 +50,15 @@ refine connection SMB_Conn += { case 0x0d: { - auto security = make_intrusive(BifType::Record::SMB1::NegotiateResponseSecurity); + auto security = make_intrusive(zeek::BifType::Record::SMB1::NegotiateResponseSecurity); security->Assign(0, val_mgr->Bool(${val.lanman.security_user_level})); security->Assign(1, val_mgr->Bool(${val.lanman.security_challenge_response})); - auto raw = make_intrusive(BifType::Record::SMB1::NegotiateRawMode); + auto raw = make_intrusive(zeek::BifType::Record::SMB1::NegotiateRawMode); raw->Assign(0, val_mgr->Bool(${val.lanman.raw_read_supported})); raw->Assign(1, val_mgr->Bool(${val.lanman.raw_write_supported})); - auto lanman = make_intrusive(BifType::Record::SMB1::NegotiateResponseLANMAN); + auto lanman = make_intrusive(zeek::BifType::Record::SMB1::NegotiateResponseLANMAN); lanman->Assign(0, val_mgr->Count(${val.word_count})); lanman->Assign(1, val_mgr->Count(${val.dialect_index})); lanman->Assign(2, std::move(security)); @@ -79,13 +79,13 @@ refine connection SMB_Conn += { case 0x11: { - auto security = make_intrusive(BifType::Record::SMB1::NegotiateResponseSecurity); + auto security = make_intrusive(zeek::BifType::Record::SMB1::NegotiateResponseSecurity); security->Assign(0, val_mgr->Bool(${val.ntlm.security_user_level})); security->Assign(1, val_mgr->Bool(${val.ntlm.security_challenge_response})); security->Assign(2, val_mgr->Bool(${val.ntlm.security_signatures_enabled})); security->Assign(3, val_mgr->Bool(${val.ntlm.security_signatures_required})); - auto capabilities = make_intrusive(BifType::Record::SMB1::NegotiateCapabilities); + auto capabilities = make_intrusive(zeek::BifType::Record::SMB1::NegotiateCapabilities); capabilities->Assign(0, val_mgr->Bool(${val.ntlm.capabilities_raw_mode})); capabilities->Assign(1, val_mgr->Bool(${val.ntlm.capabilities_mpx_mode})); capabilities->Assign(2, val_mgr->Bool(${val.ntlm.capabilities_unicode})); @@ -108,7 +108,7 @@ refine connection SMB_Conn += { capabilities->Assign(16, val_mgr->Bool(${val.ntlm.capabilities_compressed_data})); capabilities->Assign(17, val_mgr->Bool(${val.ntlm.capabilities_extended_security})); - auto ntlm = make_intrusive(BifType::Record::SMB1::NegotiateResponseNTLM); + auto ntlm = make_intrusive(zeek::BifType::Record::SMB1::NegotiateResponseNTLM); ntlm->Assign(0, val_mgr->Count(${val.word_count})); ntlm->Assign(1, val_mgr->Count(${val.dialect_index})); ntlm->Assign(2, std::move(security)); diff --git a/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac b/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac index f6dddc345e..f5d2628e26 100644 --- a/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac @@ -12,7 +12,7 @@ refine connection SMB_Conn += { %{ if ( smb1_session_setup_andx_request ) { - auto request = make_intrusive(BifType::Record::SMB1::SessionSetupAndXRequest); + auto request = make_intrusive(zeek::BifType::Record::SMB1::SessionSetupAndXRequest); request->Assign(0, val_mgr->Count(${val.word_count})); switch ( ${val.word_count} ) { @@ -31,7 +31,7 @@ refine connection SMB_Conn += { break; case 12: // NT LM 0.12 with extended security { - auto capabilities = make_intrusive(BifType::Record::SMB1::SessionSetupAndXCapabilities); + auto capabilities = make_intrusive(zeek::BifType::Record::SMB1::SessionSetupAndXCapabilities); capabilities->Assign(0, val_mgr->Bool(${val.ntlm_extended_security.capabilities.unicode})); capabilities->Assign(1, val_mgr->Bool(${val.ntlm_extended_security.capabilities.large_files})); capabilities->Assign(2, val_mgr->Bool(${val.ntlm_extended_security.capabilities.nt_smbs})); @@ -53,7 +53,7 @@ refine connection SMB_Conn += { case 13: // NT LM 0.12 without extended security { - auto capabilities = make_intrusive(BifType::Record::SMB1::SessionSetupAndXCapabilities); + auto capabilities = make_intrusive(zeek::BifType::Record::SMB1::SessionSetupAndXCapabilities); capabilities->Assign(0, val_mgr->Bool(${val.ntlm_nonextended_security.capabilities.unicode})); capabilities->Assign(1, val_mgr->Bool(${val.ntlm_nonextended_security.capabilities.large_files})); capabilities->Assign(2, val_mgr->Bool(${val.ntlm_nonextended_security.capabilities.nt_smbs})); @@ -90,7 +90,7 @@ refine connection SMB_Conn += { %{ if ( smb1_session_setup_andx_response ) { - auto response = make_intrusive(BifType::Record::SMB1::SessionSetupAndXResponse); + auto response = make_intrusive(zeek::BifType::Record::SMB1::SessionSetupAndXResponse); response->Assign(0, val_mgr->Count(${val.word_count})); switch ( ${val.word_count} ) diff --git a/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac b/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac index 80af3dfe6b..a065d6ac9d 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac @@ -5,7 +5,7 @@ refine connection SMB_Conn += { if ( ! smb1_transaction_secondary_request ) return false; - auto args = make_intrusive(BifType::Record::SMB1::Trans_Sec_Args); + auto args = make_intrusive(zeek::BifType::Record::SMB1::Trans_Sec_Args); args->Assign(0, val_mgr->Count(${val.total_param_count})); args->Assign(1, val_mgr->Count(${val.total_data_count})); args->Assign(2, val_mgr->Count(${val.param_count})); diff --git a/src/analyzer/protocol/smb/smb1-com-transaction2-secondary.pac b/src/analyzer/protocol/smb/smb1-com-transaction2-secondary.pac index 3c41139935..3ecd1f65c8 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction2-secondary.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction2-secondary.pac @@ -5,7 +5,7 @@ refine connection SMB_Conn += { if ( ! smb1_transaction2_secondary_request ) return false; - auto args = make_intrusive(BifType::Record::SMB1::Trans2_Sec_Args); + auto args = make_intrusive(zeek::BifType::Record::SMB1::Trans2_Sec_Args); args->Assign(0, val_mgr->Count(${val.total_param_count})); args->Assign(1, val_mgr->Count(${val.total_data_count})); args->Assign(2, val_mgr->Count(${val.param_count})); diff --git a/src/analyzer/protocol/smb/smb1-com-transaction2.pac b/src/analyzer/protocol/smb/smb1-com-transaction2.pac index b360c25798..491d06d06c 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction2.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction2.pac @@ -24,7 +24,7 @@ refine connection SMB_Conn += { %{ if ( smb1_transaction2_request ) { - auto args = make_intrusive(BifType::Record::SMB1::Trans2_Args); + auto args = make_intrusive(zeek::BifType::Record::SMB1::Trans2_Args); args->Assign(0, val_mgr->Count(${val.total_param_count})); args->Assign(1, val_mgr->Count(${val.total_data_count})); args->Assign(2, val_mgr->Count(${val.max_param_count})); @@ -131,7 +131,7 @@ refine connection SMB_Conn += { %{ if ( smb1_trans2_find_first2_request ) { - auto result = make_intrusive(BifType::Record::SMB1::Find_First2_Request_Args); + auto result = make_intrusive(zeek::BifType::Record::SMB1::Find_First2_Request_Args); result->Assign(0, val_mgr->Count(${val.search_attrs})); result->Assign(1, val_mgr->Count(${val.search_count})); result->Assign(2, val_mgr->Count(${val.flags})); diff --git a/src/analyzer/protocol/smb/smb1-protocol.pac b/src/analyzer/protocol/smb/smb1-protocol.pac index 8e19fcbe57..bafb427f5f 100644 --- a/src/analyzer/protocol/smb/smb1-protocol.pac +++ b/src/analyzer/protocol/smb/smb1-protocol.pac @@ -9,7 +9,7 @@ %code{ IntrusivePtr SMBHeaderVal(SMB_Header* hdr) { - auto r = make_intrusive(BifType::Record::SMB1::Header); + auto r = make_intrusive(zeek::BifType::Record::SMB1::Header); //unsigned int status = 0; // diff --git a/src/analyzer/protocol/smb/smb2-com-close.pac b/src/analyzer/protocol/smb/smb2-com-close.pac index 2a4c7baa41..be049dd5d2 100644 --- a/src/analyzer/protocol/smb/smb2-com-close.pac +++ b/src/analyzer/protocol/smb/smb2-com-close.pac @@ -20,7 +20,7 @@ refine connection SMB_Conn += { %{ if ( smb2_close_response ) { - auto resp = make_intrusive(BifType::Record::SMB2::CloseResponse); + auto resp = make_intrusive(zeek::BifType::Record::SMB2::CloseResponse); resp->Assign(0, val_mgr->Count(${val.alloc_size})); resp->Assign(1, val_mgr->Count(${val.eof})); diff --git a/src/analyzer/protocol/smb/smb2-com-create.pac b/src/analyzer/protocol/smb/smb2-com-create.pac index ce4178ad95..c8f8682b33 100644 --- a/src/analyzer/protocol/smb/smb2-com-create.pac +++ b/src/analyzer/protocol/smb/smb2-com-create.pac @@ -16,7 +16,7 @@ refine connection SMB_Conn += { if ( smb2_create_request ) { - auto requestinfo = make_intrusive(BifType::Record::SMB2::CreateRequest); + auto requestinfo = make_intrusive(zeek::BifType::Record::SMB2::CreateRequest); requestinfo->Assign(0, std::move(filename)); requestinfo->Assign(1, val_mgr->Count(${val.disposition})); requestinfo->Assign(2, val_mgr->Count(${val.create_options})); @@ -33,7 +33,7 @@ refine connection SMB_Conn += { %{ if ( smb2_create_response ) { - auto responseinfo = make_intrusive(BifType::Record::SMB2::CreateResponse); + auto responseinfo = make_intrusive(zeek::BifType::Record::SMB2::CreateResponse); responseinfo->Assign(0, BuildSMB2GUID(${val.file_id})); responseinfo->Assign(1, val_mgr->Count(${val.eof})); responseinfo->Assign(2, SMB_BuildMACTimes(${val.last_write_time}, diff --git a/src/analyzer/protocol/smb/smb2-com-negotiate.pac b/src/analyzer/protocol/smb/smb2-com-negotiate.pac index 7f6e42c60f..024f25b76f 100644 --- a/src/analyzer/protocol/smb/smb2-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb2-com-negotiate.pac @@ -39,7 +39,7 @@ refine connection SMB_Conn += { %{ if ( smb2_negotiate_response ) { - auto nr = make_intrusive(BifType::Record::SMB2::NegotiateResponse); + auto nr = make_intrusive(zeek::BifType::Record::SMB2::NegotiateResponse); nr->Assign(0, val_mgr->Count(${val.dialect_revision})); nr->Assign(1, val_mgr->Count(${val.security_mode})); @@ -48,7 +48,7 @@ refine connection SMB_Conn += { nr->Assign(4, filetime2brotime(${val.server_start_time})); nr->Assign(5, val_mgr->Count(${val.negotiate_context_count})); - auto cv = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::SMB2::NegotiateContextValues}); + auto cv = make_intrusive(zeek::BifType::Vector::SMB2::NegotiateContextValues); if ( ${val.dialect_revision} == 0x0311 && ${val.negotiate_context_count} > 0 ) { diff --git a/src/analyzer/protocol/smb/smb2-com-session-setup.pac b/src/analyzer/protocol/smb/smb2-com-session-setup.pac index 1f38fe1fb2..edd380790e 100644 --- a/src/analyzer/protocol/smb/smb2-com-session-setup.pac +++ b/src/analyzer/protocol/smb/smb2-com-session-setup.pac @@ -4,7 +4,7 @@ refine connection SMB_Conn += { %{ if ( smb2_session_setup_request ) { - auto req = make_intrusive(BifType::Record::SMB2::SessionSetupRequest); + auto req = make_intrusive(zeek::BifType::Record::SMB2::SessionSetupRequest); req->Assign(0, val_mgr->Count(${val.security_mode})); BifEvent::enqueue_smb2_session_setup_request(bro_analyzer(), @@ -20,12 +20,12 @@ refine connection SMB_Conn += { %{ if ( smb2_session_setup_response ) { - auto flags = make_intrusive(BifType::Record::SMB2::SessionSetupFlags); + auto flags = make_intrusive(zeek::BifType::Record::SMB2::SessionSetupFlags); flags->Assign(0, val_mgr->Bool(${val.flag_guest})); flags->Assign(1, val_mgr->Bool(${val.flag_anonymous})); flags->Assign(2, val_mgr->Bool(${val.flag_encrypt})); - auto resp = make_intrusive(BifType::Record::SMB2::SessionSetupResponse); + auto resp = make_intrusive(zeek::BifType::Record::SMB2::SessionSetupResponse); resp->Assign(0, std::move(flags)); BifEvent::enqueue_smb2_session_setup_response(bro_analyzer(), diff --git a/src/analyzer/protocol/smb/smb2-com-set-info.pac b/src/analyzer/protocol/smb/smb2-com-set-info.pac index 9f13d9b91a..daee89cb70 100644 --- a/src/analyzer/protocol/smb/smb2-com-set-info.pac +++ b/src/analyzer/protocol/smb/smb2-com-set-info.pac @@ -93,11 +93,11 @@ refine connection SMB_Conn += { %{ if ( smb2_file_fullea ) { - auto eas = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::SMB2::FileEAs}); + auto eas = make_intrusive(zeek::BifType::Vector::SMB2::FileEAs); for ( auto i = 0u; i < ${val.ea_vector}->size(); ++i ) { - auto r = make_intrusive(BifType::Record::SMB2::FileEA); + auto r = make_intrusive(zeek::BifType::Record::SMB2::FileEA); r->Assign(0, smb2_string2stringval(${val.ea_vector[i].ea_name})); r->Assign(1, smb2_string2stringval(${val.ea_vector[i].ea_value})); @@ -192,7 +192,7 @@ refine connection SMB_Conn += { %{ if ( smb2_file_fscontrol ) { - auto r = make_intrusive(BifType::Record::SMB2::Fscontrol); + auto r = make_intrusive(zeek::BifType::Record::SMB2::Fscontrol); r->Assign(0, val_mgr->Int(${val.free_space_start_filtering})); r->Assign(1, val_mgr->Int(${val.free_space_start_threshold})); r->Assign(2, val_mgr->Int(${val.free_space_stop_filtering})); diff --git a/src/analyzer/protocol/smb/smb2-com-transform-header.pac b/src/analyzer/protocol/smb/smb2-com-transform-header.pac index c9629fa842..fb546afe1d 100644 --- a/src/analyzer/protocol/smb/smb2-com-transform-header.pac +++ b/src/analyzer/protocol/smb/smb2-com-transform-header.pac @@ -4,7 +4,7 @@ refine connection SMB_Conn += { %{ if ( smb2_transform_header ) { - auto r = make_intrusive(BifType::Record::SMB2::Transform_header); + auto r = make_intrusive(zeek::BifType::Record::SMB2::Transform_header); r->Assign(0, to_stringval(${hdr.signature})); r->Assign(1, to_stringval(${hdr.nonce})); r->Assign(2, val_mgr->Count(${hdr.orig_msg_size})); diff --git a/src/analyzer/protocol/smb/smb2-com-tree-connect.pac b/src/analyzer/protocol/smb/smb2-com-tree-connect.pac index 68449d999f..7ad9516a7f 100644 --- a/src/analyzer/protocol/smb/smb2-com-tree-connect.pac +++ b/src/analyzer/protocol/smb/smb2-com-tree-connect.pac @@ -18,7 +18,7 @@ refine connection SMB_Conn += { if ( smb2_tree_connect_response ) { - auto resp = make_intrusive(BifType::Record::SMB2::TreeConnectResponse); + auto resp = make_intrusive(zeek::BifType::Record::SMB2::TreeConnectResponse); resp->Assign(0, val_mgr->Count(${val.share_type})); BifEvent::enqueue_smb2_tree_connect_response(bro_analyzer(), diff --git a/src/analyzer/protocol/smb/smb2-protocol.pac b/src/analyzer/protocol/smb/smb2-protocol.pac index 7c774d2f31..13ec2c4062 100644 --- a/src/analyzer/protocol/smb/smb2-protocol.pac +++ b/src/analyzer/protocol/smb/smb2-protocol.pac @@ -11,7 +11,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv); %code{ IntrusivePtr BuildSMB2HeaderVal(SMB2_Header* hdr) { - auto r = make_intrusive(BifType::Record::SMB2::Header); + auto r = make_intrusive(zeek::BifType::Record::SMB2::Header); r->Assign(0, val_mgr->Count(${hdr.credit_charge})); r->Assign(1, val_mgr->Count(${hdr.status})); r->Assign(2, val_mgr->Count(${hdr.command})); @@ -27,7 +27,7 @@ IntrusivePtr BuildSMB2HeaderVal(SMB2_Header* hdr) IntrusivePtr BuildSMB2GUID(SMB2_guid* file_id) { - auto r = make_intrusive(BifType::Record::SMB2::GUID); + auto r = make_intrusive(zeek::BifType::Record::SMB2::GUID); r->Assign(0, val_mgr->Count(${file_id.persistent})); r->Assign(1, val_mgr->Count(${file_id._volatile})); return r; @@ -35,7 +35,7 @@ IntrusivePtr BuildSMB2GUID(SMB2_guid* file_id) IntrusivePtr smb2_file_attrs_to_bro(SMB2_file_attributes* val) { - auto r = make_intrusive(BifType::Record::SMB2::FileAttrs); + auto r = make_intrusive(zeek::BifType::Record::SMB2::FileAttrs); r->Assign(0, val_mgr->Bool(${val.read_only})); r->Assign(1, val_mgr->Bool(${val.hidden})); r->Assign(2, val_mgr->Bool(${val.system})); @@ -56,7 +56,7 @@ IntrusivePtr smb2_file_attrs_to_bro(SMB2_file_attributes* val) IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) { - auto r = make_intrusive(BifType::Record::SMB2::NegotiateContextValue); + auto r = make_intrusive(zeek::BifType::Record::SMB2::NegotiateContextValue); r->Assign(0, val_mgr->Count(${ncv.context_type})); r->Assign(1, val_mgr->Count(${ncv.data_length})); @@ -64,7 +64,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) switch ( ${ncv.context_type} ) { case SMB2_PREAUTH_INTEGRITY_CAPABILITIES: { - auto rpreauth = make_intrusive(BifType::Record::SMB2::PreAuthIntegrityCapabilities); + auto rpreauth = make_intrusive(zeek::BifType::Record::SMB2::PreAuthIntegrityCapabilities); rpreauth->Assign(0, val_mgr->Count(${ncv.preauth_integrity_capabilities.hash_alg_count})); rpreauth->Assign(1, val_mgr->Count(${ncv.preauth_integrity_capabilities.salt_length})); @@ -84,7 +84,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) case SMB2_ENCRYPTION_CAPABILITIES: { - auto rencr = make_intrusive(BifType::Record::SMB2::EncryptionCapabilities); + auto rencr = make_intrusive(zeek::BifType::Record::SMB2::EncryptionCapabilities); rencr->Assign(0, val_mgr->Count(${ncv.encryption_capabilities.cipher_count})); auto c = make_intrusive(zeek::id::index_vec); @@ -102,7 +102,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) case SMB2_COMPRESSION_CAPABILITIES: { - auto rcomp = make_intrusive(BifType::Record::SMB2::CompressionCapabilities); + auto rcomp = make_intrusive(zeek::BifType::Record::SMB2::CompressionCapabilities); rcomp->Assign(0, val_mgr->Count(${ncv.compression_capabilities.alg_count})); auto c = make_intrusive(zeek::id::index_vec); diff --git a/src/analyzer/protocol/snmp/snmp-analyzer.pac b/src/analyzer/protocol/snmp/snmp-analyzer.pac index 0fa56d3c2f..a8c5b07b52 100644 --- a/src/analyzer/protocol/snmp/snmp-analyzer.pac +++ b/src/analyzer/protocol/snmp/snmp-analyzer.pac @@ -44,7 +44,7 @@ AddrVal* network_address_to_val(const ASN1Encoding* na) Val* asn1_obj_to_val(const ASN1Encoding* obj) { - RecordVal* rval = new RecordVal(BifType::Record::SNMP::ObjectValue); + RecordVal* rval = new RecordVal(zeek::BifType::Record::SNMP::ObjectValue); uint8 tag = obj->meta()->tag(); rval->Assign(0, val_mgr->Count(tag)); @@ -92,13 +92,13 @@ Val* time_ticks_to_val(const TimeTicks* tt) IntrusivePtr build_hdr(const Header* header) { - auto rv = make_intrusive(BifType::Record::SNMP::Header); + auto rv = make_intrusive(zeek::BifType::Record::SNMP::Header); rv->Assign(0, val_mgr->Count(header->version())); switch ( header->version() ) { case SNMPV1_TAG: { - RecordVal* v1 = new RecordVal(BifType::Record::SNMP::HeaderV1); + RecordVal* v1 = new RecordVal(zeek::BifType::Record::SNMP::HeaderV1); v1->Assign(0, asn1_octet_string_to_val(header->v1()->community())); rv->Assign(1, v1); } @@ -106,7 +106,7 @@ IntrusivePtr build_hdr(const Header* header) case SNMPV2_TAG: { - RecordVal* v2 = new RecordVal(BifType::Record::SNMP::HeaderV2); + RecordVal* v2 = new RecordVal(zeek::BifType::Record::SNMP::HeaderV2); v2->Assign(0, asn1_octet_string_to_val(header->v2()->community())); rv->Assign(2, v2); } @@ -124,7 +124,7 @@ IntrusivePtr build_hdr(const Header* header) RecordVal* build_hdrV3(const Header* header) { - RecordVal* v3 = new RecordVal(BifType::Record::SNMP::HeaderV3); + RecordVal* v3 = new RecordVal(zeek::BifType::Record::SNMP::HeaderV3); const v3Header* v3hdr = header->v3(); const v3HeaderData* global_data = v3hdr->global_data(); bytestring const& flags = global_data->flags()->encoding()->content(); @@ -144,7 +144,7 @@ RecordVal* build_hdrV3(const Header* header) if ( v3hdr->next()->tag() == ASN1_SEQUENCE_TAG ) { const v3ScopedPDU* spdu = v3hdr->plaintext_pdu(); - RecordVal* rv = new RecordVal(BifType::Record::SNMP::ScopedPDU_Context); + RecordVal* rv = new RecordVal(zeek::BifType::Record::SNMP::ScopedPDU_Context); rv->Assign(0, asn1_octet_string_to_val(spdu->context_engine_id())); rv->Assign(1, asn1_octet_string_to_val(spdu->context_name())); v3->Assign(8, rv); @@ -155,12 +155,12 @@ RecordVal* build_hdrV3(const Header* header) VectorVal* build_bindings(const VarBindList* vbl) { - auto vv = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::SNMP::Bindings}); + auto vv = make_intrusive(zeek::BifType::Vector::SNMP::Bindings); for ( size_t i = 0; i < vbl->bindings()->size(); ++i ) { VarBind* vb = (*vbl->bindings())[i]; - RecordVal* binding = new RecordVal(BifType::Record::SNMP::Binding); + RecordVal* binding = new RecordVal(zeek::BifType::Record::SNMP::Binding); binding->Assign(0, asn1_oid_to_val(vb->name()->oid())); binding->Assign(1, asn1_obj_to_val(vb->value()->encoding())); vv->Assign(i, binding); @@ -171,7 +171,7 @@ VectorVal* build_bindings(const VarBindList* vbl) IntrusivePtr build_pdu(const CommonPDU* pdu) { - auto rv = make_intrusive(BifType::Record::SNMP::PDU); + auto rv = make_intrusive(zeek::BifType::Record::SNMP::PDU); rv->Assign(0, asn1_integer_to_val(pdu->request_id(), TYPE_INT)); rv->Assign(1, asn1_integer_to_val(pdu->error_status(), TYPE_INT)); rv->Assign(2, asn1_integer_to_val(pdu->error_index(), TYPE_INT)); @@ -181,7 +181,7 @@ IntrusivePtr build_pdu(const CommonPDU* pdu) IntrusivePtr build_trap_pdu(const TrapPDU* pdu) { - auto rv = make_intrusive(BifType::Record::SNMP::TrapPDU); + auto rv = make_intrusive(zeek::BifType::Record::SNMP::TrapPDU); rv->Assign(0, asn1_oid_to_val(pdu->enterprise())); rv->Assign(1, network_address_to_val(pdu->agent_addr())); rv->Assign(2, asn1_integer_to_val(pdu->generic_trap(), TYPE_INT)); @@ -193,7 +193,7 @@ IntrusivePtr build_trap_pdu(const TrapPDU* pdu) IntrusivePtr build_bulk_pdu(const GetBulkRequestPDU* pdu) { - auto rv = make_intrusive(BifType::Record::SNMP::BulkPDU); + auto rv = make_intrusive(zeek::BifType::Record::SNMP::BulkPDU); rv->Assign(0, asn1_integer_to_val(pdu->request_id(), TYPE_INT)); rv->Assign(1, asn1_integer_to_val(pdu->non_repeaters(), TYPE_COUNT)); rv->Assign(2, asn1_integer_to_val(pdu->max_repititions(), TYPE_COUNT)); diff --git a/src/analyzer/protocol/ssh/ssh-analyzer.pac b/src/analyzer/protocol/ssh/ssh-analyzer.pac index da8c875882..0845e41efa 100644 --- a/src/analyzer/protocol/ssh/ssh-analyzer.pac +++ b/src/analyzer/protocol/ssh/ssh-analyzer.pac @@ -70,28 +70,28 @@ refine flow SSH_Flow += { if ( ! ssh_capabilities ) return false; - auto result = make_intrusive(BifType::Record::SSH::Capabilities); + auto result = make_intrusive(zeek::BifType::Record::SSH::Capabilities); result->Assign(0, name_list_to_vector(${msg.kex_algorithms.val})); result->Assign(1, name_list_to_vector(${msg.server_host_key_algorithms.val})); - RecordVal* encryption_algs = new RecordVal(BifType::Record::SSH::Algorithm_Prefs); + RecordVal* encryption_algs = new RecordVal(zeek::BifType::Record::SSH::Algorithm_Prefs); encryption_algs->Assign(0, name_list_to_vector(${msg.encryption_algorithms_client_to_server.val})); encryption_algs->Assign(1, name_list_to_vector(${msg.encryption_algorithms_server_to_client.val})); result->Assign(2, encryption_algs); - RecordVal* mac_algs = new RecordVal(BifType::Record::SSH::Algorithm_Prefs); + RecordVal* mac_algs = new RecordVal(zeek::BifType::Record::SSH::Algorithm_Prefs); mac_algs->Assign(0, name_list_to_vector(${msg.mac_algorithms_client_to_server.val})); mac_algs->Assign(1, name_list_to_vector(${msg.mac_algorithms_server_to_client.val})); result->Assign(3, mac_algs); - RecordVal* compression_algs = new RecordVal(BifType::Record::SSH::Algorithm_Prefs); + RecordVal* compression_algs = new RecordVal(zeek::BifType::Record::SSH::Algorithm_Prefs); compression_algs->Assign(0, name_list_to_vector(${msg.compression_algorithms_client_to_server.val})); compression_algs->Assign(1, name_list_to_vector(${msg.compression_algorithms_server_to_client.val})); result->Assign(4, compression_algs); if ( ${msg.languages_client_to_server.len} || ${msg.languages_server_to_client.len} ) { - RecordVal* languages = new RecordVal(BifType::Record::SSH::Algorithm_Prefs); + RecordVal* languages = new RecordVal(zeek::BifType::Record::SSH::Algorithm_Prefs); if ( ${msg.languages_client_to_server.len} ) languages->Assign(0, name_list_to_vector(${msg.languages_client_to_server.val})); if ( ${msg.languages_server_to_client.len} ) diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index 2dc919bbaf..a08d94203b 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -161,7 +161,7 @@ refine connection Handshake_Conn += { { for ( unsigned int i = 0; i < supported_signature_algorithms->size(); ++i ) { - RecordVal* el = new RecordVal(BifType::Record::SSL::SignatureAndHashAlgorithm); + RecordVal* el = new RecordVal(zeek::BifType::Record::SSL::SignatureAndHashAlgorithm); el->Assign(0, val_mgr->Count((*supported_signature_algorithms)[i]->HashAlgorithm())); el->Assign(1, val_mgr->Count((*supported_signature_algorithms)[i]->SignatureAlgorithm())); slist->Assign(i, el); @@ -342,7 +342,7 @@ refine connection Handshake_Conn += { if ( ssl_server_signature ) { - auto ha = make_intrusive(BifType::Record::SSL::SignatureAndHashAlgorithm); + auto ha = make_intrusive(zeek::BifType::Record::SSL::SignatureAndHashAlgorithm); if ( ${kex.signed_params.uses_signature_and_hashalgorithm} ) { @@ -414,7 +414,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_signed_certificate_timestamp ) return true; - auto ha = make_intrusive(BifType::Record::SSL::SignatureAndHashAlgorithm); + auto ha = make_intrusive(zeek::BifType::Record::SSL::SignatureAndHashAlgorithm); ha->Assign(0, val_mgr->Count(digitally_signed_algorithms->HashAlgorithm())); ha->Assign(1, val_mgr->Count(digitally_signed_algorithms->SignatureAlgorithm())); @@ -442,7 +442,7 @@ refine connection Handshake_Conn += { if ( ssl_server_signature ) { - auto ha = make_intrusive(BifType::Record::SSL::SignatureAndHashAlgorithm); + auto ha = make_intrusive(zeek::BifType::Record::SSL::SignatureAndHashAlgorithm); if ( ${signed_params.uses_signature_and_hashalgorithm} ) { @@ -498,7 +498,7 @@ refine connection Handshake_Conn += { { for ( auto&& identity : *(identities->identities()) ) { - RecordVal* el = new RecordVal(BifType::Record::SSL::PSKIdentity); + RecordVal* el = new RecordVal(zeek::BifType::Record::SSL::PSKIdentity); el->Assign(0, make_intrusive(identity->identity().length(), (const char*) identity->identity().data())); el->Assign(1, val_mgr->Count(identity->obfuscated_ticket_age())); slist->Assign(slist->Size(), el); diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index fc13e50848..3522439cce 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -1356,7 +1356,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) if ( tcp_options ) { - auto option_list = make_intrusive(IntrusivePtr{NewRef{}, BifType::Vector::TCP::OptionList}); + auto option_list = make_intrusive(zeek::BifType::Vector::TCP::OptionList); auto add_option_data = [](RecordVal* rv, const u_char* odata, int olen) { @@ -1372,7 +1372,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) { auto kind = o[0]; auto length = kind < 2 ? 1 : o[1]; - auto option_record = new RecordVal(BifType::Record::TCP::Option); + auto option_record = new RecordVal(zeek::BifType::Record::TCP::Option); option_list->Assign(option_list->Size(), option_record); option_record->Assign(0, val_mgr->Count(kind)); option_record->Assign(1, val_mgr->Count(length)); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 24f6d55822..b2fa59152d 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -1016,7 +1016,7 @@ broker::expected bro_broker::val_to_data(const Val* v) IntrusivePtr bro_broker::make_data_val(Val* v) { - auto rval = make_intrusive(BifType::Record::Broker::Data); + auto rval = make_intrusive(zeek::BifType::Record::Broker::Data); auto data = val_to_data(v); if ( data ) @@ -1029,7 +1029,7 @@ IntrusivePtr bro_broker::make_data_val(Val* v) IntrusivePtr bro_broker::make_data_val(broker::data d) { - auto rval = make_intrusive(BifType::Record::Broker::Data); + auto rval = make_intrusive(zeek::BifType::Record::Broker::Data); rval->Assign(0, make_intrusive(move(d))); return rval; } @@ -1039,72 +1039,72 @@ struct data_type_getter { result_type operator()(broker::none) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::NONE); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::NONE); } result_type operator()(bool) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::BOOL); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::BOOL); } result_type operator()(uint64_t) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::COUNT); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::COUNT); } result_type operator()(int64_t) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::INT); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::INT); } result_type operator()(double) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::DOUBLE); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::DOUBLE); } result_type operator()(const std::string&) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::STRING); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::STRING); } result_type operator()(const broker::address&) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::ADDR); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::ADDR); } result_type operator()(const broker::subnet&) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::SUBNET); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::SUBNET); } result_type operator()(const broker::port&) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::PORT); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::PORT); } result_type operator()(const broker::timestamp&) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::TIME); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::TIME); } result_type operator()(const broker::timespan&) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::INTERVAL); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::INTERVAL); } result_type operator()(const broker::enum_value&) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::ENUM); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::ENUM); } result_type operator()(const broker::set&) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::SET); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::SET); } result_type operator()(const broker::table&) { - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::TABLE); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::TABLE); } result_type operator()(const broker::vector&) @@ -1112,7 +1112,7 @@ struct data_type_getter { // Note that Broker uses vectors to store record data, so there's // no actual way to tell if this data was originally associated // with a Bro record. - return BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::VECTOR); + return zeek::BifType::Enum::Broker::DataType->GetVal(BifEnum::Broker::VECTOR); } }; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 9d7cc5f324..ac90d2a342 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -699,7 +699,7 @@ bool Manager::AutoUnpublishEvent(const string& topic, Val* event) RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) { - auto rval = new RecordVal(BifType::Record::Broker::Event); + auto rval = new RecordVal(zeek::BifType::Record::Broker::Event); auto arg_vec = make_intrusive(vector_of_data_type); rval->Assign(1, arg_vec); Func* func = nullptr; @@ -1351,7 +1351,7 @@ void Manager::ProcessError(broker::error err) } mgr.Enqueue(Broker::error, - BifType::Enum::Broker::ErrorCode->GetVal(ec), + zeek::BifType::Enum::Broker::ErrorCode->GetVal(ec), make_intrusive(msg) ); } diff --git a/src/broker/Store.h b/src/broker/Store.h index 09799c8c68..b439d39e0f 100644 --- a/src/broker/Store.h +++ b/src/broker/Store.h @@ -26,9 +26,9 @@ EnumVal* query_status(bool success); */ inline IntrusivePtr query_result() { - auto rval = make_intrusive(BifType::Record::Broker::QueryResult); + auto rval = make_intrusive(zeek::BifType::Record::Broker::QueryResult); rval->Assign(0, query_status(false)); - rval->Assign(1, make_intrusive(BifType::Record::Broker::Data)); + rval->Assign(1, make_intrusive(zeek::BifType::Record::Broker::Data)); return rval; } @@ -39,7 +39,7 @@ inline IntrusivePtr query_result() */ inline IntrusivePtr query_result(IntrusivePtr data) { - auto rval = make_intrusive(BifType::Record::Broker::QueryResult); + auto rval = make_intrusive(zeek::BifType::Record::Broker::QueryResult); rval->Assign(0, query_status(true)); rval->Assign(1, std::move(data)); return rval; diff --git a/src/broker/comm.bif b/src/broker/comm.bif index 71a36b44b3..77f29830af 100644 --- a/src/broker/comm.bif +++ b/src/broker/comm.bif @@ -123,7 +123,7 @@ function Broker::__peers%(%): PeerInfos auto ps = (BifEnum::Broker::PeerStatus)p.status; peer_info->Assign(0, endpoint_info); - peer_info->Assign(1, BifType::Enum::Broker::PeerStatus->GetVal(ps)); + peer_info->Assign(1, zeek::BifType::Enum::Broker::PeerStatus->GetVal(ps)); rval->Assign(i, peer_info); ++i; diff --git a/src/broker/data.bif b/src/broker/data.bif index c7a7840d30..167cc9ab48 100644 --- a/src/broker/data.bif +++ b/src/broker/data.bif @@ -146,7 +146,7 @@ function Broker::__set_iterator_next%(it: opaque of Broker::SetIterator%): bool function Broker::__set_iterator_value%(it: opaque of Broker::SetIterator%): Broker::Data %{ auto set_it = static_cast(it); - auto rval = make_intrusive(BifType::Record::Broker::Data); + auto rval = make_intrusive(zeek::BifType::Record::Broker::Data); if ( set_it->it == set_it->dat.end() ) { @@ -204,7 +204,7 @@ function Broker::__table_insert%(t: Broker::Data, key: any, val: any%): Broker:: if ( ! k ) { builtin_error("invalid Broker data conversion for key argument"); - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); } auto v = bro_broker::val_to_data(val); @@ -212,7 +212,7 @@ function Broker::__table_insert%(t: Broker::Data, key: any, val: any%): Broker:: if ( ! v ) { builtin_error("invalid Broker data conversion for value argument"); - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); } try @@ -225,7 +225,7 @@ function Broker::__table_insert%(t: Broker::Data, key: any, val: any%): Broker:: catch (const std::out_of_range&) { table[std::move(*k)] = std::move(*v); - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); } %} @@ -239,13 +239,13 @@ function Broker::__table_remove%(t: Broker::Data, key: any%): Broker::Data if ( ! k ) { builtin_error("invalid Broker data conversion for key argument"); - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); } auto it = table.find(*k); if ( it == table.end() ) - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); else { auto rval = bro_broker::make_data_val(move(it->second)); @@ -264,13 +264,13 @@ function Broker::__table_lookup%(t: Broker::Data, key: any%): Broker::Data if ( ! k ) { builtin_error("invalid Broker data conversion for key argument"); - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); } auto it = table.find(*k); if ( it == table.end() ) - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); else return bro_broker::make_data_val(it->second); %} @@ -300,9 +300,9 @@ function Broker::__table_iterator_next%(it: opaque of Broker::TableIterator%): b function Broker::__table_iterator_value%(it: opaque of Broker::TableIterator%): Broker::TableItem %{ auto ti = static_cast(it); - auto rval = make_intrusive(BifType::Record::Broker::TableItem); - auto key_val = new RecordVal(BifType::Record::Broker::Data); - auto val_val = new RecordVal(BifType::Record::Broker::Data); + auto rval = make_intrusive(zeek::BifType::Record::Broker::TableItem); + auto key_val = new RecordVal(zeek::BifType::Record::Broker::Data); + auto val_val = new RecordVal(zeek::BifType::Record::Broker::Data); rval->Assign(0, key_val); rval->Assign(1, val_val); @@ -367,7 +367,7 @@ function Broker::__vector_replace%(v: Broker::Data, idx: count, d: any%): Broker } if ( idx >= vec.size() ) - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); auto rval = bro_broker::make_data_val(move(vec[idx])); vec[idx] = std::move(*item); @@ -380,7 +380,7 @@ function Broker::__vector_remove%(v: Broker::Data, idx: count%): Broker::Data TYPE_VECTOR, frame); if ( idx >= vec.size() ) - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); auto rval = bro_broker::make_data_val(move(vec[idx])); vec.erase(vec.begin() + idx); @@ -393,7 +393,7 @@ function Broker::__vector_lookup%(v: Broker::Data, idx: count%): Broker::Data TYPE_VECTOR, frame); if ( idx >= vec.size() ) - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); return bro_broker::make_data_val(vec[idx]); %} @@ -423,7 +423,7 @@ function Broker::__vector_iterator_next%(it: opaque of Broker::VectorIterator%): function Broker::__vector_iterator_value%(it: opaque of Broker::VectorIterator%): Broker::Data %{ auto vi = static_cast(it); - auto rval = make_intrusive(BifType::Record::Broker::Data); + auto rval = make_intrusive(zeek::BifType::Record::Broker::Data); if ( vi->it == vi->dat.end() ) { @@ -472,7 +472,7 @@ function Broker::__record_lookup%(r: Broker::Data, idx: count%): Broker::Data TYPE_RECORD, frame); if ( idx >= v.size() || caf::get_if(&v[idx]) ) - return make_intrusive(BifType::Record::Broker::Data); + return make_intrusive(zeek::BifType::Record::Broker::Data); return bro_broker::make_data_val(v[idx]); %} @@ -502,7 +502,7 @@ function Broker::__record_iterator_next%(it: opaque of Broker::RecordIterator%): function Broker::__record_iterator_value%(it: opaque of Broker::RecordIterator%): Broker::Data %{ auto ri = static_cast(it); - auto rval = make_intrusive(BifType::Record::Broker::Data); + auto rval = make_intrusive(zeek::BifType::Record::Broker::Data); if ( ri->it == ri->dat.end() ) { diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index 8c5c5eecc2..b2ca39f954 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -22,7 +22,7 @@ AnalyzerSet::AnalyzerSet(File* arg_file) : file(arg_file) { auto t = make_intrusive(); t->Append(file_mgr->GetTagType()); - t->Append({NewRef{}, BifType::Record::Files::AnalyzerArgs}); + t->Append(zeek::BifType::Record::Files::AnalyzerArgs); analyzer_hash = new CompositeHash(std::move(t)); analyzer_map.SetDeleteFunc(analyzer_del_func); } diff --git a/src/file_analysis/analyzer/extract/functions.bif b/src/file_analysis/analyzer/extract/functions.bif index 9b80700755..6d0ac3435d 100644 --- a/src/file_analysis/analyzer/extract/functions.bif +++ b/src/file_analysis/analyzer/extract/functions.bif @@ -10,8 +10,8 @@ module FileExtract; ## :zeek:see:`FileExtract::set_limit`. function FileExtract::__set_limit%(file_id: string, args: any, n: count%): bool %{ - using BifType::Record::Files::AnalyzerArgs; - auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs); + using zeek::BifType::Record::Files::AnalyzerArgs; + auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs.get()); bool result = file_mgr->SetExtractionLimit(file_id->CheckString(), rv.get(), n); return val_mgr->Bool(result); %} diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index 773dcb47c0..f0967dc5ba 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -42,7 +42,7 @@ refine flow File += { %{ if ( pe_dos_header ) { - auto dh = make_intrusive(BifType::Record::PE::DOSHeader); + auto dh = make_intrusive(zeek::BifType::Record::PE::DOSHeader); dh->Assign(0, make_intrusive(${h.signature}.length(), (const char*) ${h.signature}.data())); dh->Assign(1, val_mgr->Count(${h.UsedBytesInTheLastPage})); dh->Assign(2, val_mgr->Count(${h.FileSizeInPages})); @@ -92,7 +92,7 @@ refine flow File += { %{ if ( pe_file_header ) { - auto fh = make_intrusive(BifType::Record::PE::FileHeader); + auto fh = make_intrusive(zeek::BifType::Record::PE::FileHeader); fh->Assign(0, val_mgr->Count(${h.Machine})); fh->Assign(1, make_intrusive(static_cast(${h.TimeDateStamp}), TYPE_TIME)); fh->Assign(2, val_mgr->Count(${h.PointerToSymbolTable})); @@ -120,7 +120,7 @@ refine flow File += { if ( pe_optional_header ) { - auto oh = make_intrusive(BifType::Record::PE::OptionalHeader); + auto oh = make_intrusive(zeek::BifType::Record::PE::OptionalHeader); oh->Assign(0, val_mgr->Count(${h.magic})); oh->Assign(1, val_mgr->Count(${h.major_linker_version})); @@ -162,7 +162,7 @@ refine flow File += { %{ if ( pe_section_header ) { - auto section_header = make_intrusive(BifType::Record::PE::SectionHeader); + auto section_header = make_intrusive(zeek::BifType::Record::PE::SectionHeader); // Strip null characters from the end of the section name. u_char* first_null = (u_char*) memchr(${h.name}.data(), 0, ${h.name}.length()); diff --git a/src/file_analysis/analyzer/unified2/unified2-analyzer.pac b/src/file_analysis/analyzer/unified2/unified2-analyzer.pac index b2d46c89ed..58077f1635 100644 --- a/src/file_analysis/analyzer/unified2/unified2-analyzer.pac +++ b/src/file_analysis/analyzer/unified2/unified2-analyzer.pac @@ -66,7 +66,7 @@ refine flow Flow += { %{ if ( ::unified2_event ) { - auto ids_event = make_intrusive(BifType::Record::Unified2::IDSEvent); + auto ids_event = make_intrusive(zeek::BifType::Record::Unified2::IDSEvent); ids_event->Assign(0, val_mgr->Count(${ev.sensor_id})); ids_event->Assign(1, val_mgr->Count(${ev.event_id})); ids_event->Assign(2, make_intrusive(ts_to_double(${ev.ts}), TYPE_TIME)); @@ -92,7 +92,7 @@ refine flow Flow += { %{ if ( ::unified2_event ) { - auto ids_event = make_intrusive(BifType::Record::Unified2::IDSEvent); + auto ids_event = make_intrusive(zeek::BifType::Record::Unified2::IDSEvent); ids_event->Assign(0, val_mgr->Count(${ev.sensor_id})); ids_event->Assign(1, val_mgr->Count(${ev.event_id})); ids_event->Assign(2, make_intrusive(ts_to_double(${ev.ts}), TYPE_TIME)); @@ -123,7 +123,7 @@ refine flow Flow += { %{ if ( ::unified2_packet ) { - auto packet = make_intrusive(BifType::Record::Unified2::Packet); + auto packet = make_intrusive(zeek::BifType::Record::Unified2::Packet); packet->Assign(0, val_mgr->Count(${pkt.sensor_id})); packet->Assign(1, val_mgr->Count(${pkt.event_id})); packet->Assign(2, val_mgr->Count(${pkt.event_second})); diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index b7ddbecad1..a3c3e00136 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -117,7 +117,7 @@ IntrusivePtr file_analysis::X509::ParseCertificate(X509Val* cert_val, char buf[2048]; // we need a buffer for some of the openssl functions memset(buf, 0, sizeof(buf)); - auto pX509Cert = make_intrusive(BifType::Record::X509::Certificate); + auto pX509Cert = make_intrusive(zeek::BifType::Record::X509::Certificate); BIO *bio = BIO_new(BIO_s_mem()); pX509Cert->Assign(0, val_mgr->Count((uint64_t) X509_get_version(ssl_cert) + 1)); @@ -286,7 +286,7 @@ void file_analysis::X509::ParseBasicConstraints(X509_EXTENSION* ex) { if ( x509_ext_basic_constraints ) { - auto pBasicConstraint = make_intrusive(BifType::Record::X509::BasicConstraints); + auto pBasicConstraint = make_intrusive(zeek::BifType::Record::X509::BasicConstraints); pBasicConstraint->Assign(0, val_mgr->Bool(constr->ca)); if ( constr->pathlen ) @@ -417,7 +417,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) } } - auto sanExt = make_intrusive(BifType::Record::X509::SubjectAlternativeName); + auto sanExt = make_intrusive(zeek::BifType::Record::X509::SubjectAlternativeName); if ( names != nullptr ) sanExt->Assign(0, names); diff --git a/src/file_analysis/analyzer/x509/X509Common.cc b/src/file_analysis/analyzer/x509/X509Common.cc index 12abb5ecb0..19680f6404 100644 --- a/src/file_analysis/analyzer/x509/X509Common.cc +++ b/src/file_analysis/analyzer/x509/X509Common.cc @@ -269,7 +269,7 @@ void file_analysis::X509Common::ParseExtension(X509_EXTENSION* ex, const EventHa if ( ! ext_val ) ext_val = make_intrusive(0, ""); - auto pX509Ext = make_intrusive(BifType::Record::X509::Extension); + auto pX509Ext = make_intrusive(zeek::BifType::Record::X509::Extension); pX509Ext->Assign(0, make_intrusive(name)); if ( short_name and strlen(short_name) > 0 ) diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index 003e19d1ac..5cf3fe0e1b 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -13,7 +13,7 @@ // construct an error record IntrusivePtr x509_result_record(uint64_t num, const char* reason, Val* chainVector = nullptr) { - auto rrecord = make_intrusive(BifType::Record::X509::Result); + auto rrecord = make_intrusive(zeek::BifType::Record::X509::Result); rrecord->Assign(0, val_mgr->Int(num)); rrecord->Assign(1, make_intrusive(reason)); diff --git a/src/file_analysis/file_analysis.bif b/src/file_analysis/file_analysis.bif index 91bc6929aa..e15163dd83 100644 --- a/src/file_analysis/file_analysis.bif +++ b/src/file_analysis/file_analysis.bif @@ -41,8 +41,8 @@ function Files::__set_reassembly_buffer%(file_id: string, max: count%): bool ## :zeek:see:`Files::add_analyzer`. function Files::__add_analyzer%(file_id: string, tag: Files::Tag, args: any%): bool %{ - using BifType::Record::Files::AnalyzerArgs; - auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs); + using zeek::BifType::Record::Files::AnalyzerArgs; + auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs.get()); bool result = file_mgr->AddAnalyzer(file_id->CheckString(), file_mgr->GetComponentTag(tag), rv.get()); return val_mgr->Bool(result); @@ -51,8 +51,8 @@ function Files::__add_analyzer%(file_id: string, tag: Files::Tag, args: any%): b ## :zeek:see:`Files::remove_analyzer`. function Files::__remove_analyzer%(file_id: string, tag: Files::Tag, args: any%): bool %{ - using BifType::Record::Files::AnalyzerArgs; - auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs); + using zeek::BifType::Record::Files::AnalyzerArgs; + auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs.get()); bool result = file_mgr->RemoveAnalyzer(file_id->CheckString(), file_mgr->GetComponentTag(tag) , rv.get()); return val_mgr->Bool(result); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index d31838ba2b..ed4701e127 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -225,9 +225,9 @@ ReaderBackend* Manager::CreateBackend(ReaderFrontend* frontend, EnumVal* tag) bool Manager::CreateStream(Stream* info, RecordVal* description) { RecordType* rtype = description->GetType()->AsRecordType(); - if ( ! ( same_type(rtype, BifType::Record::Input::TableDescription, false) - || same_type(rtype, BifType::Record::Input::EventDescription, false) - || same_type(rtype, BifType::Record::Input::AnalysisDescription, false) ) ) + if ( ! ( same_type(rtype, zeek::BifType::Record::Input::TableDescription.get(), false) + || same_type(rtype, zeek::BifType::Record::Input::EventDescription.get(), false) + || same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription.get(), false) ) ) { reporter->Error("Stream description argument not of right type for new input stream"); return false; @@ -311,7 +311,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) bool Manager::CreateEventStream(RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Input::EventDescription, false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Input::EventDescription.get(), false) ) { reporter->Error("EventDescription argument not of right type"); return false; @@ -344,13 +344,13 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - if ( ! same_type(args[1].get(), BifType::Enum::Input::Event, false) ) + if ( ! same_type(args[1].get(), zeek::BifType::Enum::Input::Event.get(), false) ) { reporter->Error("Input stream %s: Event's second attribute must be of type Input::Event", stream_name.c_str()); return false; } - if ( ! same_type(args[0].get(), BifType::Record::Input::EventDescription, false) ) + if ( ! same_type(args[0].get(), zeek::BifType::Record::Input::EventDescription.get(), false) ) { reporter->Error("Input stream %s: Event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; @@ -464,7 +464,7 @@ bool Manager::CreateEventStream(RecordVal* fval) bool Manager::CreateTableStream(RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Input::TableDescription, false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Input::TableDescription.get(), false) ) { reporter->Error("TableDescription argument not of right type"); return false; @@ -572,13 +572,13 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( ! same_type(args[0].get(), BifType::Record::Input::TableDescription, false) ) + if ( ! same_type(args[0].get(), zeek::BifType::Record::Input::TableDescription.get(), false) ) { reporter->Error("Input stream %s: Table event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! same_type(args[1].get(), BifType::Enum::Input::Event, false) ) + if ( ! same_type(args[1].get(), zeek::BifType::Enum::Input::Event.get(), false) ) { reporter->Error("Input stream %s: Table event's second attribute must be of type Input::Event", stream_name.c_str()); return false; @@ -719,13 +719,13 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - if ( table && ! same_type(args[0].get(), BifType::Record::Input::TableDescription, false) ) + if ( table && ! same_type(args[0].get(), zeek::BifType::Record::Input::TableDescription.get(), false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! table && ! same_type(args[0].get(), BifType::Record::Input::EventDescription, false) ) + if ( ! table && ! same_type(args[0].get(), zeek::BifType::Record::Input::EventDescription.get(), false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; @@ -737,7 +737,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - if ( ! same_type(args[2].get(), BifType::Enum::Reporter::Level, false) ) + if ( ! same_type(args[2].get(), zeek::BifType::Enum::Reporter::Level.get(), false) ) { reporter->Error("Input stream %s: Error event's third attribute must be of type Reporter::Level", stream_name.c_str()); return false; @@ -750,7 +750,7 @@ bool Manager::CreateAnalysisStream(RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Input::AnalysisDescription, false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription.get(), false) ) { reporter->Error("AnalysisDescription argument not of right type"); return false; @@ -1072,7 +1072,7 @@ void Manager::SendEntry(ReaderFrontend* reader, Value* *vals) else if ( i->stream_type == EVENT_STREAM ) { - EnumVal* type = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + EnumVal* type = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); readFields = SendEventStreamEvent(i, type, vals); } @@ -1177,9 +1177,9 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) if ( ! pred_convert_error ) { if ( updated ) - ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); else - ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); bool result; if ( stream->num_val_fields > 0 ) // we have values @@ -1278,13 +1278,13 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) else if ( updated ) { // in case of update send back the old value. assert ( stream->num_val_fields > 0 ); - ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); assert ( oldval != nullptr ); SendEvent(stream->event, 4, stream->description->Ref(), ev, predidx, oldval.release()); } else { - ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); if ( stream->num_val_fields == 0 ) { Ref(stream->description); @@ -1347,7 +1347,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) val = stream->tab->Lookup(idx.get()); assert(val != nullptr); predidx = ListValToRecordVal(idx.get(), stream->itype, &startpos); - ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); } if ( stream->pred ) @@ -1454,7 +1454,7 @@ void Manager::Put(ReaderFrontend* reader, Value* *vals) else if ( i->stream_type == EVENT_STREAM ) { - EnumVal* type = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + EnumVal* type = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); readFields = SendEventStreamEvent(i, type, vals); } @@ -1591,9 +1591,9 @@ int Manager::PutTable(Stream* i, const Value* const *vals) else { if ( updated ) - ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); else - ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); bool result; if ( stream->num_val_fields > 0 ) // we have values @@ -1632,14 +1632,14 @@ int Manager::PutTable(Stream* i, const Value* const *vals) { // in case of update send back the old value. assert ( stream->num_val_fields > 0 ); - ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); assert ( oldval != nullptr ); SendEvent(stream->event, 4, stream->description->Ref(), ev, predidx, oldval.release()); } else { - ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); if ( stream->num_val_fields == 0 ) SendEvent(stream->event, 4, stream->description->Ref(), ev, predidx); @@ -1724,7 +1724,7 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) Unref(predidx); else { - EnumVal* ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); + EnumVal* ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); streamresult = CallPred(stream->pred, 3, ev, predidx, IntrusivePtr{val}.release()); @@ -1743,7 +1743,7 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) { Ref(idxval); assert(val != nullptr); - EnumVal* ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); + EnumVal* ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); SendEvent(stream->event, 4, stream->description->Ref(), ev, idxval, IntrusivePtr{val}.release()); } } @@ -1758,7 +1758,7 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) else if ( i->stream_type == EVENT_STREAM ) { - EnumVal* type = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); + EnumVal* type = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); readVals = SendEventStreamEvent(i, type, vals); success = true; } @@ -2715,15 +2715,15 @@ void Manager::ErrorHandler(const Stream* i, ErrorType et, bool reporter_send, co switch (et) { case ErrorType::INFO: - ev = BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::INFO).release(); + ev = zeek::BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::INFO).release(); break; case ErrorType::WARNING: - ev = BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::WARNING).release(); + ev = zeek::BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::WARNING).release(); break; case ErrorType::ERROR: - ev = BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::ERROR).release(); + ev = zeek::BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::ERROR).release(); break; default: diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index fdbf824042..616de91fcc 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -627,7 +627,7 @@ IntrusivePtr Packet::ToRawPktHdrVal() const { // Ethernet header layout is: // dst[6bytes] src[6bytes] ethertype[2bytes]... - l2_hdr->Assign(0, BifType::Enum::link_encap->GetVal(BifEnum::LINK_ETHERNET)); + l2_hdr->Assign(0, zeek::BifType::Enum::link_encap->GetVal(BifEnum::LINK_ETHERNET)); l2_hdr->Assign(3, FmtEUI48(data + 6)); // src l2_hdr->Assign(4, FmtEUI48(data)); // dst @@ -644,12 +644,12 @@ IntrusivePtr Packet::ToRawPktHdrVal() const l3 = BifEnum::L3_ARP; } else - l2_hdr->Assign(0, BifType::Enum::link_encap->GetVal(BifEnum::LINK_UNKNOWN)); + l2_hdr->Assign(0, zeek::BifType::Enum::link_encap->GetVal(BifEnum::LINK_UNKNOWN)); l2_hdr->Assign(1, val_mgr->Count(len)); l2_hdr->Assign(2, val_mgr->Count(cap_len)); - l2_hdr->Assign(8, BifType::Enum::layer3_proto->GetVal(l3)); + l2_hdr->Assign(8, zeek::BifType::Enum::layer3_proto->GetVal(l3)); pkt_hdr->Assign(0, l2_hdr); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 1c4ff43653..fae52407df 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -231,7 +231,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) { RecordType* rtype = sval->GetType()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Log::Stream, false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Log::Stream.get(), false) ) { reporter->Error("sval argument not of right type"); return false; @@ -534,7 +534,7 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Log::Filter, false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Log::Filter.get(), false) ) { reporter->Error("filter argument not of right type"); return false; @@ -1514,7 +1514,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con return true; // Create the RotationInfo record. - auto info = make_intrusive(BifType::Record::Log::RotationInfo); + auto info = make_intrusive(zeek::BifType::Record::Log::RotationInfo); info->Assign(0, winfo->type->Ref()); info->Assign(1, make_intrusive(new_name)); info->Assign(2, make_intrusive(winfo->writer->Info().path)); diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index bd52f241b0..2856f188b2 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1104,7 +1104,7 @@ std::string Supervisor::NodeConfig::ToJSON() const IntrusivePtr Supervisor::NodeConfig::ToRecord() const { - auto rt = BifType::Record::Supervisor::NodeConfig; + const auto& rt = zeek::BifType::Record::Supervisor::NodeConfig; auto rval = make_intrusive(rt); rval->Assign(rt->FieldOffset("name"), make_intrusive(name)); @@ -1140,10 +1140,10 @@ IntrusivePtr Supervisor::NodeConfig::ToRecord() const auto& name = e.first; auto& ep = e.second; auto key = make_intrusive(name); - auto ept = BifType::Record::Supervisor::ClusterEndpoint; + const auto& ept = zeek::BifType::Record::Supervisor::ClusterEndpoint; auto val = make_intrusive(ept); - val->Assign(ept->FieldOffset("role"), BifType::Enum::Supervisor::ClusterRole->GetVal(ep.role)); + val->Assign(ept->FieldOffset("role"), zeek::BifType::Enum::Supervisor::ClusterRole->GetVal(ep.role)); val->Assign(ept->FieldOffset("host"), make_intrusive(ep.host)); val->Assign(ept->FieldOffset("p"), val_mgr->Port(ep.port, TRANSPORT_TCP)); @@ -1158,7 +1158,7 @@ IntrusivePtr Supervisor::NodeConfig::ToRecord() const IntrusivePtr Supervisor::Node::ToRecord() const { - auto rt = BifType::Record::Supervisor::NodeStatus; + const auto& rt = zeek::BifType::Record::Supervisor::NodeStatus; auto rval = make_intrusive(rt); rval->Assign(rt->FieldOffset("node"), config.ToRecord()); @@ -1314,8 +1314,8 @@ void Supervisor::SupervisedNode::Init(zeek::Options* options) const IntrusivePtr Supervisor::Status(std::string_view node_name) { - auto rval = make_intrusive(BifType::Record::Supervisor::Status); - const auto& tt = BifType::Record::Supervisor::Status->GetFieldType("nodes"); + auto rval = make_intrusive(zeek::BifType::Record::Supervisor::Status); + const auto& tt = zeek::BifType::Record::Supervisor::Status->GetFieldType("nodes"); auto node_table_val = new TableVal(cast_intrusive(tt)); rval->Assign(0, node_table_val); diff --git a/src/supervisor/supervisor.bif b/src/supervisor/supervisor.bif index 096fa8d957..a6ee28ae1b 100644 --- a/src/supervisor/supervisor.bif +++ b/src/supervisor/supervisor.bif @@ -24,7 +24,7 @@ function Supervisor::__status%(node: string%): Supervisor::Status if ( ! zeek::supervisor_mgr ) { builtin_error("supervisor mode not enabled"); - return make_intrusive(BifType::Record::Supervisor::Status); + return make_intrusive(zeek::BifType::Record::Supervisor::Status); } return zeek::supervisor_mgr->Status(node->CheckString()); @@ -84,7 +84,7 @@ function Supervisor::__node%(%): Supervisor::NodeConfig if ( ! zeek::Supervisor::ThisNode() ) { builtin_error("not a supervised process"); - auto rt = BifType::Record::Supervisor::NodeConfig; + const auto& rt = zeek::BifType::Record::Supervisor::NodeConfig; auto rval = make_intrusive(rt); rval->Assign(rt->FieldOffset("name"), new StringVal("")); return rval; diff --git a/src/zeek.bif b/src/zeek.bif index cd202df1d7..a61ffd55a4 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -3397,7 +3397,7 @@ function get_current_packet%(%) : pcap_packet pkt->Assign(2, val_mgr->Count(0)); pkt->Assign(3, val_mgr->Count(0)); pkt->Assign(4, val_mgr->EmptyString()); - pkt->Assign(5, BifType::Enum::link_encap->GetVal(BifEnum::LINK_UNKNOWN)); + pkt->Assign(5, zeek::BifType::Enum::link_encap->GetVal(BifEnum::LINK_UNKNOWN)); return pkt; } @@ -3406,7 +3406,7 @@ function get_current_packet%(%) : pcap_packet pkt->Assign(2, val_mgr->Count(p->cap_len)); pkt->Assign(3, val_mgr->Count(p->len)); pkt->Assign(4, make_intrusive(p->cap_len, (const char*)p->data)); - pkt->Assign(5, BifType::Enum::link_encap->GetVal(p->link_type)); + pkt->Assign(5, zeek::BifType::Enum::link_encap->GetVal(p->link_type)); return pkt; %} From 0db5c920f2bd81101b3acaff973b7d92379c02ad Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 13 May 2020 23:41:01 -0700 Subject: [PATCH 057/151] Deprecate names in BifConst, replace with zeek::BifConst Some Val* types are also replaced with IntrusivePtr at the new location --- NEWS | 4 +++ aux/bifcl | 2 +- src/Hash.cc | 2 +- src/ID.h | 10 ++++++ src/Net.cc | 6 ++-- src/Sessions.cc | 8 ++--- src/Sessions.h | 2 +- .../protocol/ayiya/ayiya-analyzer.pac | 2 +- .../protocol/dce-rpc/dce_rpc-protocol.pac | 6 ++-- .../protocol/gtpv1/gtpv1-analyzer.pac | 4 +-- src/analyzer/protocol/http/HTTP.cc | 2 +- src/analyzer/protocol/krb/KRB.cc | 4 +-- src/analyzer/protocol/ncp/NCP.cc | 2 +- src/analyzer/protocol/rpc/NFS.cc | 6 ++-- .../protocol/smb/smb1-com-nt-create-andx.pac | 2 +- src/analyzer/protocol/smb/smb2-com-create.pac | 2 +- src/analyzer/protocol/ssl/dtls-protocol.pac | 4 +-- src/analyzer/protocol/tcp/TCP.cc | 2 +- src/analyzer/protocol/tcp/TCP_Reassembler.cc | 6 ++-- src/analyzer/protocol/teredo/Teredo.cc | 2 +- src/analyzer/protocol/teredo/Teredo.h | 2 +- src/analyzer/protocol/udp/UDP.cc | 2 +- src/analyzer/protocol/vxlan/VXLAN.cc | 2 +- src/input/Manager.cc | 4 +-- src/input/readers/ascii/Ascii.cc | 24 ++++++------- src/input/readers/benchmark/Benchmark.cc | 14 ++++---- src/input/readers/binary/Binary.cc | 6 ++-- src/input/readers/config/Config.cc | 10 +++--- src/input/readers/raw/Raw.cc | 6 ++-- src/input/readers/sqlite/SQLite.cc | 12 +++---- src/iosource/Manager.cc | 2 +- src/iosource/PktSrc.cc | 2 +- src/iosource/pcap/Dumper.cc | 2 +- src/iosource/pcap/Source.cc | 4 +-- src/logging/writers/ascii/Ascii.cc | 36 +++++++++---------- src/logging/writers/none/None.cc | 2 +- src/logging/writers/sqlite/SQLite.cc | 12 +++---- src/main.cc | 2 +- src/threading/Manager.cc | 4 +-- 39 files changed, 120 insertions(+), 106 deletions(-) diff --git a/NEWS b/NEWS index fe2629d8a7..8e131e2838 100644 --- a/NEWS +++ b/NEWS @@ -180,6 +180,10 @@ Deprecated Functionality deprecated, but there's an equivalent name in ``zeek::BifType::`` of ``IntrusivePtr`` type to use instead. +- All generated ``BifConst::`` names are deprecated, but there's an + equivalent name now in ``zeek::BifCont::``, and changed to ``IntrusivePtr`` + if the old name was some ``Val*`` type. + Zeek 3.1.0 ========== diff --git a/aux/bifcl b/aux/bifcl index 5afd05f72b..7fdbbfdf5e 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 5afd05f72b52bd40637546203749fb7bed8dbc4d +Subproject commit 7fdbbfdf5ee3669a77f73360b86326344e15ea99 diff --git a/src/Hash.cc b/src/Hash.cc index 22249ad11d..a5a375750b 100644 --- a/src/Hash.cc +++ b/src/Hash.cc @@ -40,7 +40,7 @@ void KeyedHash::InitializeSeeds(const std::array& seed void KeyedHash::InitOptions() { - calculate_digest(Hash_SHA256, BifConst::digest_salt->Bytes(), BifConst::digest_salt->Len(), reinterpret_cast(cluster_highwayhash_key)); + calculate_digest(Hash_SHA256, zeek::BifConst::digest_salt->Bytes(), zeek::BifConst::digest_salt->Len(), reinterpret_cast(cluster_highwayhash_key)); } hash64_t KeyedHash::Hash64(const void* bytes, uint64_t size) diff --git a/src/ID.h b/src/ID.h index 7582dd5c81..065c144c89 100644 --- a/src/ID.h +++ b/src/ID.h @@ -212,6 +212,16 @@ IntrusivePtr lookup_val(std::string_view name) */ const IntrusivePtr& lookup_const(std::string_view name); +/** + * Lookup an ID by its name and return its value (as cast to @c T). + * A fatal occurs if the ID does not exist. + * @param name The identifier name to lookup + * @return The current value of the identifier. + */ +template +IntrusivePtr lookup_const(std::string_view name) + { return cast_intrusive(lookup_const(name)); } + /** * Lookup an ID by its name and return the function it references. * A fatal occurs if the ID does not exist or if it is not a function. diff --git a/src/Net.cc b/src/Net.cc index 9f8f28ba28..d7d6f59a14 100644 --- a/src/Net.cc +++ b/src/Net.cc @@ -283,7 +283,7 @@ void net_run() ready.reserve(iosource_mgr->TotalSize()); while ( iosource_mgr->Size() || - (BifConst::exit_only_after_terminate && ! terminating) ) + (zeek::BifConst::exit_only_after_terminate && ! terminating) ) { iosource_mgr->FindReadySources(&ready); @@ -314,8 +314,8 @@ void net_run() } } else if ( (have_pending_timers || communication_enabled || - BifConst::exit_only_after_terminate) && - ! pseudo_realtime ) + zeek::BifConst::exit_only_after_terminate) && + ! pseudo_realtime ) { // Take advantage of the lull to get up to // date on timers and events. Because we only diff --git a/src/Sessions.cc b/src/Sessions.cc index 8e04444298..56a40d0964 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -54,7 +54,7 @@ void IPTunnelTimer::Dispatch(double t, bool is_expire) double last_active = it->second.second; double inactive_time = t > last_active ? t - last_active : 0; - if ( inactive_time >= BifConst::Tunnel::ip_tunnel_timeout ) + if ( inactive_time >= zeek::BifConst::Tunnel::ip_tunnel_timeout ) // tunnel activity timed out, delete it from map sessions->ip_tunnels.erase(tunnel_idx); @@ -409,7 +409,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr case IPPROTO_GRE: { - if ( ! BifConst::Tunnel::enable_gre ) + if ( ! zeek::BifConst::Tunnel::enable_gre ) { Weird("GRE_tunnel", ip_hdr, encapsulation); return; @@ -561,14 +561,14 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr case IPPROTO_IPV4: case IPPROTO_IPV6: { - if ( ! BifConst::Tunnel::enable_ip ) + if ( ! zeek::BifConst::Tunnel::enable_ip ) { Weird("IP_tunnel", ip_hdr, encapsulation); return; } if ( encapsulation && - encapsulation->Depth() >= BifConst::Tunnel::max_depth ) + encapsulation->Depth() >= zeek::BifConst::Tunnel::max_depth ) { Weird("exceeded_tunnel_max_depth", ip_hdr, encapsulation); return; diff --git a/src/Sessions.h b/src/Sessions.h index 67589d8742..d5edf62291 100644 --- a/src/Sessions.h +++ b/src/Sessions.h @@ -243,7 +243,7 @@ protected: class IPTunnelTimer final : public Timer { public: IPTunnelTimer(double t, NetSessions::IPPair p) - : Timer(t + BifConst::Tunnel::ip_tunnel_timeout, + : Timer(t + zeek::BifConst::Tunnel::ip_tunnel_timeout, TIMER_IP_TUNNEL_INACTIVITY), tunnel_idx(p) {} ~IPTunnelTimer() override {} diff --git a/src/analyzer/protocol/ayiya/ayiya-analyzer.pac b/src/analyzer/protocol/ayiya/ayiya-analyzer.pac index 935e05d749..30a263d2bc 100644 --- a/src/analyzer/protocol/ayiya/ayiya-analyzer.pac +++ b/src/analyzer/protocol/ayiya/ayiya-analyzer.pac @@ -18,7 +18,7 @@ flow AYIYA_Flow Connection *c = connection()->bro_analyzer()->Conn(); const EncapsulationStack* e = c->GetEncapsulation(); - if ( e && e->Depth() >= BifConst::Tunnel::max_depth ) + if ( e && e->Depth() >= zeek::BifConst::Tunnel::max_depth ) { reporter->Weird(c, "tunnel_depth"); return false; diff --git a/src/analyzer/protocol/dce-rpc/dce_rpc-protocol.pac b/src/analyzer/protocol/dce-rpc/dce_rpc-protocol.pac index db1b487178..5263b20c93 100644 --- a/src/analyzer/protocol/dce-rpc/dce_rpc-protocol.pac +++ b/src/analyzer/protocol/dce-rpc/dce_rpc-protocol.pac @@ -210,14 +210,14 @@ flow DCE_RPC_Flow(is_orig: bool) { flowbuf->NewFrame(0, true); flowbuf->BufferData(frag.begin(), frag.end()); - if ( fb.size() > BifConst::DCE_RPC::max_cmd_reassembly ) + if ( fb.size() > zeek::BifConst::DCE_RPC::max_cmd_reassembly ) { reporter->Weird(connection()->bro_analyzer()->Conn(), "too_many_dce_rpc_msgs_in_reassembly"); connection()->bro_analyzer()->SetSkip(true); } - if ( flowbuf->data_length() > (int)BifConst::DCE_RPC::max_frag_data ) + if ( flowbuf->data_length() > (int)zeek::BifConst::DCE_RPC::max_frag_data ) { reporter->Weird(connection()->bro_analyzer()->Conn(), "too_much_dce_rpc_fragment_data"); @@ -233,7 +233,7 @@ flow DCE_RPC_Flow(is_orig: bool) { auto& flowbuf = it->second; flowbuf->BufferData(frag.begin(), frag.end()); - if ( flowbuf->data_length() > (int)BifConst::DCE_RPC::max_frag_data ) + if ( flowbuf->data_length() > (int)zeek::BifConst::DCE_RPC::max_frag_data ) { reporter->Weird(connection()->bro_analyzer()->Conn(), "too_much_dce_rpc_fragment_data"); diff --git a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac index 6b06e0383a..e91d4499b3 100644 --- a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac +++ b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac @@ -652,7 +652,7 @@ flow GTPv1_Flow(is_orig: bool) connection()->set_valid(is_orig(), false); - if ( e && e->Depth() >= BifConst::Tunnel::max_depth ) + if ( e && e->Depth() >= zeek::BifConst::Tunnel::max_depth ) { reporter->Weird(c, "tunnel_depth"); return false; @@ -738,7 +738,7 @@ flow GTPv1_Flow(is_orig: bool) { connection()->set_valid(is_orig(), true); - if ( (! BifConst::Tunnel::delay_gtp_confirmation) || + if ( (! zeek::BifConst::Tunnel::delay_gtp_confirmation) || (connection()->valid(true) && connection()->valid(false)) ) a->ProtocolConfirmation(); } diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index f210f27644..875f371a43 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -810,7 +810,7 @@ void HTTP_Message::SetPlainDelivery(int64_t length) { content_line->SetPlainDelivery(length); - if ( length > 0 && BifConst::skip_http_data ) + if ( length > 0 && zeek::BifConst::skip_http_data ) content_line->SkipBytesAfterThisLine(length); } diff --git a/src/analyzer/protocol/krb/KRB.cc b/src/analyzer/protocol/krb/KRB.cc index da8af91e8e..5d66d7942a 100644 --- a/src/analyzer/protocol/krb/KRB.cc +++ b/src/analyzer/protocol/krb/KRB.cc @@ -35,10 +35,10 @@ static void warn_krb(const char* msg, krb5_context ctx, krb5_error_code code) void KRB_Analyzer::Initialize_Krb() { - if ( BifConst::KRB::keytab->Len() == 0 ) + if ( zeek::BifConst::KRB::keytab->Len() == 0 ) return; // no keytab set - const char* keytab_filename = BifConst::KRB::keytab->CheckString(); + const char* keytab_filename = zeek::BifConst::KRB::keytab->CheckString(); if ( access(keytab_filename, R_OK) != 0 ) { reporter->Warning("KRB: Can't access keytab (%s)", keytab_filename); diff --git a/src/analyzer/protocol/ncp/NCP.cc b/src/analyzer/protocol/ncp/NCP.cc index 31a39023e9..180d1164c9 100644 --- a/src/analyzer/protocol/ncp/NCP.cc +++ b/src/analyzer/protocol/ncp/NCP.cc @@ -129,7 +129,7 @@ int FrameBuffer::Deliver(int &len, const u_char* &data) if ( msg_len > buf_len ) { - if ( msg_len > BifConst::NCP::max_frame_size ) + if ( msg_len > zeek::BifConst::NCP::max_frame_size ) return 1; buf_len = msg_len; diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index c57e1eba38..3e343f2e73 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -302,15 +302,15 @@ StringVal* NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offse const u_char *data = extract_XDR_opaque(buf, n, data_n, 1 << 30, true); // check whether we have to deliver data to the event - if ( ! BifConst::NFS3::return_data ) + if ( ! zeek::BifConst::NFS3::return_data ) return nullptr; - if ( BifConst::NFS3::return_data_first_only && offset != 0 ) + if ( zeek::BifConst::NFS3::return_data_first_only && offset != 0 ) return nullptr; // Ok, so we want to return some data data_n = std::min(data_n, size); - data_n = std::min(data_n, int(BifConst::NFS3::return_data_max)); + data_n = std::min(data_n, int(zeek::BifConst::NFS3::return_data_max)); if ( data && data_n > 0 ) return new StringVal(new BroString(data, data_n, false)); diff --git a/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac b/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac index 05fc5d3014..f07f9774e2 100644 --- a/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac @@ -4,7 +4,7 @@ refine connection SMB_Conn += { auto filename = smb_string2stringval(${val.filename}); if ( ! ${header.is_pipe} && - BifConst::SMB::pipe_filenames->AsTable()->Lookup(filename->CheckString()) ) + zeek::BifConst::SMB::pipe_filenames->AsTable()->Lookup(filename->CheckString()) ) { set_tree_is_pipe(${header.tid}); diff --git a/src/analyzer/protocol/smb/smb2-com-create.pac b/src/analyzer/protocol/smb/smb2-com-create.pac index c8f8682b33..ff60931c9d 100644 --- a/src/analyzer/protocol/smb/smb2-com-create.pac +++ b/src/analyzer/protocol/smb/smb2-com-create.pac @@ -5,7 +5,7 @@ refine connection SMB_Conn += { auto filename = smb2_string2stringval(${val.filename}); if ( ! ${h.is_pipe} && - BifConst::SMB::pipe_filenames->AsTable()->Lookup(filename->CheckString()) ) + zeek::BifConst::SMB::pipe_filenames->AsTable()->Lookup(filename->CheckString()) ) { set_tree_is_pipe(${h.tree_id}); diff --git a/src/analyzer/protocol/ssl/dtls-protocol.pac b/src/analyzer/protocol/ssl/dtls-protocol.pac index 70897a585c..c54a62f251 100644 --- a/src/analyzer/protocol/ssl/dtls-protocol.pac +++ b/src/analyzer/protocol/ssl/dtls-protocol.pac @@ -73,11 +73,11 @@ refine connection SSL_Conn += { if ( bro_analyzer()->ProtocolConfirmed() ) { reported_errors_++; - if ( reported_errors_ <= BifConst::SSL::dtls_max_reported_version_errors ) + if ( reported_errors_ <= zeek::BifConst::SSL::dtls_max_reported_version_errors ) bro_analyzer()->ProtocolViolation(fmt("Invalid version in DTLS connection. Packet reported version: %d", version)); } - if ( invalid_version_count_ > BifConst::SSL::dtls_max_version_errors ) + if ( invalid_version_count_ > zeek::BifConst::SSL::dtls_max_version_errors ) bro_analyzer()->SetSkip(true); return false; } diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index 3522439cce..6233c3a0ad 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -2051,7 +2051,7 @@ bool TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int capl int64_t sequence_delta = top_seq - max_top_seq; if ( sequence_delta <= 0 ) { - if ( ! BifConst::ignore_keep_alive_rexmit || len > 1 || data_in_flight > 0 ) + if ( ! zeek::BifConst::ignore_keep_alive_rexmit || len > 1 || data_in_flight > 0 ) { ++num_rxmit; num_rxmit_bytes += len; diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.cc b/src/analyzer/protocol/tcp/TCP_Reassembler.cc index 9de7331255..1b251cfa10 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.cc +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.cc @@ -135,7 +135,7 @@ static inline bool established_or_cleanly_closing(const TCP_Endpoint* a, static inline bool report_gap(const TCP_Endpoint* a, const TCP_Endpoint* b) { return content_gap && - ( BifConst::report_gaps_for_partial || + ( zeek::BifConst::report_gaps_for_partial || established_or_cleanly_closing(a, b) ); } @@ -210,7 +210,7 @@ void TCP_Reassembler::Undelivered(uint64_t up_to_seq) // to this method and only if this condition is not true). reporter->InternalError("Calling Undelivered for data that has already been delivered (or has already been marked as undelivered"); - if ( BifConst::detect_filtered_trace && last_reassem_seq == 1 && + if ( zeek::BifConst::detect_filtered_trace && last_reassem_seq == 1 && (endpoint->FIN_cnt > 0 || endpoint->RST_cnt > 0 || peer->FIN_cnt > 0 || peer->RST_cnt > 0) ) { @@ -539,7 +539,7 @@ void TCP_Reassembler::AckReceived(uint64_t seq) return; bool test_active = ! skip_deliveries && ! tcp_analyzer->Skipping() && - ( BifConst::report_gaps_for_partial || + ( zeek::BifConst::report_gaps_for_partial || (endp->state == TCP_ENDPOINT_ESTABLISHED && endp->peer->state == TCP_ENDPOINT_ESTABLISHED ) ); diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index fcd0f0323e..d5e8790fe3 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -161,7 +161,7 @@ void Teredo_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, const EncapsulationStack* e = Conn()->GetEncapsulation(); - if ( e && e->Depth() >= BifConst::Tunnel::max_depth ) + if ( e && e->Depth() >= zeek::BifConst::Tunnel::max_depth ) { Weird("tunnel_depth", true); return; diff --git a/src/analyzer/protocol/teredo/Teredo.h b/src/analyzer/protocol/teredo/Teredo.h index 4abd9483e6..6b9975537c 100644 --- a/src/analyzer/protocol/teredo/Teredo.h +++ b/src/analyzer/protocol/teredo/Teredo.h @@ -42,7 +42,7 @@ public: */ void Confirm() { - if ( ! BifConst::Tunnel::delay_teredo_confirmation || + if ( ! zeek::BifConst::Tunnel::delay_teredo_confirmation || ( valid_orig && valid_resp ) ) ProtocolConfirmation(); } diff --git a/src/analyzer/protocol/udp/UDP.cc b/src/analyzer/protocol/udp/UDP.cc index 50c73fd51e..518050a1c7 100644 --- a/src/analyzer/protocol/udp/UDP.cc +++ b/src/analyzer/protocol/udp/UDP.cc @@ -81,7 +81,7 @@ void UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig, if ( chksum == 0 ) validate_checksum = false; else - validate_checksum = BifConst::Tunnel::validate_vxlan_checksums; + validate_checksum = zeek::BifConst::Tunnel::validate_vxlan_checksums; } } diff --git a/src/analyzer/protocol/vxlan/VXLAN.cc b/src/analyzer/protocol/vxlan/VXLAN.cc index eb4e0e5926..d633649ae6 100644 --- a/src/analyzer/protocol/vxlan/VXLAN.cc +++ b/src/analyzer/protocol/vxlan/VXLAN.cc @@ -48,7 +48,7 @@ void VXLAN_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, const EncapsulationStack* estack = Conn()->GetEncapsulation(); - if ( estack && estack->Depth() >= BifConst::Tunnel::max_depth ) + if ( estack && estack->Depth() >= zeek::BifConst::Tunnel::max_depth ) { reporter->Weird(Conn(), "tunnel_depth"); return; diff --git a/src/input/Manager.cc b/src/input/Manager.cc index ed4701e127..e9f80cb6ad 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -405,7 +405,7 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - allow_file_func = BifConst::Input::accept_unsupported_types; + allow_file_func = zeek::BifConst::Input::accept_unsupported_types; } @@ -637,7 +637,7 @@ bool Manager::CreateTableStream(RecordVal* fval) int idxfields = fieldsV.size(); if ( val ) // if we are not a set - status = status || ! UnrollRecordType(&fieldsV, val.get(), "", BifConst::Input::accept_unsupported_types); + status = status || ! UnrollRecordType(&fieldsV, val.get(), "", zeek::BifConst::Input::accept_unsupported_types); int valfields = fieldsV.size() - idxfields; diff --git a/src/input/readers/ascii/Ascii.cc b/src/input/readers/ascii/Ascii.cc index 3b108e365c..c3950cdc59 100644 --- a/src/input/readers/ascii/Ascii.cc +++ b/src/input/readers/ascii/Ascii.cc @@ -67,23 +67,23 @@ bool Ascii::DoInit(const ReaderInfo& info, int num_fields, const Field* const* f { StopWarningSuppression(); - separator.assign( (const char*) BifConst::InputAscii::separator->Bytes(), - BifConst::InputAscii::separator->Len()); + separator.assign( (const char*) zeek::BifConst::InputAscii::separator->Bytes(), + zeek::BifConst::InputAscii::separator->Len()); - set_separator.assign( (const char*) BifConst::InputAscii::set_separator->Bytes(), - BifConst::InputAscii::set_separator->Len()); + set_separator.assign( (const char*) zeek::BifConst::InputAscii::set_separator->Bytes(), + zeek::BifConst::InputAscii::set_separator->Len()); - empty_field.assign( (const char*) BifConst::InputAscii::empty_field->Bytes(), - BifConst::InputAscii::empty_field->Len()); + empty_field.assign( (const char*) zeek::BifConst::InputAscii::empty_field->Bytes(), + zeek::BifConst::InputAscii::empty_field->Len()); - unset_field.assign( (const char*) BifConst::InputAscii::unset_field->Bytes(), - BifConst::InputAscii::unset_field->Len()); + unset_field.assign( (const char*) zeek::BifConst::InputAscii::unset_field->Bytes(), + zeek::BifConst::InputAscii::unset_field->Len()); - fail_on_invalid_lines = BifConst::InputAscii::fail_on_invalid_lines; - fail_on_file_problem = BifConst::InputAscii::fail_on_file_problem; + fail_on_invalid_lines = zeek::BifConst::InputAscii::fail_on_invalid_lines; + fail_on_file_problem = zeek::BifConst::InputAscii::fail_on_file_problem; - path_prefix.assign((const char*) BifConst::InputAscii::path_prefix->Bytes(), - BifConst::InputAscii::path_prefix->Len()); + path_prefix.assign((const char*) zeek::BifConst::InputAscii::path_prefix->Bytes(), + zeek::BifConst::InputAscii::path_prefix->Len()); // Set per-filter configuration options. for ( ReaderInfo::config_map::const_iterator i = info.config.begin(); i != info.config.end(); i++ ) diff --git a/src/input/readers/benchmark/Benchmark.cc b/src/input/readers/benchmark/Benchmark.cc index a7b0cc7c44..26975ad411 100644 --- a/src/input/readers/benchmark/Benchmark.cc +++ b/src/input/readers/benchmark/Benchmark.cc @@ -18,15 +18,15 @@ using threading::Field; Benchmark::Benchmark(ReaderFrontend *frontend) : ReaderBackend(frontend) { num_lines = 0; - multiplication_factor = double(BifConst::InputBenchmark::factor); - autospread = double(BifConst::InputBenchmark::autospread); - spread = int(BifConst::InputBenchmark::spread); - add = int(BifConst::InputBenchmark::addfactor); + multiplication_factor = double(zeek::BifConst::InputBenchmark::factor); + autospread = double(zeek::BifConst::InputBenchmark::autospread); + spread = int(zeek::BifConst::InputBenchmark::spread); + add = int(zeek::BifConst::InputBenchmark::addfactor); autospread_time = 0; - stopspreadat = int(BifConst::InputBenchmark::stopspreadat); - timedspread = double(BifConst::InputBenchmark::timedspread); + stopspreadat = int(zeek::BifConst::InputBenchmark::stopspreadat); + timedspread = double(zeek::BifConst::InputBenchmark::timedspread); heartbeatstarttime = 0; - heartbeat_interval = double(BifConst::Threading::heartbeat_interval); + heartbeat_interval = double(zeek::BifConst::Threading::heartbeat_interval); ascii = new threading::formatter::Ascii(this, threading::formatter::Ascii::SeparatorInfo()); } diff --git a/src/input/readers/binary/Binary.cc b/src/input/readers/binary/Binary.cc index 9aa815cb47..77db68a80e 100644 --- a/src/input/readers/binary/Binary.cc +++ b/src/input/readers/binary/Binary.cc @@ -19,7 +19,7 @@ Binary::Binary(ReaderFrontend *frontend) { if ( ! chunk_size ) { - chunk_size = BifConst::InputBinary::chunk_size; + chunk_size = zeek::BifConst::InputBinary::chunk_size; if ( ! chunk_size ) chunk_size = 1024; @@ -82,8 +82,8 @@ bool Binary::DoInit(const ReaderInfo& info, int num_fields, ino = 0; firstrun = true; - path_prefix.assign((const char*) BifConst::InputBinary::path_prefix->Bytes(), - BifConst::InputBinary::path_prefix->Len()); + path_prefix.assign((const char*) zeek::BifConst::InputBinary::path_prefix->Bytes(), + zeek::BifConst::InputBinary::path_prefix->Len()); if ( ! info.source || strlen(info.source) == 0 ) { diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 60437eb825..9ed946ba9b 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -63,13 +63,13 @@ void Config::DoClose() bool Config::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fields) { - fail_on_file_problem = BifConst::InputConfig::fail_on_file_problem; + fail_on_file_problem = zeek::BifConst::InputConfig::fail_on_file_problem; - set_separator.assign( (const char*) BifConst::InputConfig::set_separator->Bytes(), - BifConst::InputConfig::set_separator->Len()); + set_separator.assign( (const char*) zeek::BifConst::InputConfig::set_separator->Bytes(), + zeek::BifConst::InputConfig::set_separator->Len()); - empty_field.assign( (const char*) BifConst::InputConfig::empty_field->Bytes(), - BifConst::InputConfig::empty_field->Len()); + empty_field.assign( (const char*) zeek::BifConst::InputConfig::empty_field->Bytes(), + zeek::BifConst::InputConfig::empty_field->Len()); formatter::Ascii::SeparatorInfo sep_info("\t", set_separator, "", empty_field); formatter = std::unique_ptr(new formatter::Ascii(this, sep_info)); diff --git a/src/input/readers/raw/Raw.cc b/src/input/readers/raw/Raw.cc index b8bfbdb1da..d1dd8c9aac 100644 --- a/src/input/readers/raw/Raw.cc +++ b/src/input/readers/raw/Raw.cc @@ -34,10 +34,10 @@ Raw::Raw(ReaderFrontend *frontend) : ReaderBackend(frontend), file(nullptr, fclo ino = 0; forcekill = false; offset = 0; - separator.assign( (const char*) BifConst::InputRaw::record_separator->Bytes(), - BifConst::InputRaw::record_separator->Len()); + separator.assign( (const char*) zeek::BifConst::InputRaw::record_separator->Bytes(), + zeek::BifConst::InputRaw::record_separator->Len()); - sep_length = BifConst::InputRaw::record_separator->Len(); + sep_length = zeek::BifConst::InputRaw::record_separator->Len(); bufpos = 0; diff --git a/src/input/readers/sqlite/SQLite.cc b/src/input/readers/sqlite/SQLite.cc index e5e3a133e4..fccb9a5b0b 100644 --- a/src/input/readers/sqlite/SQLite.cc +++ b/src/input/readers/sqlite/SQLite.cc @@ -24,18 +24,18 @@ SQLite::SQLite(ReaderFrontend *frontend) fields(), num_fields(), mode(), started(), query(), db(), st() { set_separator.assign( - (const char*) BifConst::LogSQLite::set_separator->Bytes(), - BifConst::InputSQLite::set_separator->Len() + (const char*) zeek::BifConst::LogSQLite::set_separator->Bytes(), + zeek::BifConst::InputSQLite::set_separator->Len() ); unset_field.assign( - (const char*) BifConst::LogSQLite::unset_field->Bytes(), - BifConst::InputSQLite::unset_field->Len() + (const char*) zeek::BifConst::LogSQLite::unset_field->Bytes(), + zeek::BifConst::InputSQLite::unset_field->Len() ); empty_field.assign( - (const char*) BifConst::LogAscii::empty_field->Bytes(), - BifConst::InputSQLite::empty_field->Len() + (const char*) zeek::BifConst::LogAscii::empty_field->Bytes(), + zeek::BifConst::InputSQLite::empty_field->Len() ); io = new threading::formatter::Ascii(this, threading::formatter::Ascii::SeparatorInfo(std::string(), set_separator, unset_field, empty_field)); diff --git a/src/iosource/Manager.cc b/src/iosource/Manager.cc index 6ffc924ab8..d97b585894 100644 --- a/src/iosource/Manager.cc +++ b/src/iosource/Manager.cc @@ -115,7 +115,7 @@ void Manager::FindReadySources(std::vector* ready) // If there aren't any sources and exit_only_after_terminate is false, just // return an empty set of sources. We want the main loop to end. - if ( Size() == 0 && ( ! BifConst::exit_only_after_terminate || terminating ) ) + if ( Size() == 0 && ( ! zeek::BifConst::exit_only_after_terminate || terminating ) ) return; double timeout = -1; diff --git a/src/iosource/PktSrc.cc b/src/iosource/PktSrc.cc index 0aa1a2568e..8c0432425b 100644 --- a/src/iosource/PktSrc.cc +++ b/src/iosource/PktSrc.cc @@ -271,7 +271,7 @@ bool PktSrc::PrecompileBPFFilter(int index, const std::string& filter) // Compile filter. BPF_Program* code = new BPF_Program(); - if ( ! code->Compile(BifConst::Pcap::snaplen, LinkType(), filter.c_str(), Netmask(), errbuf, sizeof(errbuf)) ) + if ( ! code->Compile(zeek::BifConst::Pcap::snaplen, LinkType(), filter.c_str(), Netmask(), errbuf, sizeof(errbuf)) ) { std::string msg = fmt("cannot compile BPF filter \"%s\"", filter.c_str()); diff --git a/src/iosource/pcap/Dumper.cc b/src/iosource/pcap/Dumper.cc index 5bbf12dfa6..d161adda88 100644 --- a/src/iosource/pcap/Dumper.cc +++ b/src/iosource/pcap/Dumper.cc @@ -27,7 +27,7 @@ void PcapDumper::Open() { int linktype = -1; - pd = pcap_open_dead(DLT_EN10MB, BifConst::Pcap::snaplen); + pd = pcap_open_dead(DLT_EN10MB, zeek::BifConst::Pcap::snaplen); if ( ! pd ) { diff --git a/src/iosource/pcap/Source.cc b/src/iosource/pcap/Source.cc index 31599139ac..8df5111da0 100644 --- a/src/iosource/pcap/Source.cc +++ b/src/iosource/pcap/Source.cc @@ -111,7 +111,7 @@ void PcapSource::OpenLive() return; } - if ( pcap_set_snaplen(pd, BifConst::Pcap::snaplen) ) + if ( pcap_set_snaplen(pd, zeek::BifConst::Pcap::snaplen) ) { PcapError("pcap_set_snaplen"); return; @@ -137,7 +137,7 @@ void PcapSource::OpenLive() return; } - if ( pcap_set_buffer_size(pd, BifConst::Pcap::bufsize * 1024 * 1024) ) + if ( pcap_set_buffer_size(pd, zeek::BifConst::Pcap::bufsize * 1024 * 1024) ) { PcapError("pcap_set_buffer_size"); return; diff --git a/src/logging/writers/ascii/Ascii.cc b/src/logging/writers/ascii/Ascii.cc index 8c502b498b..47cceeb738 100644 --- a/src/logging/writers/ascii/Ascii.cc +++ b/src/logging/writers/ascii/Ascii.cc @@ -35,47 +35,47 @@ Ascii::Ascii(WriterFrontend* frontend) : WriterBackend(frontend) void Ascii::InitConfigOptions() { - output_to_stdout = BifConst::LogAscii::output_to_stdout; - include_meta = BifConst::LogAscii::include_meta; - use_json = BifConst::LogAscii::use_json; - enable_utf_8 = BifConst::LogAscii::enable_utf_8; - gzip_level = BifConst::LogAscii::gzip_level; + output_to_stdout = zeek::BifConst::LogAscii::output_to_stdout; + include_meta = zeek::BifConst::LogAscii::include_meta; + use_json = zeek::BifConst::LogAscii::use_json; + enable_utf_8 = zeek::BifConst::LogAscii::enable_utf_8; + gzip_level = zeek::BifConst::LogAscii::gzip_level; separator.assign( - (const char*) BifConst::LogAscii::separator->Bytes(), - BifConst::LogAscii::separator->Len() + (const char*) zeek::BifConst::LogAscii::separator->Bytes(), + zeek::BifConst::LogAscii::separator->Len() ); set_separator.assign( - (const char*) BifConst::LogAscii::set_separator->Bytes(), - BifConst::LogAscii::set_separator->Len() + (const char*) zeek::BifConst::LogAscii::set_separator->Bytes(), + zeek::BifConst::LogAscii::set_separator->Len() ); empty_field.assign( - (const char*) BifConst::LogAscii::empty_field->Bytes(), - BifConst::LogAscii::empty_field->Len() + (const char*) zeek::BifConst::LogAscii::empty_field->Bytes(), + zeek::BifConst::LogAscii::empty_field->Len() ); unset_field.assign( - (const char*) BifConst::LogAscii::unset_field->Bytes(), - BifConst::LogAscii::unset_field->Len() + (const char*) zeek::BifConst::LogAscii::unset_field->Bytes(), + zeek::BifConst::LogAscii::unset_field->Len() ); meta_prefix.assign( - (const char*) BifConst::LogAscii::meta_prefix->Bytes(), - BifConst::LogAscii::meta_prefix->Len() + (const char*) zeek::BifConst::LogAscii::meta_prefix->Bytes(), + zeek::BifConst::LogAscii::meta_prefix->Len() ); ODesc tsfmt; - BifConst::LogAscii::json_timestamps->Describe(&tsfmt); + zeek::BifConst::LogAscii::json_timestamps->Describe(&tsfmt); json_timestamps.assign( (const char*) tsfmt.Bytes(), tsfmt.Len() ); gzip_file_extension.assign( - (const char*) BifConst::LogAscii::gzip_file_extension->Bytes(), - BifConst::LogAscii::gzip_file_extension->Len() + (const char*) zeek::BifConst::LogAscii::gzip_file_extension->Bytes(), + zeek::BifConst::LogAscii::gzip_file_extension->Len() ); } diff --git a/src/logging/writers/none/None.cc b/src/logging/writers/none/None.cc index a668dde3cc..3ab4f049aa 100644 --- a/src/logging/writers/none/None.cc +++ b/src/logging/writers/none/None.cc @@ -12,7 +12,7 @@ using namespace writer; bool None::DoInit(const WriterInfo& info, int num_fields, const threading::Field* const * fields) { - if ( BifConst::LogNone::debug ) + if ( zeek::BifConst::LogNone::debug ) { std::cout << "[logging::writer::None]" << std::endl; std::cout << " path=" << info.path << std::endl; diff --git a/src/logging/writers/sqlite/SQLite.cc b/src/logging/writers/sqlite/SQLite.cc index 5043ad75c6..b0ac37afa3 100644 --- a/src/logging/writers/sqlite/SQLite.cc +++ b/src/logging/writers/sqlite/SQLite.cc @@ -22,18 +22,18 @@ SQLite::SQLite(WriterFrontend* frontend) fields(), num_fields(), db(), st() { set_separator.assign( - (const char*) BifConst::LogSQLite::set_separator->Bytes(), - BifConst::LogSQLite::set_separator->Len() + (const char*) zeek::BifConst::LogSQLite::set_separator->Bytes(), + zeek::BifConst::LogSQLite::set_separator->Len() ); unset_field.assign( - (const char*) BifConst::LogSQLite::unset_field->Bytes(), - BifConst::LogSQLite::unset_field->Len() + (const char*) zeek::BifConst::LogSQLite::unset_field->Bytes(), + zeek::BifConst::LogSQLite::unset_field->Len() ); empty_field.assign( - (const char*) BifConst::LogSQLite::empty_field->Bytes(), - BifConst::LogSQLite::empty_field->Len() + (const char*) zeek::BifConst::LogSQLite::empty_field->Bytes(), + zeek::BifConst::LogSQLite::empty_field->Len() ); threading::formatter::Ascii::SeparatorInfo sep_info(string(), set_separator, unset_field, empty_field); diff --git a/src/main.cc b/src/main.cc index b107dd213c..3cd648a0aa 100644 --- a/src/main.cc +++ b/src/main.cc @@ -18,7 +18,7 @@ int main(int argc, char** argv) auto& options = setup_result.options; auto do_net_run = iosource_mgr->Size() > 0 || have_pending_timers || - BifConst::exit_only_after_terminate; + zeek::BifConst::exit_only_after_terminate; if ( do_net_run ) { diff --git a/src/threading/Manager.cc b/src/threading/Manager.cc index e5562a0ddd..d7d3676f95 100644 --- a/src/threading/Manager.cc +++ b/src/threading/Manager.cc @@ -125,7 +125,7 @@ void Manager::SendHeartbeats() void Manager::StartHeartbeatTimer() { heartbeat_timer_running = true; - timer_mgr->Add(new HeartbeatTimer(network_time + BifConst::Threading::heartbeat_interval)); + timer_mgr->Add(new HeartbeatTimer(network_time + zeek::BifConst::Threading::heartbeat_interval)); } void Manager::Flush() @@ -135,7 +135,7 @@ void Manager::Flush() if ( network_time && (network_time > next_beat || ! next_beat) ) { do_beat = true; - next_beat = ::network_time + BifConst::Threading::heartbeat_interval; + next_beat = ::network_time + zeek::BifConst::Threading::heartbeat_interval; } did_process = false; From ca1e5fe4be9aaea453273e484530e12f40d75d6c Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 14 May 2020 14:21:30 -0700 Subject: [PATCH 058/151] Replace deprecated usage of BifFunc:: with zeek::BifFunc:: Names of functions also changed slightly, like bro_fmt -> fmt_bif. Should generally be unusual/unexpected to see somone calling these directly from C++ in their plugin, but since technically possible in previous versions, I also removed the "private" restriction on accessing the BifReturnVal member. --- aux/bifcl | 2 +- src/Func.cc | 2 +- src/Func.h | 4 ---- src/Hash.h | 8 ++++---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/aux/bifcl b/aux/bifcl index 7fdbbfdf5e..2d56fd7e6d 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 7fdbbfdf5ee3669a77f73360b86326344e15ea99 +Subproject commit 2d56fd7e6d59aab754176b3ec90e71600d22d713 diff --git a/src/Func.cc b/src/Func.cc index 12a2d4eef8..1ae7e0b8a7 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -781,7 +781,7 @@ void init_builtin_funcs_subdirs() bool check_built_in_call(BuiltinFunc* f, CallExpr* call) { - if ( f->TheFunc() != BifFunc::bro_fmt ) + if ( f->TheFunc() != zeek::BifFunc::fmt_bif) return true; const expr_list& args = call->Args()->Exprs(); diff --git a/src/Func.h b/src/Func.h index dff2c9a36b..cc18471b1a 100644 --- a/src/Func.h +++ b/src/Func.h @@ -206,10 +206,6 @@ public: [[deprecated("Remove in v4.1. Return an IntrusivePtr instead.")]] BifReturnVal(Val* v) noexcept; -private: - - friend class BuiltinFunc; - IntrusivePtr rval; }; diff --git a/src/Hash.h b/src/Hash.h index 8e143e98f2..bff33c2b9f 100644 --- a/src/Hash.h +++ b/src/Hash.h @@ -30,9 +30,9 @@ class BroString; class Val; class Frame; class BifReturnVal; -namespace BifFunc { - extern BifReturnVal bro_md5_hmac(Frame* frame, const zeek::Args*); -} +namespace zeek { namespace BifFunc { + extern BifReturnVal md5_hmac_bif(Frame* frame, const zeek::Args*); +}} typedef uint64_t hash_t; typedef uint64_t hash64_t; @@ -196,7 +196,7 @@ private: inline static bool seeds_initialized = false; friend void hmac_md5(size_t size, const unsigned char* bytes, unsigned char digest[16]); - friend BifReturnVal BifFunc::bro_md5_hmac(Frame* frame, const zeek::Args*); + friend BifReturnVal zeek::BifFunc::md5_hmac_bif(Frame* frame, const zeek::Args*); }; typedef enum { From 7843416e510dcbabf21a8b8bf434c4157f194c01 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 14 May 2020 14:48:18 -0700 Subject: [PATCH 059/151] Use zeek::BifEvent:: for enqueue_ functions instead of BifEvent:: --- NEWS | 2 +- aux/bifcl | 2 +- .../bittorrent/bittorrent-analyzer.pac | 26 ++--- .../protocol/dce-rpc/dce_rpc-analyzer.pac | 14 +-- src/analyzer/protocol/dhcp/dhcp-analyzer.pac | 2 +- src/analyzer/protocol/dnp3/dnp3-analyzer.pac | 102 +++++++++--------- .../protocol/gssapi/gssapi-analyzer.pac | 2 +- .../protocol/gtpv1/gtpv1-analyzer.pac | 16 +-- src/analyzer/protocol/imap/imap-analyzer.pac | 4 +- src/analyzer/protocol/krb/krb-analyzer.pac | 20 ++-- .../protocol/modbus/modbus-analyzer.pac | 56 +++++----- .../protocol/mqtt/commands/connack.pac | 2 +- .../protocol/mqtt/commands/connect.pac | 2 +- .../protocol/mqtt/commands/disconnect.pac | 2 +- .../protocol/mqtt/commands/pingreq.pac | 2 +- .../protocol/mqtt/commands/pingresp.pac | 2 +- .../protocol/mqtt/commands/puback.pac | 2 +- .../protocol/mqtt/commands/pubcomp.pac | 2 +- .../protocol/mqtt/commands/publish.pac | 2 +- .../protocol/mqtt/commands/pubrec.pac | 2 +- .../protocol/mqtt/commands/pubrel.pac | 2 +- .../protocol/mqtt/commands/suback.pac | 2 +- .../protocol/mqtt/commands/subscribe.pac | 2 +- .../protocol/mqtt/commands/unsuback.pac | 2 +- .../protocol/mqtt/commands/unsubscribe.pac | 2 +- .../protocol/mysql/mysql-analyzer.pac | 18 ++-- src/analyzer/protocol/ntlm/ntlm-analyzer.pac | 6 +- src/analyzer/protocol/ntp/ntp-analyzer.pac | 2 +- .../protocol/radius/radius-analyzer.pac | 4 +- src/analyzer/protocol/rdp/RDP.cc | 2 +- src/analyzer/protocol/rdp/rdp-analyzer.pac | 20 ++-- src/analyzer/protocol/rdp/rdp-protocol.pac | 2 +- .../protocol/rdp/rdpeudp-analyzer.pac | 12 +-- src/analyzer/protocol/rfb/rfb-analyzer.pac | 14 +-- src/analyzer/protocol/sip/sip-analyzer.pac | 12 +-- .../protocol/smb/smb1-com-check-directory.pac | 4 +- src/analyzer/protocol/smb/smb1-com-close.pac | 2 +- .../smb/smb1-com-create-directory.pac | 4 +- src/analyzer/protocol/smb/smb1-com-echo.pac | 4 +- .../protocol/smb/smb1-com-logoff-andx.pac | 2 +- .../protocol/smb/smb1-com-negotiate.pac | 4 +- .../protocol/smb/smb1-com-nt-cancel.pac | 2 +- .../protocol/smb/smb1-com-nt-create-andx.pac | 6 +- .../smb/smb1-com-query-information.pac | 2 +- .../protocol/smb/smb1-com-read-andx.pac | 4 +- .../smb/smb1-com-session-setup-andx.pac | 4 +- .../smb/smb1-com-transaction-secondary.pac | 2 +- .../protocol/smb/smb1-com-transaction.pac | 4 +- .../smb/smb1-com-transaction2-secondary.pac | 2 +- .../protocol/smb/smb1-com-transaction2.pac | 10 +- .../smb/smb1-com-tree-connect-andx.pac | 4 +- .../protocol/smb/smb1-com-tree-disconnect.pac | 2 +- .../protocol/smb/smb1-com-write-andx.pac | 4 +- src/analyzer/protocol/smb/smb1-protocol.pac | 8 +- src/analyzer/protocol/smb/smb2-com-close.pac | 4 +- src/analyzer/protocol/smb/smb2-com-create.pac | 6 +- .../protocol/smb/smb2-com-negotiate.pac | 4 +- src/analyzer/protocol/smb/smb2-com-read.pac | 2 +- .../protocol/smb/smb2-com-session-setup.pac | 4 +- .../protocol/smb/smb2-com-set-info.pac | 28 ++--- .../smb/smb2-com-transform-header.pac | 2 +- .../protocol/smb/smb2-com-tree-connect.pac | 4 +- .../protocol/smb/smb2-com-tree-disconnect.pac | 4 +- src/analyzer/protocol/smb/smb2-com-write.pac | 4 +- src/analyzer/protocol/smb/smb2-protocol.pac | 2 +- src/analyzer/protocol/snmp/snmp-analyzer.pac | 26 ++--- .../protocol/socks/socks-analyzer.pac | 12 +-- src/analyzer/protocol/ssh/SSH.cc | 12 +-- src/analyzer/protocol/ssh/ssh-analyzer.pac | 16 +-- .../protocol/ssl/proc-client-hello.pac | 2 +- .../protocol/ssl/proc-server-hello.pac | 2 +- src/analyzer/protocol/ssl/ssl-analyzer.pac | 2 +- .../protocol/ssl/ssl-dtls-analyzer.pac | 12 +-- .../protocol/ssl/tls-handshake-analyzer.pac | 54 +++++----- .../protocol/syslog/syslog-analyzer.pac | 4 +- src/analyzer/protocol/xmpp/xmpp-analyzer.pac | 2 +- .../protocol-plugin/src/foo-analyzer.pac | 2 +- 77 files changed, 325 insertions(+), 325 deletions(-) diff --git a/NEWS b/NEWS index 8e131e2838..f9dba96980 100644 --- a/NEWS +++ b/NEWS @@ -128,7 +128,7 @@ Deprecated Functionality - ``Analyzer::BuildConnVal()`` is deprecated, use ``Analyzer::ConnVal()``. -- ``BifEvent::generate_`` functions are deprecated, use ``BifEvent::enqueue_``. +- ``BifEvent::generate_`` functions are deprecated, use ``zeek::BifEvent::enqueue_``. - ``binpac::bytestring_to_val()`` is deprecated, use ``binpac::to_stringval()``. diff --git a/aux/bifcl b/aux/bifcl index 2d56fd7e6d..b155d04585 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 2d56fd7e6d59aab754176b3ec90e71600d22d713 +Subproject commit b155d04585c61c8fdd0768e1f2a403b27447bb9d diff --git a/src/analyzer/protocol/bittorrent/bittorrent-analyzer.pac b/src/analyzer/protocol/bittorrent/bittorrent-analyzer.pac index 27ae99f0df..f6dbb95dda 100644 --- a/src/analyzer/protocol/bittorrent/bittorrent-analyzer.pac +++ b/src/analyzer/protocol/bittorrent/bittorrent-analyzer.pac @@ -61,7 +61,7 @@ flow BitTorrent_Flow(is_orig: bool) { handshake_ok = true; if ( ::bittorrent_peer_handshake ) { - BifEvent::enqueue_bittorrent_peer_handshake( + zeek::BifEvent::enqueue_bittorrent_peer_handshake( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), @@ -79,7 +79,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_keep_alive ) { - BifEvent::enqueue_bittorrent_peer_keep_alive( + zeek::BifEvent::enqueue_bittorrent_peer_keep_alive( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig()); @@ -92,7 +92,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_choke ) { - BifEvent::enqueue_bittorrent_peer_choke( + zeek::BifEvent::enqueue_bittorrent_peer_choke( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig()); @@ -105,7 +105,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_unchoke ) { - BifEvent::enqueue_bittorrent_peer_unchoke( + zeek::BifEvent::enqueue_bittorrent_peer_unchoke( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig()); @@ -118,7 +118,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_interested ) { - BifEvent::enqueue_bittorrent_peer_interested( + zeek::BifEvent::enqueue_bittorrent_peer_interested( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig()); @@ -131,7 +131,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_not_interested ) { - BifEvent::enqueue_bittorrent_peer_not_interested( + zeek::BifEvent::enqueue_bittorrent_peer_not_interested( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig()); @@ -144,7 +144,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_have ) { - BifEvent::enqueue_bittorrent_peer_have( + zeek::BifEvent::enqueue_bittorrent_peer_have( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), @@ -158,7 +158,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_bitfield ) { - BifEvent::enqueue_bittorrent_peer_bitfield( + zeek::BifEvent::enqueue_bittorrent_peer_bitfield( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), @@ -173,7 +173,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_request ) { - BifEvent::enqueue_bittorrent_peer_request( + zeek::BifEvent::enqueue_bittorrent_peer_request( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), @@ -188,7 +188,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_piece ) { - BifEvent::enqueue_bittorrent_peer_piece( + zeek::BifEvent::enqueue_bittorrent_peer_piece( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), @@ -203,7 +203,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_cancel ) { - BifEvent::enqueue_bittorrent_peer_cancel( + zeek::BifEvent::enqueue_bittorrent_peer_cancel( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), @@ -217,7 +217,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_port ) { - BifEvent::enqueue_bittorrent_peer_port( + zeek::BifEvent::enqueue_bittorrent_peer_port( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), @@ -231,7 +231,7 @@ flow BitTorrent_Flow(is_orig: bool) { %{ if ( ::bittorrent_peer_unknown ) { - BifEvent::enqueue_bittorrent_peer_unknown( + zeek::BifEvent::enqueue_bittorrent_peer_unknown( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), diff --git a/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac b/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac index 7dfff77119..c6bdbd3ab8 100644 --- a/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac +++ b/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac @@ -37,7 +37,7 @@ refine connection DCE_RPC_Conn += { %{ if ( dce_rpc_message ) { - BifEvent::enqueue_dce_rpc_message(bro_analyzer(), + zeek::BifEvent::enqueue_dce_rpc_message(bro_analyzer(), bro_analyzer()->Conn(), ${header.is_orig}, fid, @@ -51,7 +51,7 @@ refine connection DCE_RPC_Conn += { %{ if ( dce_rpc_bind ) { - BifEvent::enqueue_dce_rpc_bind(bro_analyzer(), + zeek::BifEvent::enqueue_dce_rpc_bind(bro_analyzer(), bro_analyzer()->Conn(), fid, ${req.id}, @@ -67,7 +67,7 @@ refine connection DCE_RPC_Conn += { %{ if ( dce_rpc_alter_context ) { - BifEvent::enqueue_dce_rpc_alter_context(bro_analyzer(), + zeek::BifEvent::enqueue_dce_rpc_alter_context(bro_analyzer(), bro_analyzer()->Conn(), fid, ${req.id}, @@ -92,7 +92,7 @@ refine connection DCE_RPC_Conn += { else sec_addr = make_intrusive(${bind.sec_addr}.length(), (const char*) ${bind.sec_addr}.begin()); - BifEvent::enqueue_dce_rpc_bind_ack(bro_analyzer(), + zeek::BifEvent::enqueue_dce_rpc_bind_ack(bro_analyzer(), bro_analyzer()->Conn(), fid, std::move(sec_addr)); @@ -104,7 +104,7 @@ refine connection DCE_RPC_Conn += { %{ if ( dce_rpc_alter_context_resp ) { - BifEvent::enqueue_dce_rpc_alter_context_resp(bro_analyzer(), + zeek::BifEvent::enqueue_dce_rpc_alter_context_resp(bro_analyzer(), bro_analyzer()->Conn(), fid); } @@ -115,7 +115,7 @@ refine connection DCE_RPC_Conn += { %{ if ( dce_rpc_request ) { - BifEvent::enqueue_dce_rpc_request(bro_analyzer(), + zeek::BifEvent::enqueue_dce_rpc_request(bro_analyzer(), bro_analyzer()->Conn(), fid, ${req.context_id}, @@ -132,7 +132,7 @@ refine connection DCE_RPC_Conn += { %{ if ( dce_rpc_response ) { - BifEvent::enqueue_dce_rpc_response(bro_analyzer(), + zeek::BifEvent::enqueue_dce_rpc_response(bro_analyzer(), bro_analyzer()->Conn(), fid, ${resp.context_id}, diff --git a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac index e8994436f8..37ab13e57c 100644 --- a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac +++ b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac @@ -91,7 +91,7 @@ refine flow DHCP_Flow += { init_options(); - BifEvent::enqueue_dhcp_message(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_dhcp_message(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.is_orig}, std::move(dhcp_msg_val), diff --git a/src/analyzer/protocol/dnp3/dnp3-analyzer.pac b/src/analyzer/protocol/dnp3/dnp3-analyzer.pac index 9ce8892790..189128b39d 100644 --- a/src/analyzer/protocol/dnp3/dnp3-analyzer.pac +++ b/src/analyzer/protocol/dnp3/dnp3-analyzer.pac @@ -29,7 +29,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_header_block ) { - BifEvent::enqueue_dnp3_header_block( + zeek::BifEvent::enqueue_dnp3_header_block( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), len, ctrl, dest_addr, src_addr); @@ -42,7 +42,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_application_request_header ) { - BifEvent::enqueue_dnp3_application_request_header( + zeek::BifEvent::enqueue_dnp3_application_request_header( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), @@ -57,7 +57,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_application_response_header ) { - BifEvent::enqueue_dnp3_application_response_header( + zeek::BifEvent::enqueue_dnp3_application_response_header( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), @@ -73,7 +73,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_object_header ) { - BifEvent::enqueue_dnp3_object_header( + zeek::BifEvent::enqueue_dnp3_object_header( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), obj_type, qua_field, number, rf_low, rf_high); @@ -86,7 +86,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_object_prefix ) { - BifEvent::enqueue_dnp3_object_prefix( + zeek::BifEvent::enqueue_dnp3_object_prefix( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), prefix_value); @@ -99,7 +99,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_response_data_object ) { - BifEvent::enqueue_dnp3_response_data_object( + zeek::BifEvent::enqueue_dnp3_response_data_object( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), data_value); @@ -113,7 +113,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_attribute_common ) { - BifEvent::enqueue_dnp3_attribute_common( + zeek::BifEvent::enqueue_dnp3_attribute_common( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), data_type_code, leng, to_stringval(attribute_obj) ); @@ -127,7 +127,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_crob ) { - BifEvent::enqueue_dnp3_crob( + zeek::BifEvent::enqueue_dnp3_crob( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), control_code, count8, on_time, off_time, status_code); @@ -141,7 +141,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_pcb ) { - BifEvent::enqueue_dnp3_pcb( + zeek::BifEvent::enqueue_dnp3_pcb( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), control_code, count8, on_time, off_time, status_code); @@ -155,7 +155,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_counter_32wFlag ) { - BifEvent::enqueue_dnp3_counter_32wFlag( + zeek::BifEvent::enqueue_dnp3_counter_32wFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, count_value); @@ -169,7 +169,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_counter_16wFlag ) { - BifEvent::enqueue_dnp3_counter_16wFlag( + zeek::BifEvent::enqueue_dnp3_counter_16wFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, count_value); @@ -183,7 +183,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_counter_32woFlag ) { - BifEvent::enqueue_dnp3_counter_32woFlag( + zeek::BifEvent::enqueue_dnp3_counter_32woFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), count_value); @@ -197,7 +197,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_counter_16woFlag ) { - BifEvent::enqueue_dnp3_counter_16woFlag( + zeek::BifEvent::enqueue_dnp3_counter_16woFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), count_value); @@ -211,7 +211,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_counter_32wFlag ) { - BifEvent::enqueue_dnp3_frozen_counter_32wFlag( + zeek::BifEvent::enqueue_dnp3_frozen_counter_32wFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, count_value); @@ -225,7 +225,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_counter_16wFlag ) { - BifEvent::enqueue_dnp3_frozen_counter_16wFlag( + zeek::BifEvent::enqueue_dnp3_frozen_counter_16wFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, count_value); @@ -239,7 +239,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_counter_32wFlagTime ) { - BifEvent::enqueue_dnp3_frozen_counter_32wFlagTime( + zeek::BifEvent::enqueue_dnp3_frozen_counter_32wFlagTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, count_value, bytestring_to_time(time48)); @@ -253,7 +253,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_counter_16wFlagTime ) { - BifEvent::enqueue_dnp3_frozen_counter_16wFlagTime( + zeek::BifEvent::enqueue_dnp3_frozen_counter_16wFlagTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, count_value, bytestring_to_time(time48)); @@ -267,7 +267,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_counter_32woFlag ) { - BifEvent::enqueue_dnp3_frozen_counter_32woFlag( + zeek::BifEvent::enqueue_dnp3_frozen_counter_32woFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), count_value); @@ -281,7 +281,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_counter_16woFlag ) { - BifEvent::enqueue_dnp3_frozen_counter_16woFlag( + zeek::BifEvent::enqueue_dnp3_frozen_counter_16woFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), count_value); @@ -295,7 +295,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_32wFlag ) { - BifEvent::enqueue_dnp3_analog_input_32wFlag( + zeek::BifEvent::enqueue_dnp3_analog_input_32wFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value); @@ -309,7 +309,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_16wFlag ) { - BifEvent::enqueue_dnp3_analog_input_16wFlag( + zeek::BifEvent::enqueue_dnp3_analog_input_16wFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value); @@ -323,7 +323,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_32woFlag ) { - BifEvent::enqueue_dnp3_analog_input_32woFlag( + zeek::BifEvent::enqueue_dnp3_analog_input_32woFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), value); @@ -337,7 +337,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_16woFlag ) { - BifEvent::enqueue_dnp3_analog_input_16woFlag( + zeek::BifEvent::enqueue_dnp3_analog_input_16woFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), value); @@ -351,7 +351,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_SPwFlag ) { - BifEvent::enqueue_dnp3_analog_input_SPwFlag( + zeek::BifEvent::enqueue_dnp3_analog_input_SPwFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value); @@ -365,7 +365,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_DPwFlag ) { - BifEvent::enqueue_dnp3_analog_input_DPwFlag( + zeek::BifEvent::enqueue_dnp3_analog_input_DPwFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value_low, value_high); @@ -379,7 +379,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_32wFlag ) { - BifEvent::enqueue_dnp3_frozen_analog_input_32wFlag( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_32wFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value); @@ -393,7 +393,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_16wFlag ) { - BifEvent::enqueue_dnp3_frozen_analog_input_16wFlag( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_16wFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value); @@ -407,7 +407,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_32wTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_32wTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_32wTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value, bytestring_to_time(time48)); @@ -421,7 +421,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_16wTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_16wTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_16wTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value, bytestring_to_time(time48)); @@ -435,7 +435,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_32woFlag ) { - BifEvent::enqueue_dnp3_frozen_analog_input_32woFlag( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_32woFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), frozen_value); @@ -449,7 +449,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_16woFlag ) { - BifEvent::enqueue_dnp3_frozen_analog_input_16woFlag( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_16woFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), frozen_value); @@ -463,7 +463,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_SPwFlag ) { - BifEvent::enqueue_dnp3_frozen_analog_input_SPwFlag( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_SPwFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value); @@ -477,7 +477,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_DPwFlag ) { - BifEvent::enqueue_dnp3_frozen_analog_input_DPwFlag( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_DPwFlag( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value_low, frozen_value_high); @@ -491,7 +491,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_event_32woTime ) { - BifEvent::enqueue_dnp3_analog_input_event_32woTime( + zeek::BifEvent::enqueue_dnp3_analog_input_event_32woTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value); @@ -505,7 +505,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_event_16woTime ) { - BifEvent::enqueue_dnp3_analog_input_event_16woTime( + zeek::BifEvent::enqueue_dnp3_analog_input_event_16woTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value); @@ -519,7 +519,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_event_32wTime ) { - BifEvent::enqueue_dnp3_analog_input_event_32wTime( + zeek::BifEvent::enqueue_dnp3_analog_input_event_32wTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value, bytestring_to_time(time48)); @@ -533,7 +533,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_event_16wTime ) { - BifEvent::enqueue_dnp3_analog_input_event_16wTime( + zeek::BifEvent::enqueue_dnp3_analog_input_event_16wTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value, bytestring_to_time(time48)); @@ -547,7 +547,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_event_SPwoTime ) { - BifEvent::enqueue_dnp3_analog_input_event_SPwoTime( + zeek::BifEvent::enqueue_dnp3_analog_input_event_SPwoTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value); @@ -561,7 +561,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_event_DPwoTime ) { - BifEvent::enqueue_dnp3_analog_input_event_DPwoTime( + zeek::BifEvent::enqueue_dnp3_analog_input_event_DPwoTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value_low, value_high); @@ -575,7 +575,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_event_SPwTime ) { - BifEvent::enqueue_dnp3_analog_input_event_SPwTime( + zeek::BifEvent::enqueue_dnp3_analog_input_event_SPwTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value, bytestring_to_time(time48)); @@ -589,7 +589,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_analog_input_event_DPwTime ) { - BifEvent::enqueue_dnp3_analog_input_event_DPwTime( + zeek::BifEvent::enqueue_dnp3_analog_input_event_DPwTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, value_low, value_high, bytestring_to_time(time48)); @@ -603,7 +603,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_event_32woTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_event_32woTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_event_32woTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value); @@ -617,7 +617,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_event_16woTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_event_16woTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_event_16woTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value); @@ -631,7 +631,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_event_32wTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_event_32wTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_event_32wTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value, bytestring_to_time(time48)); @@ -645,7 +645,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_event_16wTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_event_16wTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_event_16wTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value, bytestring_to_time(time48)); @@ -659,7 +659,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_event_SPwoTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_event_SPwoTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_event_SPwoTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value); @@ -673,7 +673,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_event_DPwoTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_event_DPwoTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_event_DPwoTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value_low, frozen_value_high); @@ -687,7 +687,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_event_SPwTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_event_SPwTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_event_SPwTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value, bytestring_to_time(time48)); @@ -701,7 +701,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_frozen_analog_input_event_DPwTime ) { - BifEvent::enqueue_dnp3_frozen_analog_input_event_DPwTime( + zeek::BifEvent::enqueue_dnp3_frozen_analog_input_event_DPwTime( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), flag, frozen_value_low, frozen_value_high, bytestring_to_time(time48)); @@ -715,7 +715,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_file_transport ) { - BifEvent::enqueue_dnp3_file_transport( + zeek::BifEvent::enqueue_dnp3_file_transport( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), file_handle, block_num, to_stringval(file_data)); @@ -729,7 +729,7 @@ flow DNP3_Flow(is_orig: bool) { %{ if ( ::dnp3_debug_byte ) { - BifEvent::enqueue_dnp3_debug_byte ( + zeek::BifEvent::enqueue_dnp3_debug_byte ( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), to_stringval(debug)); diff --git a/src/analyzer/protocol/gssapi/gssapi-analyzer.pac b/src/analyzer/protocol/gssapi/gssapi-analyzer.pac index b92468c04d..48c3e086fd 100644 --- a/src/analyzer/protocol/gssapi/gssapi-analyzer.pac +++ b/src/analyzer/protocol/gssapi/gssapi-analyzer.pac @@ -61,7 +61,7 @@ refine connection GSSAPI_Conn += { %{ if ( gssapi_neg_result ) { - BifEvent::enqueue_gssapi_neg_result(bro_analyzer(), + zeek::BifEvent::enqueue_gssapi_neg_result(bro_analyzer(), bro_analyzer()->Conn(), binary_to_int64(${val.neg_state.encoding.content})); } diff --git a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac index e91d4499b3..f4daeb8c0c 100644 --- a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac +++ b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac @@ -328,7 +328,7 @@ void CreatePDP_Request(const BroAnalyzer& a, const GTPv1_Header* pdu) } } - BifEvent::enqueue_gtpv1_create_pdp_ctx_request(a, a->Conn(), + zeek::BifEvent::enqueue_gtpv1_create_pdp_ctx_request(a, a->Conn(), BuildGTPv1Hdr(pdu), std::move(rv)); } @@ -397,7 +397,7 @@ void CreatePDP_Response(const BroAnalyzer& a, const GTPv1_Header* pdu) } } - BifEvent::enqueue_gtpv1_create_pdp_ctx_response(a, a->Conn(), + zeek::BifEvent::enqueue_gtpv1_create_pdp_ctx_response(a, a->Conn(), BuildGTPv1Hdr(pdu), std::move(rv)); } @@ -475,7 +475,7 @@ void UpdatePDP_Request(const BroAnalyzer& a, const GTPv1_Header* pdu) } } - BifEvent::enqueue_gtpv1_update_pdp_ctx_request(a, a->Conn(), + zeek::BifEvent::enqueue_gtpv1_update_pdp_ctx_request(a, a->Conn(), BuildGTPv1Hdr(pdu), std::move(rv)); } @@ -535,7 +535,7 @@ void UpdatePDP_Response(const BroAnalyzer& a, const GTPv1_Header* pdu) } } - BifEvent::enqueue_gtpv1_update_pdp_ctx_response(a, a->Conn(), + zeek::BifEvent::enqueue_gtpv1_update_pdp_ctx_response(a, a->Conn(), BuildGTPv1Hdr(pdu), std::move(rv)); } @@ -569,7 +569,7 @@ void DeletePDP_Request(const BroAnalyzer& a, const GTPv1_Header* pdu) } } - BifEvent::enqueue_gtpv1_delete_pdp_ctx_request(a, a->Conn(), + zeek::BifEvent::enqueue_gtpv1_delete_pdp_ctx_request(a, a->Conn(), BuildGTPv1Hdr(pdu), std::move(rv)); } @@ -600,7 +600,7 @@ void DeletePDP_Response(const BroAnalyzer& a, const GTPv1_Header* pdu) } } - BifEvent::enqueue_gtpv1_delete_pdp_ctx_response(a, a->Conn(), + zeek::BifEvent::enqueue_gtpv1_delete_pdp_ctx_response(a, a->Conn(), BuildGTPv1Hdr(pdu), std::move(rv)); } %} @@ -679,7 +679,7 @@ flow GTPv1_Flow(is_orig: bool) } if ( ::gtpv1_message ) - BifEvent::enqueue_gtpv1_message(a, c, BuildGTPv1Hdr(pdu)); + zeek::BifEvent::enqueue_gtpv1_message(a, c, BuildGTPv1Hdr(pdu)); switch ( ${pdu.msg_type} ) { case 16: @@ -759,7 +759,7 @@ flow GTPv1_Flow(is_orig: bool) } if ( ::gtpv1_g_pdu_packet ) - BifEvent::enqueue_gtpv1_g_pdu_packet(a, c, BuildGTPv1Hdr(pdu), + zeek::BifEvent::enqueue_gtpv1_g_pdu_packet(a, c, BuildGTPv1Hdr(pdu), inner->ToPktHdrVal()); EncapsulatingConn ec(c, BifEnum::Tunnel::GTPv1); diff --git a/src/analyzer/protocol/imap/imap-analyzer.pac b/src/analyzer/protocol/imap/imap-analyzer.pac index b8fe0652ec..677e3789ec 100644 --- a/src/analyzer/protocol/imap/imap-analyzer.pac +++ b/src/analyzer/protocol/imap/imap-analyzer.pac @@ -45,7 +45,7 @@ refine connection IMAP_Conn += { bro_analyzer()->StartTLS(); if ( imap_starttls ) - BifEvent::enqueue_imap_starttls(bro_analyzer(), bro_analyzer()->Conn()); + zeek::BifEvent::enqueue_imap_starttls(bro_analyzer(), bro_analyzer()->Conn()); } else reporter->Weird(bro_analyzer()->Conn(), "IMAP: server refused StartTLS"); @@ -67,7 +67,7 @@ refine connection IMAP_Conn += { capv->Assign(i, make_intrusive(capability.length(), (const char*)capability.data())); } - BifEvent::enqueue_imap_capabilities(bro_analyzer(), bro_analyzer()->Conn(), std::move(capv)); + zeek::BifEvent::enqueue_imap_capabilities(bro_analyzer(), bro_analyzer()->Conn(), std::move(capv)); return true; %} diff --git a/src/analyzer/protocol/krb/krb-analyzer.pac b/src/analyzer/protocol/krb/krb-analyzer.pac index d36f721b44..ebc07a0f3a 100644 --- a/src/analyzer/protocol/krb/krb-analyzer.pac +++ b/src/analyzer/protocol/krb/krb-analyzer.pac @@ -180,7 +180,7 @@ refine connection KRB_Conn += { return false; RecordVal* rv = proc_krb_kdc_req_arguments(${msg}, bro_analyzer()); - BifEvent::enqueue_krb_as_request(bro_analyzer(), bro_analyzer()->Conn(), {AdoptRef{}, rv}); + zeek::BifEvent::enqueue_krb_as_request(bro_analyzer(), bro_analyzer()->Conn(), {AdoptRef{}, rv}); return true; } @@ -190,7 +190,7 @@ refine connection KRB_Conn += { return false; RecordVal* rv = proc_krb_kdc_req_arguments(${msg}, bro_analyzer()); - BifEvent::enqueue_krb_tgs_request(bro_analyzer(), bro_analyzer()->Conn(), {AdoptRef{}, rv}); + zeek::BifEvent::enqueue_krb_tgs_request(bro_analyzer(), bro_analyzer()->Conn(), {AdoptRef{}, rv}); return true; } @@ -223,7 +223,7 @@ refine connection KRB_Conn += { if ( ! krb_as_response ) return false; - BifEvent::enqueue_krb_as_response(bro_analyzer(), bro_analyzer()->Conn(), make_arg()); + zeek::BifEvent::enqueue_krb_as_response(bro_analyzer(), bro_analyzer()->Conn(), make_arg()); return true; } @@ -232,7 +232,7 @@ refine connection KRB_Conn += { if ( ! krb_tgs_response ) return false; - BifEvent::enqueue_krb_tgs_response(bro_analyzer(), bro_analyzer()->Conn(), make_arg()); + zeek::BifEvent::enqueue_krb_tgs_response(bro_analyzer(), bro_analyzer()->Conn(), make_arg()); return true; } @@ -248,7 +248,7 @@ refine connection KRB_Conn += { proc_error_arguments(rv.get(), ${msg.args1}, 0); rv->Assign(4, asn1_integer_to_val(${msg.error_code}, TYPE_COUNT)); proc_error_arguments(rv.get(), ${msg.args2}, binary_to_int64(${msg.error_code.encoding.content})); - BifEvent::enqueue_krb_error(bro_analyzer(), bro_analyzer()->Conn(), std::move(rv)); + zeek::BifEvent::enqueue_krb_error(bro_analyzer(), bro_analyzer()->Conn(), std::move(rv)); } return true; %} @@ -268,7 +268,7 @@ refine connection KRB_Conn += { if ( authenticationinfo ) rvticket->Assign(5, authenticationinfo); - BifEvent::enqueue_krb_ap_request(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_krb_ap_request(bro_analyzer(), bro_analyzer()->Conn(), std::move(rvticket), std::move(rv)); } return true; @@ -279,7 +279,7 @@ refine connection KRB_Conn += { bro_analyzer()->ProtocolConfirmation(); if ( krb_ap_response ) { - BifEvent::enqueue_krb_ap_response(bro_analyzer(), bro_analyzer()->Conn()); + zeek::BifEvent::enqueue_krb_ap_response(bro_analyzer(), bro_analyzer()->Conn()); } return true; %} @@ -337,7 +337,7 @@ refine connection KRB_Conn += { break; } } - BifEvent::enqueue_krb_safe(bro_analyzer(), bro_analyzer()->Conn(), ${msg.is_orig}, std::move(rv)); + zeek::BifEvent::enqueue_krb_safe(bro_analyzer(), bro_analyzer()->Conn(), ${msg.is_orig}, std::move(rv)); } return true; %} @@ -347,7 +347,7 @@ refine connection KRB_Conn += { bro_analyzer()->ProtocolConfirmation(); if ( krb_priv ) { - BifEvent::enqueue_krb_priv(bro_analyzer(), bro_analyzer()->Conn(), ${msg.is_orig}); + zeek::BifEvent::enqueue_krb_priv(bro_analyzer(), bro_analyzer()->Conn(), ${msg.is_orig}); } return true; %} @@ -357,7 +357,7 @@ refine connection KRB_Conn += { bro_analyzer()->ProtocolConfirmation(); if ( krb_cred ) { - BifEvent::enqueue_krb_cred(bro_analyzer(), bro_analyzer()->Conn(), ${msg.is_orig}, + zeek::BifEvent::enqueue_krb_cred(bro_analyzer(), bro_analyzer()->Conn(), ${msg.is_orig}, proc_tickets(${msg.tickets})); } return true; diff --git a/src/analyzer/protocol/modbus/modbus-analyzer.pac b/src/analyzer/protocol/modbus/modbus-analyzer.pac index 52e9d41838..9d5de6a705 100644 --- a/src/analyzer/protocol/modbus/modbus-analyzer.pac +++ b/src/analyzer/protocol/modbus/modbus-analyzer.pac @@ -88,7 +88,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_message ) { - BifEvent::enqueue_modbus_message(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_message(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), is_orig()); @@ -117,7 +117,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_exception ) { - BifEvent::enqueue_modbus_exception(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_exception(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.code}); @@ -131,7 +131,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_read_coils_request ) { - BifEvent::enqueue_modbus_read_coils_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_coils_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.start_address}, @@ -146,7 +146,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_read_coils_response ) { - BifEvent::enqueue_modbus_read_coils_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_coils_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), bytestring_to_coils(${message.bits}, ${message.bits}.length()*8)); @@ -159,7 +159,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_read_discrete_inputs_request ) { - BifEvent::enqueue_modbus_read_discrete_inputs_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_discrete_inputs_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.start_address}, ${message.quantity}); @@ -173,7 +173,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_read_discrete_inputs_response ) { - BifEvent::enqueue_modbus_read_discrete_inputs_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_discrete_inputs_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), bytestring_to_coils(${message.bits}, ${message.bits}.length()*8)); @@ -188,7 +188,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_read_holding_registers_request ) { - BifEvent::enqueue_modbus_read_holding_registers_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_holding_registers_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.start_address}, ${message.quantity}); @@ -217,7 +217,7 @@ refine flow ModbusTCP_Flow += { t->Assign(i, r); } - BifEvent::enqueue_modbus_read_holding_registers_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_holding_registers_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), std::move(t)); @@ -232,7 +232,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_read_input_registers_request ) { - BifEvent::enqueue_modbus_read_input_registers_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_input_registers_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.start_address}, ${message.quantity}); @@ -261,7 +261,7 @@ refine flow ModbusTCP_Flow += { t->Assign(i, r); } - BifEvent::enqueue_modbus_read_input_registers_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_input_registers_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), std::move(t)); @@ -288,7 +288,7 @@ refine flow ModbusTCP_Flow += { return false; } - BifEvent::enqueue_modbus_write_single_coil_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_single_coil_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.address}, @@ -315,7 +315,7 @@ refine flow ModbusTCP_Flow += { return false; } - BifEvent::enqueue_modbus_write_single_coil_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_single_coil_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.address}, @@ -331,7 +331,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_write_single_register_request ) { - BifEvent::enqueue_modbus_write_single_register_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_single_register_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.address}, ${message.value}); @@ -345,7 +345,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_write_single_register_response ) { - BifEvent::enqueue_modbus_write_single_register_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_single_register_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.address}, ${message.value}); @@ -360,7 +360,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_write_multiple_coils_request ) { - BifEvent::enqueue_modbus_write_multiple_coils_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_multiple_coils_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.start_address}, @@ -375,7 +375,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_write_multiple_coils_response ) { - BifEvent::enqueue_modbus_write_multiple_coils_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_multiple_coils_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.start_address}, ${message.quantity}); @@ -405,7 +405,7 @@ refine flow ModbusTCP_Flow += { t->Assign(i, r); } - BifEvent::enqueue_modbus_write_multiple_registers_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_multiple_registers_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.start_address}, std::move(t)); @@ -419,7 +419,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_write_multiple_registers_response ) { - BifEvent::enqueue_modbus_write_multiple_registers_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_multiple_registers_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.start_address}, ${message.quantity}); @@ -447,7 +447,7 @@ refine flow ModbusTCP_Flow += { // t->Assign(i, l); // } - BifEvent::enqueue_modbus_read_file_record_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_file_record_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header)); } @@ -468,7 +468,7 @@ refine flow ModbusTCP_Flow += { // t->Assign(i, r); // } - BifEvent::enqueue_modbus_read_file_record_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_file_record_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header)); } @@ -500,7 +500,7 @@ refine flow ModbusTCP_Flow += { // } // } - BifEvent::enqueue_modbus_write_file_record_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_file_record_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header)); } @@ -532,7 +532,7 @@ refine flow ModbusTCP_Flow += { // t->Assign(i, k); // } - BifEvent::enqueue_modbus_write_file_record_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_write_file_record_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header)); } @@ -545,7 +545,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_mask_write_register_request ) { - BifEvent::enqueue_modbus_mask_write_register_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_mask_write_register_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.address}, @@ -560,7 +560,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_mask_write_register_response ) { - BifEvent::enqueue_modbus_mask_write_register_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_mask_write_register_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.address}, @@ -590,7 +590,7 @@ refine flow ModbusTCP_Flow += { t->Assign(i, r); } - BifEvent::enqueue_modbus_read_write_multiple_registers_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_write_multiple_registers_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.read_start_address}, @@ -622,7 +622,7 @@ refine flow ModbusTCP_Flow += { t->Assign(i, r); } - BifEvent::enqueue_modbus_read_write_multiple_registers_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_write_multiple_registers_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), std::move(t)); @@ -636,7 +636,7 @@ refine flow ModbusTCP_Flow += { %{ if ( ::modbus_read_fifo_queue_request ) { - BifEvent::enqueue_modbus_read_fifo_queue_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_fifo_queue_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), ${message.start_address}); @@ -666,7 +666,7 @@ refine flow ModbusTCP_Flow += { t->Assign(i, r); } - BifEvent::enqueue_modbus_read_fifo_queue_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_modbus_read_fifo_queue_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), HeaderToVal(header), std::move(t)); diff --git a/src/analyzer/protocol/mqtt/commands/connack.pac b/src/analyzer/protocol/mqtt/commands/connack.pac index 98ac7c4122..c2954efa8a 100644 --- a/src/analyzer/protocol/mqtt/commands/connack.pac +++ b/src/analyzer/protocol/mqtt/commands/connack.pac @@ -18,7 +18,7 @@ refine flow MQTT_Flow += { auto m = make_intrusive(zeek::BifType::Record::MQTT::ConnectAckMsg); m->Assign(0, val_mgr->Count(${msg.return_code})); m->Assign(1, val_mgr->Bool(${msg.session_present})); - BifEvent::enqueue_mqtt_connack(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_connack(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(m)); } diff --git a/src/analyzer/protocol/mqtt/commands/connect.pac b/src/analyzer/protocol/mqtt/commands/connect.pac index 4c4f5374a3..407313cc8a 100644 --- a/src/analyzer/protocol/mqtt/commands/connect.pac +++ b/src/analyzer/protocol/mqtt/commands/connect.pac @@ -75,7 +75,7 @@ refine flow MQTT_Flow += { reinterpret_cast(${msg.pass.str}.begin()))); } - BifEvent::enqueue_mqtt_connect(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_connect(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(m)); } diff --git a/src/analyzer/protocol/mqtt/commands/disconnect.pac b/src/analyzer/protocol/mqtt/commands/disconnect.pac index d9f49e20c6..8a3050a3a9 100644 --- a/src/analyzer/protocol/mqtt/commands/disconnect.pac +++ b/src/analyzer/protocol/mqtt/commands/disconnect.pac @@ -11,7 +11,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_disconnect ) { - BifEvent::enqueue_mqtt_disconnect(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_disconnect(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn()); } diff --git a/src/analyzer/protocol/mqtt/commands/pingreq.pac b/src/analyzer/protocol/mqtt/commands/pingreq.pac index 2c436f0091..3aad0b854d 100644 --- a/src/analyzer/protocol/mqtt/commands/pingreq.pac +++ b/src/analyzer/protocol/mqtt/commands/pingreq.pac @@ -11,7 +11,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_pingreq ) { - BifEvent::enqueue_mqtt_pingreq(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_pingreq(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn()); } diff --git a/src/analyzer/protocol/mqtt/commands/pingresp.pac b/src/analyzer/protocol/mqtt/commands/pingresp.pac index a4295775a5..dc0cb227ba 100644 --- a/src/analyzer/protocol/mqtt/commands/pingresp.pac +++ b/src/analyzer/protocol/mqtt/commands/pingresp.pac @@ -11,7 +11,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_pingresp ) { - BifEvent::enqueue_mqtt_pingresp(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_pingresp(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn()); } diff --git a/src/analyzer/protocol/mqtt/commands/puback.pac b/src/analyzer/protocol/mqtt/commands/puback.pac index b8a6ef57fe..1a3e6454fe 100644 --- a/src/analyzer/protocol/mqtt/commands/puback.pac +++ b/src/analyzer/protocol/mqtt/commands/puback.pac @@ -13,7 +13,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_puback ) { - BifEvent::enqueue_mqtt_puback(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_puback(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig, ${msg.msg_id}); diff --git a/src/analyzer/protocol/mqtt/commands/pubcomp.pac b/src/analyzer/protocol/mqtt/commands/pubcomp.pac index f1cf1657a0..28e5650efe 100644 --- a/src/analyzer/protocol/mqtt/commands/pubcomp.pac +++ b/src/analyzer/protocol/mqtt/commands/pubcomp.pac @@ -13,7 +13,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_pubcomp ) { - BifEvent::enqueue_mqtt_pubcomp(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_pubcomp(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig, ${msg.msg_id}); diff --git a/src/analyzer/protocol/mqtt/commands/publish.pac b/src/analyzer/protocol/mqtt/commands/publish.pac index ecb1d3e380..ea8e60198e 100644 --- a/src/analyzer/protocol/mqtt/commands/publish.pac +++ b/src/analyzer/protocol/mqtt/commands/publish.pac @@ -42,7 +42,7 @@ refine flow MQTT_Flow += { m->Assign(5, val_mgr->Count(${msg.payload}.length())); - BifEvent::enqueue_mqtt_publish(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_publish(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${pdu.is_orig}, ${msg.qos} == 0 ? 0 : ${msg.msg_id}, diff --git a/src/analyzer/protocol/mqtt/commands/pubrec.pac b/src/analyzer/protocol/mqtt/commands/pubrec.pac index 84724db804..7aa128ad3c 100644 --- a/src/analyzer/protocol/mqtt/commands/pubrec.pac +++ b/src/analyzer/protocol/mqtt/commands/pubrec.pac @@ -13,7 +13,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_pubrec ) { - BifEvent::enqueue_mqtt_pubrec(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_pubrec(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig, ${msg.msg_id}); diff --git a/src/analyzer/protocol/mqtt/commands/pubrel.pac b/src/analyzer/protocol/mqtt/commands/pubrel.pac index 0f329eb3dd..1c11d61289 100644 --- a/src/analyzer/protocol/mqtt/commands/pubrel.pac +++ b/src/analyzer/protocol/mqtt/commands/pubrel.pac @@ -13,7 +13,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_pubrel ) { - BifEvent::enqueue_mqtt_pubrel(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_pubrel(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig, ${msg.msg_id}); diff --git a/src/analyzer/protocol/mqtt/commands/suback.pac b/src/analyzer/protocol/mqtt/commands/suback.pac index 1f0adf5e32..79f4d09a05 100644 --- a/src/analyzer/protocol/mqtt/commands/suback.pac +++ b/src/analyzer/protocol/mqtt/commands/suback.pac @@ -14,7 +14,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_suback ) { - BifEvent::enqueue_mqtt_suback(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_suback(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.msg_id}, ${msg.granted_QoS}); diff --git a/src/analyzer/protocol/mqtt/commands/subscribe.pac b/src/analyzer/protocol/mqtt/commands/subscribe.pac index a6d9b01dd8..75015bffc7 100644 --- a/src/analyzer/protocol/mqtt/commands/subscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/subscribe.pac @@ -31,7 +31,7 @@ refine flow MQTT_Flow += { qos_levels->Assign(qos_levels->Size(), qos); } - BifEvent::enqueue_mqtt_subscribe(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_subscribe(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.msg_id}, std::move(topics), diff --git a/src/analyzer/protocol/mqtt/commands/unsuback.pac b/src/analyzer/protocol/mqtt/commands/unsuback.pac index 3c368188a3..168d55e1bd 100644 --- a/src/analyzer/protocol/mqtt/commands/unsuback.pac +++ b/src/analyzer/protocol/mqtt/commands/unsuback.pac @@ -13,7 +13,7 @@ refine flow MQTT_Flow += { %{ if ( mqtt_unsuback ) { - BifEvent::enqueue_mqtt_unsuback(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_unsuback(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.msg_id}); } diff --git a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac index 15342aef85..45f68f8d8b 100644 --- a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac @@ -23,7 +23,7 @@ refine flow MQTT_Flow += { topics->Assign(topics->Size(), unsubscribe_topic); } - BifEvent::enqueue_mqtt_unsubscribe(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mqtt_unsubscribe(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.msg_id}, std::move(topics)); diff --git a/src/analyzer/protocol/mysql/mysql-analyzer.pac b/src/analyzer/protocol/mysql/mysql-analyzer.pac index 3e5ef0afd6..8c94ecdec6 100644 --- a/src/analyzer/protocol/mysql/mysql-analyzer.pac +++ b/src/analyzer/protocol/mysql/mysql-analyzer.pac @@ -6,11 +6,11 @@ refine flow MySQL_Flow += { if ( mysql_server_version ) { if ( ${msg.version} == 10 ) - BifEvent::enqueue_mysql_server_version(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mysql_server_version(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), make_intrusive(c_str(${msg.handshake10.server_version}))); if ( ${msg.version} == 9 ) - BifEvent::enqueue_mysql_server_version(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mysql_server_version(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), make_intrusive(c_str(${msg.handshake9.server_version}))); } @@ -25,11 +25,11 @@ refine flow MySQL_Flow += { if ( mysql_handshake ) { if ( ${msg.version} == 10 ) - BifEvent::enqueue_mysql_handshake(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mysql_handshake(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), make_intrusive(c_str(${msg.v10_response.username}))); if ( ${msg.version} == 9 ) - BifEvent::enqueue_mysql_handshake(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mysql_handshake(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), make_intrusive(c_str(${msg.v9_response.username}))); } @@ -39,7 +39,7 @@ refine flow MySQL_Flow += { function proc_mysql_command_request_packet(msg: Command_Request_Packet): bool %{ if ( mysql_command_request ) - BifEvent::enqueue_mysql_command_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mysql_command_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.command}, to_stringval(${msg.arg})); @@ -49,7 +49,7 @@ refine flow MySQL_Flow += { function proc_err_packet(msg: ERR_Packet): bool %{ if ( mysql_error ) - BifEvent::enqueue_mysql_error(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mysql_error(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.code}, to_stringval(${msg.msg})); @@ -59,7 +59,7 @@ refine flow MySQL_Flow += { function proc_ok_packet(msg: OK_Packet): bool %{ if ( mysql_ok ) - BifEvent::enqueue_mysql_ok(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mysql_ok(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.rows}); return true; @@ -71,7 +71,7 @@ refine flow MySQL_Flow += { { // This is a bit fake... if ( mysql_ok ) - BifEvent::enqueue_mysql_ok(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mysql_ok(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), 0); } @@ -98,7 +98,7 @@ refine flow MySQL_Flow += { vv->Assign(vv->Size(), make_intrusive(bstring.length(), ptr)); } - BifEvent::enqueue_mysql_result_row(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_mysql_result_row(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(vv)); diff --git a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac index 50d52c5a7d..c95e90982d 100644 --- a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac +++ b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac @@ -122,7 +122,7 @@ refine connection NTLM_Conn += { if ( ${val}->has_version() ) result->Assign(3, build_version_record(${val.version})); - BifEvent::enqueue_ntlm_negotiate(bro_analyzer(), + zeek::BifEvent::enqueue_ntlm_negotiate(bro_analyzer(), bro_analyzer()->Conn(), std::move(result)); @@ -146,7 +146,7 @@ refine connection NTLM_Conn += { if ( ${val}->has_target_info() ) result->Assign(3, build_av_record(${val.target_info}, ${val.target_info_fields.length})); - BifEvent::enqueue_ntlm_challenge(bro_analyzer(), + zeek::BifEvent::enqueue_ntlm_challenge(bro_analyzer(), bro_analyzer()->Conn(), std::move(result)); @@ -176,7 +176,7 @@ refine connection NTLM_Conn += { if ( ${val}->has_version() ) result->Assign(5, build_version_record(${val.version})); - BifEvent::enqueue_ntlm_authenticate(bro_analyzer(), + zeek::BifEvent::enqueue_ntlm_authenticate(bro_analyzer(), bro_analyzer()->Conn(), std::move(result)); return true; diff --git a/src/analyzer/protocol/ntp/ntp-analyzer.pac b/src/analyzer/protocol/ntp/ntp-analyzer.pac index 10e92a33a1..35e776c3a9 100644 --- a/src/analyzer/protocol/ntp/ntp-analyzer.pac +++ b/src/analyzer/protocol/ntp/ntp-analyzer.pac @@ -147,7 +147,7 @@ refine flow NTP_Flow += { else if ( ${msg.mode} == 7 ) rv->Assign(4, BuildNTPMode7Msg(${msg.mode7})); - BifEvent::enqueue_ntp_message(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_ntp_message(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), std::move(rv)); return true; diff --git a/src/analyzer/protocol/radius/radius-analyzer.pac b/src/analyzer/protocol/radius/radius-analyzer.pac index 337b7a6364..4bb6d006b4 100644 --- a/src/analyzer/protocol/radius/radius-analyzer.pac +++ b/src/analyzer/protocol/radius/radius-analyzer.pac @@ -41,7 +41,7 @@ refine flow RADIUS_Flow += { result->Assign(3, attributes); } - BifEvent::enqueue_radius_message(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(result)); + zeek::BifEvent::enqueue_radius_message(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(result)); return true; %} @@ -50,7 +50,7 @@ refine flow RADIUS_Flow += { if ( ! radius_attribute ) return false; - BifEvent::enqueue_radius_attribute(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_radius_attribute(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${attr.code}, to_stringval(${attr.value})); return true; %} diff --git a/src/analyzer/protocol/rdp/RDP.cc b/src/analyzer/protocol/rdp/RDP.cc index 1509064221..0d1f77a70d 100644 --- a/src/analyzer/protocol/rdp/RDP.cc +++ b/src/analyzer/protocol/rdp/RDP.cc @@ -75,7 +75,7 @@ void RDP_Analyzer::DeliverStream(int len, const u_char* data, bool orig) else { if ( rdp_native_encrypted_data ) - BifEvent::enqueue_rdp_native_encrypted_data( + zeek::BifEvent::enqueue_rdp_native_encrypted_data( interp->bro_analyzer(), interp->bro_analyzer()->Conn(), orig, len); } diff --git a/src/analyzer/protocol/rdp/rdp-analyzer.pac b/src/analyzer/protocol/rdp/rdp-analyzer.pac index 2e2de63afc..51faabee3c 100644 --- a/src/analyzer/protocol/rdp/rdp-analyzer.pac +++ b/src/analyzer/protocol/rdp/rdp-analyzer.pac @@ -9,7 +9,7 @@ refine flow RDP_Flow += { %{ if ( rdp_connect_request ) { - BifEvent::enqueue_rdp_connect_request(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_connect_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(${cr.cookie_value})); } @@ -21,7 +21,7 @@ refine flow RDP_Flow += { %{ if ( rdp_negotiation_response ) { - BifEvent::enqueue_rdp_negotiation_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_negotiation_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${nr.selected_protocol}); } @@ -33,7 +33,7 @@ refine flow RDP_Flow += { %{ if ( rdp_negotiation_failure ) { - BifEvent::enqueue_rdp_negotiation_failure(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_negotiation_failure(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${nf.failure_code}); } @@ -47,7 +47,7 @@ refine flow RDP_Flow += { connection()->bro_analyzer()->ProtocolConfirmation(); if ( rdp_gcc_server_create_response ) - BifEvent::enqueue_rdp_gcc_server_create_response(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_gcc_server_create_response(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${gcc_response.result}); @@ -94,7 +94,7 @@ refine flow RDP_Flow += { ccd->Assign(18, std::move(ec_flags)); ccd->Assign(19, utf16_to_utf8_val(connection()->bro_analyzer()->Conn(), ${ccore.dig_product_id})); - BifEvent::enqueue_rdp_client_core_data(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_client_core_data(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(ccd)); } @@ -111,7 +111,7 @@ refine flow RDP_Flow += { csd->Assign(0, val_mgr->Count(${csec.encryption_methods})); csd->Assign(1, val_mgr->Count(${csec.ext_encryption_methods})); - BifEvent::enqueue_rdp_client_security_data(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_client_security_data(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(csd)); return true; @@ -148,7 +148,7 @@ refine flow RDP_Flow += { channels->Assign(channels->Size(), std::move(channel_def)); } - BifEvent::enqueue_rdp_client_network_data(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_client_network_data(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(channels)); } @@ -169,7 +169,7 @@ refine flow RDP_Flow += { ccld->Assign(4, val_mgr->Bool(${ccluster.REDIRECTED_SESSIONID_FIELD_VALID})); ccld->Assign(5, val_mgr->Bool(${ccluster.REDIRECTED_SMARTCARD})); - BifEvent::enqueue_rdp_client_cluster_data(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_client_cluster_data(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(ccld)); return true; @@ -180,7 +180,7 @@ refine flow RDP_Flow += { connection()->bro_analyzer()->ProtocolConfirmation(); if ( rdp_server_security ) - BifEvent::enqueue_rdp_server_security(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_server_security(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${ssd.encryption_method}, ${ssd.encryption_level}); @@ -192,7 +192,7 @@ refine flow RDP_Flow += { %{ if ( rdp_server_certificate ) { - BifEvent::enqueue_rdp_server_certificate(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rdp_server_certificate(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${cert.cert_type}, ${cert.permanently_issued}); diff --git a/src/analyzer/protocol/rdp/rdp-protocol.pac b/src/analyzer/protocol/rdp/rdp-protocol.pac index 4d7ac79df2..ca88d90284 100644 --- a/src/analyzer/protocol/rdp/rdp-protocol.pac +++ b/src/analyzer/protocol/rdp/rdp-protocol.pac @@ -383,7 +383,7 @@ refine connection RDP_Conn += { if ( rdp_begin_encryption ) { - BifEvent::enqueue_rdp_begin_encryption(bro_analyzer(), + zeek::BifEvent::enqueue_rdp_begin_encryption(bro_analyzer(), bro_analyzer()->Conn(), ${method}); } diff --git a/src/analyzer/protocol/rdp/rdpeudp-analyzer.pac b/src/analyzer/protocol/rdp/rdpeudp-analyzer.pac index a5744b637c..9e2730ba60 100644 --- a/src/analyzer/protocol/rdp/rdpeudp-analyzer.pac +++ b/src/analyzer/protocol/rdp/rdpeudp-analyzer.pac @@ -45,7 +45,7 @@ refine connection RDPEUDP_Conn += { orig_lossy_ = true; if ( rdpeudp_syn ) - BifEvent::enqueue_rdpeudp_syn(bro_analyzer(), bro_analyzer()->Conn()); + zeek::BifEvent::enqueue_rdpeudp_syn(bro_analyzer(), bro_analyzer()->Conn()); state_ = NEED_SYNACK; return true; @@ -60,7 +60,7 @@ refine connection RDPEUDP_Conn += { return false; if ( rdpeudp_synack ) - BifEvent::enqueue_rdpeudp_synack(bro_analyzer(), bro_analyzer()->Conn()); + zeek::BifEvent::enqueue_rdpeudp_synack(bro_analyzer(), bro_analyzer()->Conn()); bro_analyzer()->ProtocolConfirmation(); state_ = NEED_ACK; @@ -79,11 +79,11 @@ refine connection RDPEUDP_Conn += { state_ = ESTABLISHED; if ( rdpeudp_established ) - BifEvent::enqueue_rdpeudp_established(bro_analyzer(), bro_analyzer()->Conn(), 1); + zeek::BifEvent::enqueue_rdpeudp_established(bro_analyzer(), bro_analyzer()->Conn(), 1); } if ( state_ == ESTABLISHED && rdpeudp_data ) - BifEvent::enqueue_rdpeudp_data(bro_analyzer(), + zeek::BifEvent::enqueue_rdpeudp_data(bro_analyzer(), bro_analyzer()->Conn(), is_orig, 1, @@ -102,13 +102,13 @@ refine connection RDPEUDP_Conn += { if ( state_ == NEED_ACK ) { if ( rdpeudp_established ) - BifEvent::enqueue_rdpeudp_established(bro_analyzer(), bro_analyzer()->Conn(), 2); + zeek::BifEvent::enqueue_rdpeudp_established(bro_analyzer(), bro_analyzer()->Conn(), 2); state_ = ESTABLISHED; } if ( state_ == ESTABLISHED && rdpeudp_data ) - BifEvent::enqueue_rdpeudp_data(bro_analyzer(), + zeek::BifEvent::enqueue_rdpeudp_data(bro_analyzer(), bro_analyzer()->Conn(), is_orig, 2, diff --git a/src/analyzer/protocol/rfb/rfb-analyzer.pac b/src/analyzer/protocol/rfb/rfb-analyzer.pac index 80f6c2c58b..b3e99e1af2 100644 --- a/src/analyzer/protocol/rfb/rfb-analyzer.pac +++ b/src/analyzer/protocol/rfb/rfb-analyzer.pac @@ -4,7 +4,7 @@ refine flow RFB_Flow += { if ( client ) { if ( rfb_client_version ) - BifEvent::enqueue_rfb_client_version(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rfb_client_version(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(major), to_stringval(minor)); @@ -14,7 +14,7 @@ refine flow RFB_Flow += { else { if ( rfb_server_version ) - BifEvent::enqueue_rfb_server_version(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_rfb_server_version(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(major), to_stringval(minor)); @@ -26,21 +26,21 @@ refine flow RFB_Flow += { function proc_rfb_share_flag(shared: bool) : bool %{ if ( rfb_share_flag ) - BifEvent::enqueue_rfb_share_flag(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), shared); + zeek::BifEvent::enqueue_rfb_share_flag(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), shared); return true; %} function proc_security_types(msg: RFBSecurityType) : bool %{ if ( rfb_authentication_type ) - BifEvent::enqueue_rfb_authentication_type(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.sectype}); + zeek::BifEvent::enqueue_rfb_authentication_type(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.sectype}); return true; %} function proc_security_types37(msg: RFBAuthTypeSelected) : bool %{ if ( rfb_authentication_type ) - BifEvent::enqueue_rfb_authentication_type(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.type}); + zeek::BifEvent::enqueue_rfb_authentication_type(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.type}); return true; %} @@ -50,7 +50,7 @@ refine flow RFB_Flow += { { auto vec_ptr = ${msg.name}; auto name_ptr = &((*vec_ptr)[0]); - BifEvent::enqueue_rfb_server_parameters( + zeek::BifEvent::enqueue_rfb_server_parameters( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), make_intrusive(${msg.name}->size(), (const char*)name_ptr), ${msg.width}, @@ -62,7 +62,7 @@ refine flow RFB_Flow += { function proc_handle_security_result(result : uint32) : bool %{ if ( rfb_auth_result ) - BifEvent::enqueue_rfb_auth_result(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), result); + zeek::BifEvent::enqueue_rfb_auth_result(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), result); return true; %} }; diff --git a/src/analyzer/protocol/sip/sip-analyzer.pac b/src/analyzer/protocol/sip/sip-analyzer.pac index 0b37a5c385..39b465ab7a 100644 --- a/src/analyzer/protocol/sip/sip-analyzer.pac +++ b/src/analyzer/protocol/sip/sip-analyzer.pac @@ -20,7 +20,7 @@ refine flow SIP_Flow += { %{ if ( sip_request ) { - BifEvent::enqueue_sip_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_sip_request(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(method), to_stringval(uri), to_stringval(${vers.vers_str})); } @@ -35,7 +35,7 @@ refine flow SIP_Flow += { connection()->bro_analyzer()->ProtocolConfirmation(); if ( sip_reply ) { - BifEvent::enqueue_sip_reply(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_sip_reply(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(${vers.vers_str}), code, to_stringval(reason)); } @@ -53,7 +53,7 @@ refine flow SIP_Flow += { { auto nameval = to_stringval(name); nameval->ToUpper(); - BifEvent::enqueue_sip_header(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_sip_header(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), std::move(nameval), to_stringval(value)); } @@ -83,7 +83,7 @@ refine flow SIP_Flow += { %{ if ( sip_all_headers ) { - BifEvent::enqueue_sip_all_headers(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_sip_all_headers(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig(), {AdoptRef{}, build_sip_headers_val()}); } @@ -127,7 +127,7 @@ refine flow SIP_Flow += { %{ if ( sip_begin_entity ) { - BifEvent::enqueue_sip_begin_entity(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig()); + zeek::BifEvent::enqueue_sip_begin_entity(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig()); } %} @@ -135,7 +135,7 @@ refine flow SIP_Flow += { %{ if ( sip_end_entity ) { - BifEvent::enqueue_sip_end_entity(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig()); + zeek::BifEvent::enqueue_sip_end_entity(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig()); } return true; diff --git a/src/analyzer/protocol/smb/smb1-com-check-directory.pac b/src/analyzer/protocol/smb/smb1-com-check-directory.pac index 8643192a59..3c7747fc7b 100644 --- a/src/analyzer/protocol/smb/smb1-com-check-directory.pac +++ b/src/analyzer/protocol/smb/smb1-com-check-directory.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_check_directory_request(header: SMB_Header, val: SMB1_check_directory_request): bool %{ if ( smb1_check_directory_request ) - BifEvent::enqueue_smb1_check_directory_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_check_directory_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), smb_string2stringval(${val.directory_name})); @@ -13,7 +13,7 @@ refine connection SMB_Conn += { function proc_smb1_check_directory_response(header: SMB_Header, val: SMB1_check_directory_response): bool %{ if ( smb1_check_directory_response ) - BifEvent::enqueue_smb1_check_directory_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_check_directory_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header)); return true; diff --git a/src/analyzer/protocol/smb/smb1-com-close.pac b/src/analyzer/protocol/smb/smb1-com-close.pac index f07fce3820..8e85de4685 100644 --- a/src/analyzer/protocol/smb/smb1-com-close.pac +++ b/src/analyzer/protocol/smb/smb1-com-close.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_close_request(h: SMB_Header, val: SMB1_close_request): bool %{ if ( smb1_close_request ) - BifEvent::enqueue_smb1_close_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_close_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(h), ${val.file_id}); diff --git a/src/analyzer/protocol/smb/smb1-com-create-directory.pac b/src/analyzer/protocol/smb/smb1-com-create-directory.pac index adc84619a8..af9b9f4897 100644 --- a/src/analyzer/protocol/smb/smb1-com-create-directory.pac +++ b/src/analyzer/protocol/smb/smb1-com-create-directory.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_create_directory_request(header: SMB_Header, val: SMB1_create_directory_request): bool %{ if ( smb1_create_directory_request ) - BifEvent::enqueue_smb1_create_directory_request(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_smb1_create_directory_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), smb_string2stringval(${val.directory_name})); return true; @@ -11,7 +11,7 @@ refine connection SMB_Conn += { function proc_smb1_create_directory_response(header: SMB_Header, val: SMB1_create_directory_response): bool %{ if ( smb1_create_directory_response ) - BifEvent::enqueue_smb1_create_directory_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_create_directory_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header)); return true; diff --git a/src/analyzer/protocol/smb/smb1-com-echo.pac b/src/analyzer/protocol/smb/smb1-com-echo.pac index c8a8f9eb0c..33fb977748 100644 --- a/src/analyzer/protocol/smb/smb1-com-echo.pac +++ b/src/analyzer/protocol/smb/smb1-com-echo.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_echo_request(header: SMB_Header, val: SMB1_echo_request): bool %{ if ( smb1_echo_request ) - BifEvent::enqueue_smb1_echo_request(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_smb1_echo_request(bro_analyzer(), bro_analyzer()->Conn(), ${val.echo_count}, to_stringval(${val.data})); return true; %} @@ -11,7 +11,7 @@ refine connection SMB_Conn += { function proc_smb1_echo_response(header: SMB_Header, val: SMB1_echo_response): bool %{ if ( smb1_echo_response ) - BifEvent::enqueue_smb1_echo_response(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_smb1_echo_response(bro_analyzer(), bro_analyzer()->Conn(), ${val.seq_num}, to_stringval(${val.data})); return true; %} diff --git a/src/analyzer/protocol/smb/smb1-com-logoff-andx.pac b/src/analyzer/protocol/smb/smb1-com-logoff-andx.pac index 878d549022..7efc8993ca 100644 --- a/src/analyzer/protocol/smb/smb1-com-logoff-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-logoff-andx.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_logoff_andx(header: SMB_Header, val: SMB1_logoff_andx): bool %{ if ( smb1_logoff_andx ) - BifEvent::enqueue_smb1_logoff_andx(bro_analyzer(), bro_analyzer()->Conn(), ${val.is_orig}); + zeek::BifEvent::enqueue_smb1_logoff_andx(bro_analyzer(), bro_analyzer()->Conn(), ${val.is_orig}); return true; %} diff --git a/src/analyzer/protocol/smb/smb1-com-negotiate.pac b/src/analyzer/protocol/smb/smb1-com-negotiate.pac index 8240848111..1a6ef0c3bd 100644 --- a/src/analyzer/protocol/smb/smb1-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb1-com-negotiate.pac @@ -23,7 +23,7 @@ refine connection SMB_Conn += { dialects->Assign(i, std::move(dia)); } - BifEvent::enqueue_smb1_negotiate_request(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_smb1_negotiate_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(dialects)); } @@ -135,7 +135,7 @@ refine connection SMB_Conn += { } break; } - BifEvent::enqueue_smb1_negotiate_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_negotiate_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(response)); diff --git a/src/analyzer/protocol/smb/smb1-com-nt-cancel.pac b/src/analyzer/protocol/smb/smb1-com-nt-cancel.pac index 17da194d01..185c49b6b5 100644 --- a/src/analyzer/protocol/smb/smb1-com-nt-cancel.pac +++ b/src/analyzer/protocol/smb/smb1-com-nt-cancel.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_nt_cancel_request(header: SMB_Header, val: SMB1_nt_cancel_request): bool %{ if ( smb1_nt_cancel_request ) - BifEvent::enqueue_smb1_nt_cancel_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_nt_cancel_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header)); return true; diff --git a/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac b/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac index f07f9774e2..c7c0ba745e 100644 --- a/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac @@ -9,13 +9,13 @@ refine connection SMB_Conn += { set_tree_is_pipe(${header.tid}); if ( smb_pipe_connect_heuristic ) - BifEvent::enqueue_smb_pipe_connect_heuristic(bro_analyzer(), + zeek::BifEvent::enqueue_smb_pipe_connect_heuristic(bro_analyzer(), bro_analyzer()->Conn()); } if ( smb1_nt_create_andx_request ) { - BifEvent::enqueue_smb1_nt_create_andx_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_nt_create_andx_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(filename)); @@ -28,7 +28,7 @@ refine connection SMB_Conn += { %{ if ( smb1_nt_create_andx_response ) { - BifEvent::enqueue_smb1_nt_create_andx_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_nt_create_andx_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), ${val.file_id}, diff --git a/src/analyzer/protocol/smb/smb1-com-query-information.pac b/src/analyzer/protocol/smb/smb1-com-query-information.pac index fd458222f1..a5dc03366b 100644 --- a/src/analyzer/protocol/smb/smb1-com-query-information.pac +++ b/src/analyzer/protocol/smb/smb1-com-query-information.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_query_information_request(header: SMB_Header, val: SMB1_query_information_request): bool %{ if ( smb1_query_information_request ) - BifEvent::enqueue_smb1_query_information_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_query_information_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), smb_string2stringval(${val.filename})); diff --git a/src/analyzer/protocol/smb/smb1-com-read-andx.pac b/src/analyzer/protocol/smb/smb1-com-read-andx.pac index a90518b604..79317a3450 100644 --- a/src/analyzer/protocol/smb/smb1-com-read-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-read-andx.pac @@ -9,7 +9,7 @@ refine connection SMB_Conn += { function proc_smb1_read_andx_request(h: SMB_Header, val: SMB1_read_andx_request): bool %{ if ( smb1_read_andx_request ) - BifEvent::enqueue_smb1_read_andx_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_read_andx_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(h), ${val.file_id}, @@ -23,7 +23,7 @@ refine connection SMB_Conn += { function proc_smb1_read_andx_response(h: SMB_Header, val: SMB1_read_andx_response): bool %{ if ( smb1_read_andx_response ) - BifEvent::enqueue_smb1_read_andx_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_read_andx_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(h), ${val.data_len}); diff --git a/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac b/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac index f5d2628e26..ddc2c6ce3e 100644 --- a/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac @@ -78,7 +78,7 @@ refine connection SMB_Conn += { break; } - BifEvent::enqueue_smb1_session_setup_andx_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_session_setup_andx_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(request)); @@ -112,7 +112,7 @@ refine connection SMB_Conn += { break; } - BifEvent::enqueue_smb1_session_setup_andx_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_session_setup_andx_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(response)); diff --git a/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac b/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac index a065d6ac9d..321e1f9183 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac @@ -45,7 +45,7 @@ refine connection SMB_Conn += { payload_str = val_mgr->EmptyString(); } - BifEvent::enqueue_smb1_transaction_secondary_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_transaction_secondary_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(args), diff --git a/src/analyzer/protocol/smb/smb1-com-transaction.pac b/src/analyzer/protocol/smb/smb1-com-transaction.pac index 1ffc80209f..221f8c5549 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction.pac @@ -62,7 +62,7 @@ refine connection SMB_Conn += { else payload_str = val_mgr->EmptyString(); - BifEvent::enqueue_smb1_transaction_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_transaction_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), smb_string2stringval(${val.name}), @@ -87,7 +87,7 @@ refine connection SMB_Conn += { else payload_str = val_mgr->EmptyString(); - BifEvent::enqueue_smb1_transaction_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_transaction_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(parameters), diff --git a/src/analyzer/protocol/smb/smb1-com-transaction2-secondary.pac b/src/analyzer/protocol/smb/smb1-com-transaction2-secondary.pac index 3ecd1f65c8..a3a65c8367 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction2-secondary.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction2-secondary.pac @@ -19,7 +19,7 @@ refine connection SMB_Conn += { auto parameters = make_intrusive(${val.parameters}.length(), (const char*)${val.parameters}.data()); auto payload = make_intrusive(${val.data}.length(), (const char*)${val.data}.data()); - BifEvent::enqueue_smb1_transaction2_secondary_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_transaction2_secondary_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(args), diff --git a/src/analyzer/protocol/smb/smb1-com-transaction2.pac b/src/analyzer/protocol/smb/smb1-com-transaction2.pac index 491d06d06c..b13865d989 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction2.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction2.pac @@ -38,7 +38,7 @@ refine connection SMB_Conn += { args->Assign(10, val_mgr->Count(${val.data_offset})); args->Assign(11, val_mgr->Count(${val.setup_count})); - BifEvent::enqueue_smb1_transaction2_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_transaction2_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(args), @@ -51,7 +51,7 @@ refine connection SMB_Conn += { function proc_smb1_transaction2_response(header: SMB_Header, val: SMB1_transaction2_response): bool %{ //if ( smb1_transaction2_response ) - // BifEvent::enqueue_smb1_transaction2_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), ${val.sub_cmd}); + // zeek::BifEvent::enqueue_smb1_transaction2_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), ${val.sub_cmd}); return true; %} @@ -138,7 +138,7 @@ refine connection SMB_Conn += { result->Assign(3, val_mgr->Count(${val.info_level})); result->Assign(4, val_mgr->Count(${val.search_storage_type})); result->Assign(5, smb_string2stringval(${val.file_name})); - BifEvent::enqueue_smb1_trans2_find_first2_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_trans2_find_first2_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(result)); @@ -217,7 +217,7 @@ refine connection SMB_Conn += { %{ if ( smb1_trans2_query_path_info_request ) { - BifEvent::enqueue_smb1_trans2_query_path_info_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_trans2_query_path_info_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), smb_string2stringval(${val.file_name})); @@ -322,7 +322,7 @@ refine connection SMB_Conn += { %{ if ( smb1_trans2_get_dfs_referral_request ) { - BifEvent::enqueue_smb1_trans2_get_dfs_referral_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_trans2_get_dfs_referral_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), smb_string2stringval(${val.file_name})); diff --git a/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac b/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac index a2c415e56c..914aef838b 100644 --- a/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_tree_connect_andx_request(header: SMB_Header, val: SMB1_tree_connect_andx_request): bool %{ if ( smb1_tree_connect_andx_request ) - BifEvent::enqueue_smb1_tree_connect_andx_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_tree_connect_andx_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), smb_string2stringval(${val.path}), @@ -20,7 +20,7 @@ refine connection SMB_Conn += { set_tree_is_pipe(${header.tid}); if ( smb1_tree_connect_andx_response ) - BifEvent::enqueue_smb1_tree_connect_andx_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_tree_connect_andx_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), std::move(service_string), diff --git a/src/analyzer/protocol/smb/smb1-com-tree-disconnect.pac b/src/analyzer/protocol/smb/smb1-com-tree-disconnect.pac index b0178b65aa..7a23729181 100644 --- a/src/analyzer/protocol/smb/smb1-com-tree-disconnect.pac +++ b/src/analyzer/protocol/smb/smb1-com-tree-disconnect.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_tree_disconnect(header: SMB_Header, val: SMB1_tree_disconnect): bool %{ if ( smb1_tree_disconnect ) - BifEvent::enqueue_smb1_tree_disconnect(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_tree_disconnect(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header), ${val.is_orig}); diff --git a/src/analyzer/protocol/smb/smb1-com-write-andx.pac b/src/analyzer/protocol/smb/smb1-com-write-andx.pac index b2fd8d9381..8831d730df 100644 --- a/src/analyzer/protocol/smb/smb1-com-write-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-write-andx.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb1_write_andx_request(h: SMB_Header, val: SMB1_write_andx_request): bool %{ if ( smb1_write_andx_request ) - BifEvent::enqueue_smb1_write_andx_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_write_andx_request(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(h), ${val.file_id}, @@ -24,7 +24,7 @@ refine connection SMB_Conn += { function proc_smb1_write_andx_response(h: SMB_Header, val: SMB1_write_andx_response): bool %{ if ( smb1_write_andx_response ) - BifEvent::enqueue_smb1_write_andx_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_write_andx_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(h), ${val.written_bytes}); diff --git a/src/analyzer/protocol/smb/smb1-protocol.pac b/src/analyzer/protocol/smb/smb1-protocol.pac index bafb427f5f..63e6d87e87 100644 --- a/src/analyzer/protocol/smb/smb1-protocol.pac +++ b/src/analyzer/protocol/smb/smb1-protocol.pac @@ -43,7 +43,7 @@ refine connection SMB_Conn += { %{ if ( smb1_message ) { - BifEvent::enqueue_smb1_message(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_smb1_message(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(h), is_orig); } @@ -54,7 +54,7 @@ refine connection SMB_Conn += { %{ if ( smb1_empty_response ) { - BifEvent::enqueue_smb1_empty_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_empty_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(header)); } @@ -67,7 +67,7 @@ refine connection SMB_Conn += { { if ( smb1_empty_response ) { - BifEvent::enqueue_smb1_empty_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_empty_response(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(h)); } @@ -75,7 +75,7 @@ refine connection SMB_Conn += { else { if ( smb1_error ) - BifEvent::enqueue_smb1_error(bro_analyzer(), + zeek::BifEvent::enqueue_smb1_error(bro_analyzer(), bro_analyzer()->Conn(), SMBHeaderVal(h), is_orig); } diff --git a/src/analyzer/protocol/smb/smb2-com-close.pac b/src/analyzer/protocol/smb/smb2-com-close.pac index be049dd5d2..db6b24b9b4 100644 --- a/src/analyzer/protocol/smb/smb2-com-close.pac +++ b/src/analyzer/protocol/smb/smb2-com-close.pac @@ -4,7 +4,7 @@ refine connection SMB_Conn += { %{ if ( smb2_close_request ) { - BifEvent::enqueue_smb2_close_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_close_request(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), BuildSMB2GUID(${val.file_id})); @@ -30,7 +30,7 @@ refine connection SMB_Conn += { ${val.change_time})); resp->Assign(3, smb2_file_attrs_to_bro(${val.file_attrs})); - BifEvent::enqueue_smb2_close_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_close_response(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), std::move(resp)); diff --git a/src/analyzer/protocol/smb/smb2-com-create.pac b/src/analyzer/protocol/smb/smb2-com-create.pac index ff60931c9d..ac9feb22f0 100644 --- a/src/analyzer/protocol/smb/smb2-com-create.pac +++ b/src/analyzer/protocol/smb/smb2-com-create.pac @@ -10,7 +10,7 @@ refine connection SMB_Conn += { set_tree_is_pipe(${h.tree_id}); if ( smb_pipe_connect_heuristic ) - BifEvent::enqueue_smb_pipe_connect_heuristic(bro_analyzer(), + zeek::BifEvent::enqueue_smb_pipe_connect_heuristic(bro_analyzer(), bro_analyzer()->Conn()); } @@ -20,7 +20,7 @@ refine connection SMB_Conn += { requestinfo->Assign(0, std::move(filename)); requestinfo->Assign(1, val_mgr->Count(${val.disposition})); requestinfo->Assign(2, val_mgr->Count(${val.create_options})); - BifEvent::enqueue_smb2_create_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_create_request(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), std::move(requestinfo)); @@ -42,7 +42,7 @@ refine connection SMB_Conn += { ${val.change_time})); responseinfo->Assign(3, smb2_file_attrs_to_bro(${val.file_attrs})); responseinfo->Assign(4, val_mgr->Count(${val.create_action})); - BifEvent::enqueue_smb2_create_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_create_response(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), std::move(responseinfo)); diff --git a/src/analyzer/protocol/smb/smb2-com-negotiate.pac b/src/analyzer/protocol/smb/smb2-com-negotiate.pac index 024f25b76f..cc639088f2 100644 --- a/src/analyzer/protocol/smb/smb2-com-negotiate.pac +++ b/src/analyzer/protocol/smb/smb2-com-negotiate.pac @@ -27,7 +27,7 @@ refine connection SMB_Conn += { for ( unsigned int i = 0; i < ${val.dialects}->size(); ++i ) dialects->Assign(i, val_mgr->Count((*${val.dialects})[i])); - BifEvent::enqueue_smb2_negotiate_request(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_smb2_negotiate_request(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), std::move(dialects)); } @@ -60,7 +60,7 @@ refine connection SMB_Conn += { nr->Assign(6, std::move(cv)); - BifEvent::enqueue_smb2_negotiate_response(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_smb2_negotiate_response(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), std::move(nr)); } diff --git a/src/analyzer/protocol/smb/smb2-com-read.pac b/src/analyzer/protocol/smb/smb2-com-read.pac index a3b01e4f5f..07eafcbabc 100644 --- a/src/analyzer/protocol/smb/smb2-com-read.pac +++ b/src/analyzer/protocol/smb/smb2-com-read.pac @@ -26,7 +26,7 @@ refine connection SMB_Conn += { %{ if ( smb2_read_request ) { - BifEvent::enqueue_smb2_read_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_read_request(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), BuildSMB2GUID(${val.file_id}), diff --git a/src/analyzer/protocol/smb/smb2-com-session-setup.pac b/src/analyzer/protocol/smb/smb2-com-session-setup.pac index edd380790e..5b4b5f27e8 100644 --- a/src/analyzer/protocol/smb/smb2-com-session-setup.pac +++ b/src/analyzer/protocol/smb/smb2-com-session-setup.pac @@ -7,7 +7,7 @@ refine connection SMB_Conn += { auto req = make_intrusive(zeek::BifType::Record::SMB2::SessionSetupRequest); req->Assign(0, val_mgr->Count(${val.security_mode})); - BifEvent::enqueue_smb2_session_setup_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_session_setup_request(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), std::move(req)); @@ -28,7 +28,7 @@ refine connection SMB_Conn += { auto resp = make_intrusive(zeek::BifType::Record::SMB2::SessionSetupResponse); resp->Assign(0, std::move(flags)); - BifEvent::enqueue_smb2_session_setup_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_session_setup_response(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), std::move(resp)); diff --git a/src/analyzer/protocol/smb/smb2-com-set-info.pac b/src/analyzer/protocol/smb/smb2-com-set-info.pac index daee89cb70..a1c13e61b6 100644 --- a/src/analyzer/protocol/smb/smb2-com-set-info.pac +++ b/src/analyzer/protocol/smb/smb2-com-set-info.pac @@ -28,7 +28,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file(val: SMB2_file_basic_info): bool %{ if ( smb2_file_sattr ) - BifEvent::enqueue_smb2_file_sattr(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_sattr(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -44,7 +44,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_rename(val: SMB2_file_rename_info): bool %{ if ( smb2_file_rename ) - BifEvent::enqueue_smb2_file_rename(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_rename(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -56,7 +56,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_delete(val: SMB2_file_disposition_info): bool %{ if ( smb2_file_delete ) - BifEvent::enqueue_smb2_file_delete(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_delete(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -68,7 +68,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_allocation(val: SMB2_file_allocation_info): bool %{ if ( smb2_file_allocation ) - BifEvent::enqueue_smb2_file_allocation(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_allocation(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -80,7 +80,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_endoffile(val: SMB2_file_endoffile_info): bool %{ if ( smb2_file_endoffile ) - BifEvent::enqueue_smb2_file_endoffile(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_endoffile(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -104,7 +104,7 @@ refine connection SMB_Conn += { eas->Assign(i, std::move(r)); } - BifEvent::enqueue_smb2_file_fullea(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_fullea(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -117,7 +117,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_link(val: SMB2_file_link_info): bool %{ if ( smb2_file_link ) - BifEvent::enqueue_smb2_file_link(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_link(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -130,7 +130,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_mode(val: SMB2_file_mode_info): bool %{ if ( smb2_file_mode ) - BifEvent::enqueue_smb2_file_mode(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_mode(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -142,7 +142,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_pipe(val: SMB2_file_pipe_info): bool %{ if ( smb2_file_pipe ) - BifEvent::enqueue_smb2_file_pipe(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_pipe(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -155,7 +155,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_position(val: SMB2_file_position_info): bool %{ if ( smb2_file_position ) - BifEvent::enqueue_smb2_file_position(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_position(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -167,7 +167,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_shortname(val: SMB2_file_shortname_info): bool %{ if ( smb2_file_shortname ) - BifEvent::enqueue_smb2_file_shortname(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_shortname(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -179,7 +179,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_validdatalength(val: SMB2_file_validdatalength_info): bool %{ if ( smb2_file_validdatalength ) - BifEvent::enqueue_smb2_file_validdatalength(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_validdatalength(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -200,7 +200,7 @@ refine connection SMB_Conn += { r->Assign(4, val_mgr->Count(${val.default_quota_limit})); r->Assign(5, val_mgr->Count(${val.file_system_control_flags})); - BifEvent::enqueue_smb2_file_fscontrol(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_fscontrol(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), @@ -213,7 +213,7 @@ refine connection SMB_Conn += { function proc_smb2_set_info_request_file_fsobjectid(val: SMB2_file_fsobjectid_info): bool %{ if ( smb2_file_fsobjectid ) - BifEvent::enqueue_smb2_file_fsobjectid(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_file_fsobjectid(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(${val.sir.header}), BuildSMB2GUID(${val.sir.file_id}), diff --git a/src/analyzer/protocol/smb/smb2-com-transform-header.pac b/src/analyzer/protocol/smb/smb2-com-transform-header.pac index fb546afe1d..a261f58d42 100644 --- a/src/analyzer/protocol/smb/smb2-com-transform-header.pac +++ b/src/analyzer/protocol/smb/smb2-com-transform-header.pac @@ -11,7 +11,7 @@ refine connection SMB_Conn += { r->Assign(3, val_mgr->Count(${hdr.flags})); r->Assign(4, val_mgr->Count(${hdr.session_id})); - BifEvent::enqueue_smb2_transform_header(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_transform_header(bro_analyzer(), bro_analyzer()->Conn(), std::move(r)); } diff --git a/src/analyzer/protocol/smb/smb2-com-tree-connect.pac b/src/analyzer/protocol/smb/smb2-com-tree-connect.pac index 7ad9516a7f..63de3c1ccb 100644 --- a/src/analyzer/protocol/smb/smb2-com-tree-connect.pac +++ b/src/analyzer/protocol/smb/smb2-com-tree-connect.pac @@ -3,7 +3,7 @@ refine connection SMB_Conn += { function proc_smb2_tree_connect_request(header: SMB2_Header, val: SMB2_tree_connect_request): bool %{ if ( smb2_tree_connect_request ) - BifEvent::enqueue_smb2_tree_connect_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_tree_connect_request(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(header), smb2_string2stringval(${val.path})); @@ -21,7 +21,7 @@ refine connection SMB_Conn += { auto resp = make_intrusive(zeek::BifType::Record::SMB2::TreeConnectResponse); resp->Assign(0, val_mgr->Count(${val.share_type})); - BifEvent::enqueue_smb2_tree_connect_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_tree_connect_response(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(header), std::move(resp)); diff --git a/src/analyzer/protocol/smb/smb2-com-tree-disconnect.pac b/src/analyzer/protocol/smb/smb2-com-tree-disconnect.pac index f98523e94a..ebfe3cf367 100644 --- a/src/analyzer/protocol/smb/smb2-com-tree-disconnect.pac +++ b/src/analyzer/protocol/smb/smb2-com-tree-disconnect.pac @@ -7,7 +7,7 @@ refine connection SMB_Conn += { if ( smb2_tree_disconnect_request ) { - BifEvent::enqueue_smb2_tree_disconnect_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_tree_disconnect_request(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(header)); } @@ -19,7 +19,7 @@ refine connection SMB_Conn += { %{ if ( smb2_tree_disconnect_response ) { - BifEvent::enqueue_smb2_tree_disconnect_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_tree_disconnect_response(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(header)); } diff --git a/src/analyzer/protocol/smb/smb2-com-write.pac b/src/analyzer/protocol/smb/smb2-com-write.pac index 773dcd8bcc..91cbd1988d 100644 --- a/src/analyzer/protocol/smb/smb2-com-write.pac +++ b/src/analyzer/protocol/smb/smb2-com-write.pac @@ -4,7 +4,7 @@ refine connection SMB_Conn += { %{ if ( smb2_write_request ) { - BifEvent::enqueue_smb2_write_request(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_write_request(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), BuildSMB2GUID(${val.file_id}), @@ -27,7 +27,7 @@ refine connection SMB_Conn += { if ( smb2_write_response ) { - BifEvent::enqueue_smb2_write_response(bro_analyzer(), + zeek::BifEvent::enqueue_smb2_write_response(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), ${val.write_count}); diff --git a/src/analyzer/protocol/smb/smb2-protocol.pac b/src/analyzer/protocol/smb/smb2-protocol.pac index 13ec2c4062..3df04b354d 100644 --- a/src/analyzer/protocol/smb/smb2-protocol.pac +++ b/src/analyzer/protocol/smb/smb2-protocol.pac @@ -250,7 +250,7 @@ refine connection SMB_Conn += { if ( smb2_message ) { - BifEvent::enqueue_smb2_message(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_smb2_message(bro_analyzer(), bro_analyzer()->Conn(), BuildSMB2HeaderVal(h), is_orig); } return true; diff --git a/src/analyzer/protocol/snmp/snmp-analyzer.pac b/src/analyzer/protocol/snmp/snmp-analyzer.pac index a8c5b07b52..504a525440 100644 --- a/src/analyzer/protocol/snmp/snmp-analyzer.pac +++ b/src/analyzer/protocol/snmp/snmp-analyzer.pac @@ -209,7 +209,7 @@ refine connection SNMP_Conn += { if ( ! snmp_get_request ) return false; - BifEvent::enqueue_snmp_get_request(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_get_request(bro_analyzer(), bro_analyzer()->Conn(), ${pdu.header.is_orig}, build_hdr(${pdu.header}), @@ -222,7 +222,7 @@ refine connection SNMP_Conn += { if ( ! snmp_get_next_request ) return false; - BifEvent::enqueue_snmp_get_next_request(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_get_next_request(bro_analyzer(), bro_analyzer()->Conn(), ${pdu.header.is_orig}, build_hdr(${pdu.header}), @@ -235,7 +235,7 @@ refine connection SNMP_Conn += { if ( ! snmp_response ) return false; - BifEvent::enqueue_snmp_response(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_response(bro_analyzer(), bro_analyzer()->Conn(), ${pdu.header.is_orig}, build_hdr(${pdu.header}), @@ -248,7 +248,7 @@ refine connection SNMP_Conn += { if ( ! snmp_set_request ) return false; - BifEvent::enqueue_snmp_set_request(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_set_request(bro_analyzer(), bro_analyzer()->Conn(), ${pdu.header.is_orig}, build_hdr(${pdu.header}), @@ -261,7 +261,7 @@ refine connection SNMP_Conn += { if ( ! snmp_trap ) return false; - BifEvent::enqueue_snmp_trap(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_trap(bro_analyzer(), bro_analyzer()->Conn(), ${pdu.header.is_orig}, build_hdr(${pdu.header}), @@ -274,7 +274,7 @@ refine connection SNMP_Conn += { if ( ! snmp_get_bulk_request ) return false; - BifEvent::enqueue_snmp_get_bulk_request(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_get_bulk_request(bro_analyzer(), bro_analyzer()->Conn(), ${pdu.header.is_orig}, build_hdr(${pdu.header}), @@ -287,7 +287,7 @@ refine connection SNMP_Conn += { if ( ! snmp_inform_request ) return false; - BifEvent::enqueue_snmp_inform_request(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_inform_request(bro_analyzer(), bro_analyzer()->Conn(), ${pdu.header.is_orig}, build_hdr(${pdu.header}), @@ -300,7 +300,7 @@ refine connection SNMP_Conn += { if ( ! snmp_trapV2 ) return false; - BifEvent::enqueue_snmp_trapV2(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_trapV2(bro_analyzer(), bro_analyzer()->Conn(), ${pdu.header.is_orig}, build_hdr(${pdu.header}), @@ -313,7 +313,7 @@ refine connection SNMP_Conn += { if ( ! snmp_report ) return false; - BifEvent::enqueue_snmp_report(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_report(bro_analyzer(), bro_analyzer()->Conn(), ${pdu.header.is_orig}, build_hdr(${pdu.header}), @@ -326,7 +326,7 @@ refine connection SNMP_Conn += { if ( ! snmp_unknown_header_version ) return false; - BifEvent::enqueue_snmp_unknown_header_version(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_unknown_header_version(bro_analyzer(), bro_analyzer()->Conn(), ${rec.header.is_orig}, ${rec.header.version}); @@ -338,7 +338,7 @@ refine connection SNMP_Conn += { if ( ! snmp_unknown_pdu ) return false; - BifEvent::enqueue_snmp_unknown_pdu(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_unknown_pdu(bro_analyzer(), bro_analyzer()->Conn(), ${rec.header.is_orig}, build_hdr(${rec.header}), @@ -351,7 +351,7 @@ refine connection SNMP_Conn += { if ( ! snmp_unknown_scoped_pdu ) return false; - BifEvent::enqueue_snmp_unknown_scoped_pdu(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_unknown_scoped_pdu(bro_analyzer(), bro_analyzer()->Conn(), ${rec.header.is_orig}, build_hdr(${rec.header}), @@ -364,7 +364,7 @@ refine connection SNMP_Conn += { if ( ! snmp_encrypted_pdu ) return false; - BifEvent::enqueue_snmp_encrypted_pdu(bro_analyzer(), + zeek::BifEvent::enqueue_snmp_encrypted_pdu(bro_analyzer(), bro_analyzer()->Conn(), ${rec.header.is_orig}, build_hdr(${rec.header})); diff --git a/src/analyzer/protocol/socks/socks-analyzer.pac b/src/analyzer/protocol/socks/socks-analyzer.pac index e880f22bdc..b347e42263 100644 --- a/src/analyzer/protocol/socks/socks-analyzer.pac +++ b/src/analyzer/protocol/socks/socks-analyzer.pac @@ -31,7 +31,7 @@ refine connection SOCKS_Conn += { if ( ${request.v4a} ) sa->Assign(1, array_to_string(${request.name})); - BifEvent::enqueue_socks_request(bro_analyzer(), + zeek::BifEvent::enqueue_socks_request(bro_analyzer(), bro_analyzer()->Conn(), 4, ${request.command}, @@ -53,7 +53,7 @@ refine connection SOCKS_Conn += { auto sa = make_intrusive(socks_address); sa->Assign(0, make_intrusive(htonl(${reply.addr}))); - BifEvent::enqueue_socks_reply(bro_analyzer(), + zeek::BifEvent::enqueue_socks_reply(bro_analyzer(), bro_analyzer()->Conn(), 4, ${reply.status}, @@ -107,7 +107,7 @@ refine connection SOCKS_Conn += { } if ( socks_request ) - BifEvent::enqueue_socks_request(bro_analyzer(), + zeek::BifEvent::enqueue_socks_request(bro_analyzer(), bro_analyzer()->Conn(), 5, ${request.command}, @@ -147,7 +147,7 @@ refine connection SOCKS_Conn += { } if ( socks_reply ) - BifEvent::enqueue_socks_reply(bro_analyzer(), + zeek::BifEvent::enqueue_socks_reply(bro_analyzer(), bro_analyzer()->Conn(), 5, ${reply.reply}, @@ -167,7 +167,7 @@ refine connection SOCKS_Conn += { auto user = make_intrusive(${request.username}.length(), (const char*) ${request.username}.begin()); auto pass = make_intrusive(${request.password}.length(), (const char*) ${request.password}.begin()); - BifEvent::enqueue_socks_login_userpass_request(bro_analyzer(), + zeek::BifEvent::enqueue_socks_login_userpass_request(bro_analyzer(), bro_analyzer()->Conn(), std::move(user), std::move(pass)); return true; @@ -188,7 +188,7 @@ refine connection SOCKS_Conn += { function socks5_auth_reply_userpass(reply: SOCKS5_Auth_Reply_UserPass_v1): bool %{ if ( socks_login_userpass_reply ) - BifEvent::enqueue_socks_login_userpass_reply(bro_analyzer(), + zeek::BifEvent::enqueue_socks_login_userpass_reply(bro_analyzer(), bro_analyzer()->Conn(), ${reply.code}); return true; diff --git a/src/analyzer/protocol/ssh/SSH.cc b/src/analyzer/protocol/ssh/SSH.cc index f39d125bff..c43a4ce1fc 100644 --- a/src/analyzer/protocol/ssh/SSH.cc +++ b/src/analyzer/protocol/ssh/SSH.cc @@ -91,7 +91,7 @@ void SSH_Analyzer::Undelivered(uint64_t seq, int len, bool orig) void SSH_Analyzer::ProcessEncryptedSegment(int len, bool orig) { if ( ssh_encrypted_packet ) - BifEvent::enqueue_ssh_encrypted_packet(interp->bro_analyzer(), + zeek::BifEvent::enqueue_ssh_encrypted_packet(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), orig, len); @@ -132,9 +132,9 @@ void SSH_Analyzer::ProcessEncrypted(int len, bool orig) { auth_decision_made = true; if ( ssh_auth_attempted ) - BifEvent::enqueue_ssh_auth_attempted(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), true); + zeek::BifEvent::enqueue_ssh_auth_attempted(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), true); if ( ssh_auth_successful ) - BifEvent::enqueue_ssh_auth_successful(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), true); + zeek::BifEvent::enqueue_ssh_auth_successful(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), true); return; } @@ -159,7 +159,7 @@ void SSH_Analyzer::ProcessEncrypted(int len, bool orig) if ( len == userauth_failure_size ) { if ( ssh_auth_attempted ) - BifEvent::enqueue_ssh_auth_attempted(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), false); + zeek::BifEvent::enqueue_ssh_auth_attempted(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), false); return; } @@ -168,9 +168,9 @@ void SSH_Analyzer::ProcessEncrypted(int len, bool orig) { auth_decision_made = true; if ( ssh_auth_attempted ) - BifEvent::enqueue_ssh_auth_attempted(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), true); + zeek::BifEvent::enqueue_ssh_auth_attempted(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), true); if ( ssh_auth_successful ) - BifEvent::enqueue_ssh_auth_successful(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), false); + zeek::BifEvent::enqueue_ssh_auth_successful(interp->bro_analyzer(), interp->bro_analyzer()->Conn(), false); return; } } diff --git a/src/analyzer/protocol/ssh/ssh-analyzer.pac b/src/analyzer/protocol/ssh/ssh-analyzer.pac index 0845e41efa..12fa79634c 100644 --- a/src/analyzer/protocol/ssh/ssh-analyzer.pac +++ b/src/analyzer/protocol/ssh/ssh-analyzer.pac @@ -52,13 +52,13 @@ refine flow SSH_Flow += { %{ if ( ssh_client_version && ${msg.is_orig } ) { - BifEvent::enqueue_ssh_client_version(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_ssh_client_version(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(${msg.version})); } else if ( ssh_server_version ) { - BifEvent::enqueue_ssh_server_version(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_ssh_server_version(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(${msg.version})); } @@ -103,7 +103,7 @@ refine flow SSH_Flow += { result->Assign(6, val_mgr->Bool(!${msg.is_orig})); - BifEvent::enqueue_ssh_capabilities(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_ssh_capabilities(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(${msg.cookie}), result); @@ -115,7 +115,7 @@ refine flow SSH_Flow += { %{ if ( ssh2_dh_server_params ) { - BifEvent::enqueue_ssh2_dh_server_params(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_ssh2_dh_server_params(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(${msg.p.val}), to_stringval(${msg.g.val})); } @@ -126,7 +126,7 @@ refine flow SSH_Flow += { %{ if ( ssh2_ecc_key ) { - BifEvent::enqueue_ssh2_ecc_key(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_ssh2_ecc_key(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), is_orig, to_stringval(q)); } @@ -137,7 +137,7 @@ refine flow SSH_Flow += { %{ if ( ssh2_gss_error ) { - BifEvent::enqueue_ssh2_gss_error(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_ssh2_gss_error(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${msg.major_status}, ${msg.minor_status}, to_stringval(${msg.message.val})); @@ -149,7 +149,7 @@ refine flow SSH_Flow += { %{ if ( ssh2_server_host_key ) { - BifEvent::enqueue_ssh2_server_host_key(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_ssh2_server_host_key(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(${key})); } @@ -160,7 +160,7 @@ refine flow SSH_Flow += { %{ if ( ssh1_server_host_key ) { - BifEvent::enqueue_ssh1_server_host_key(connection()->bro_analyzer(), + zeek::BifEvent::enqueue_ssh1_server_host_key(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), to_stringval(${p}), to_stringval(${e})); diff --git a/src/analyzer/protocol/ssl/proc-client-hello.pac b/src/analyzer/protocol/ssl/proc-client-hello.pac index a1cfca8e59..c98b0772c6 100644 --- a/src/analyzer/protocol/ssl/proc-client-hello.pac +++ b/src/analyzer/protocol/ssl/proc-client-hello.pac @@ -42,7 +42,7 @@ } } - BifEvent::enqueue_ssl_client_hello(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_client_hello(bro_analyzer(), bro_analyzer()->Conn(), version, record_version(), ts, make_intrusive(client_random.length(), (const char*) client_random.data()), diff --git a/src/analyzer/protocol/ssl/proc-server-hello.pac b/src/analyzer/protocol/ssl/proc-server-hello.pac index 843a83e15d..130ff1f9ca 100644 --- a/src/analyzer/protocol/ssl/proc-server-hello.pac +++ b/src/analyzer/protocol/ssl/proc-server-hello.pac @@ -25,7 +25,7 @@ if ( v2 == 0 && server_random.length() >= 4 ) ts = ntohl(*((uint32*)server_random.data())); - BifEvent::enqueue_ssl_server_hello(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_server_hello(bro_analyzer(), bro_analyzer()->Conn(), version, record_version(), ts, make_intrusive(server_random.length(), diff --git a/src/analyzer/protocol/ssl/ssl-analyzer.pac b/src/analyzer/protocol/ssl/ssl-analyzer.pac index 7d7a5a4419..3e2a4a2d6a 100644 --- a/src/analyzer/protocol/ssl/ssl-analyzer.pac +++ b/src/analyzer/protocol/ssl/ssl-analyzer.pac @@ -18,7 +18,7 @@ refine connection SSL_Conn += { function proc_v2_client_master_key(rec: SSLRecord, cipher_kind: int) : bool %{ if ( ssl_established ) - BifEvent::enqueue_ssl_established(bro_analyzer(), bro_analyzer()->Conn()); + zeek::BifEvent::enqueue_ssl_established(bro_analyzer(), bro_analyzer()->Conn()); return true; %} diff --git a/src/analyzer/protocol/ssl/ssl-dtls-analyzer.pac b/src/analyzer/protocol/ssl/ssl-dtls-analyzer.pac index 256ed2d295..47d664ef99 100644 --- a/src/analyzer/protocol/ssl/ssl-dtls-analyzer.pac +++ b/src/analyzer/protocol/ssl/ssl-dtls-analyzer.pac @@ -32,7 +32,7 @@ refine connection SSL_Conn += { function proc_alert(rec: SSLRecord, level : int, desc : int) : bool %{ if ( ssl_alert ) - BifEvent::enqueue_ssl_alert(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_alert(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, level, desc); return true; %} @@ -52,11 +52,11 @@ refine connection SSL_Conn += { { established_ = true; if ( ssl_established ) - BifEvent::enqueue_ssl_established(bro_analyzer(), bro_analyzer()->Conn()); + zeek::BifEvent::enqueue_ssl_established(bro_analyzer(), bro_analyzer()->Conn()); } if ( ssl_encrypted_data ) - BifEvent::enqueue_ssl_encrypted_data(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_encrypted_data(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, ${rec.raw_tls_version}, ${rec.content_type}, ${rec.length}); return true; @@ -65,7 +65,7 @@ refine connection SSL_Conn += { function proc_plaintext_record(rec : SSLRecord) : bool %{ if ( ssl_plaintext_data ) - BifEvent::enqueue_ssl_plaintext_data(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_plaintext_data(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, ${rec.raw_tls_version}, ${rec.content_type}, ${rec.length}); return true; @@ -74,7 +74,7 @@ refine connection SSL_Conn += { function proc_heartbeat(rec : SSLRecord, type: uint8, payload_length: uint16, data: bytestring) : bool %{ if ( ssl_heartbeat ) - BifEvent::enqueue_ssl_heartbeat(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_heartbeat(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, ${rec.length}, type, payload_length, make_intrusive(data.length(), (const char*) data.data())); return true; @@ -96,7 +96,7 @@ refine connection SSL_Conn += { function proc_ccs(rec: SSLRecord) : bool %{ if ( ssl_change_cipher_spec ) - BifEvent::enqueue_ssl_change_cipher_spec(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_change_cipher_spec(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}); return true; diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index a08d94203b..6a8a97f7c8 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -34,7 +34,7 @@ refine connection Handshake_Conn += { %{ if ( ssl_session_ticket_handshake ) { - BifEvent::enqueue_ssl_session_ticket_handshake(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_session_ticket_handshake(bro_analyzer(), bro_analyzer()->Conn(), ${rec.ticket_lifetime_hint}, make_intrusive(${rec.data}.length(), (const char*) ${rec.data}.data())); @@ -64,7 +64,7 @@ refine connection Handshake_Conn += { const unsigned char* data = sourcedata.begin() + 4; if ( ssl_extension ) - BifEvent::enqueue_ssl_extension(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_extension(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, type, make_intrusive(length, reinterpret_cast(data))); return true; @@ -83,7 +83,7 @@ refine connection Handshake_Conn += { points->Assign(i, val_mgr->Count((*point_format_list)[i])); } - BifEvent::enqueue_ssl_extension_ec_point_formats(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_extension_ec_point_formats(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(points)); return true; @@ -102,7 +102,7 @@ refine connection Handshake_Conn += { curves->Assign(i, val_mgr->Count((*list)[i])); } - BifEvent::enqueue_ssl_extension_elliptic_curves(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_extension_elliptic_curves(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(curves)); return true; @@ -121,7 +121,7 @@ refine connection Handshake_Conn += { nglist->Assign(i, val_mgr->Count((*keyshare)[i]->namedgroup())); } - BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); + zeek::BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); return true; %} @@ -134,7 +134,7 @@ refine connection Handshake_Conn += { auto nglist = make_intrusive(zeek::id::index_vec); nglist->Assign(0u, val_mgr->Count(keyshare->namedgroup())); - BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); + zeek::BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); return true; %} @@ -146,7 +146,7 @@ refine connection Handshake_Conn += { auto nglist = make_intrusive(zeek::id::index_vec); nglist->Assign(0u, val_mgr->Count(namedgroup)); - BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); + zeek::BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); return true; %} @@ -168,7 +168,7 @@ refine connection Handshake_Conn += { } } - BifEvent::enqueue_ssl_extension_signature_algorithm(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(slist)); + zeek::BifEvent::enqueue_ssl_extension_signature_algorithm(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(slist)); return true; %} @@ -186,7 +186,7 @@ refine connection Handshake_Conn += { plist->Assign(i, make_intrusive((*protocols)[i]->name().length(), (const char*) (*protocols)[i]->name().data())); } - BifEvent::enqueue_ssl_extension_application_layer_protocol_negotiation(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_extension_application_layer_protocol_negotiation(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(plist)); return true; @@ -215,7 +215,7 @@ refine connection Handshake_Conn += { } if ( ssl_extension_server_name ) - BifEvent::enqueue_ssl_extension_server_name(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_extension_server_name(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(servers)); return true; @@ -234,7 +234,7 @@ refine connection Handshake_Conn += { versions->Assign(i, val_mgr->Count((*versions_list)[i])); } - BifEvent::enqueue_ssl_extension_supported_versions(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_extension_supported_versions(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(versions)); return true; @@ -248,7 +248,7 @@ refine connection Handshake_Conn += { auto versions = make_intrusive(zeek::id::index_vec); versions->Assign(0u, val_mgr->Count(version)); - BifEvent::enqueue_ssl_extension_supported_versions(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_extension_supported_versions(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(versions)); return true; @@ -267,7 +267,7 @@ refine connection Handshake_Conn += { modes->Assign(i, val_mgr->Count((*mode_list)[i])); } - BifEvent::enqueue_ssl_extension_psk_key_exchange_modes(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_extension_psk_key_exchange_modes(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(modes)); return true; @@ -314,7 +314,7 @@ refine connection Handshake_Conn += { bro_analyzer()->Conn(), false, file_id, "application/ocsp-response"); if ( ssl_stapled_ocsp ) - BifEvent::enqueue_ssl_stapled_ocsp(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_stapled_ocsp(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, make_intrusive(response.length(), (const char*) response.data())); @@ -335,7 +335,7 @@ refine connection Handshake_Conn += { return true; if ( ssl_ecdh_server_params ) - BifEvent::enqueue_ssl_ecdh_server_params(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_ecdh_server_params(bro_analyzer(), bro_analyzer()->Conn(), ${kex.params.curve}, make_intrusive(${kex.params.point}.length(), (const char*)${kex.params.point}.data())); @@ -356,7 +356,7 @@ refine connection Handshake_Conn += { ha->Assign(1, val_mgr->Count(256)); } - BifEvent::enqueue_ssl_server_signature(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_server_signature(bro_analyzer(), bro_analyzer()->Conn(), std::move(ha), make_intrusive(${kex.signed_params.signature}.length(), (const char*)(${kex.signed_params.signature}).data())); @@ -371,7 +371,7 @@ refine connection Handshake_Conn += { return true; if ( ssl_ecdh_server_params ) - BifEvent::enqueue_ssl_ecdh_server_params(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_ecdh_server_params(bro_analyzer(), bro_analyzer()->Conn(), ${kex.params.curve}, make_intrusive(${kex.params.point}.length(), (const char*)${kex.params.point}.data())); @@ -382,7 +382,7 @@ refine connection Handshake_Conn += { function proc_rsa_client_key_exchange(rec: HandshakeRecord, rsa_pms: bytestring) : bool %{ if ( ssl_rsa_client_pms ) - BifEvent::enqueue_ssl_rsa_client_pms(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_rsa_client_pms(bro_analyzer(), bro_analyzer()->Conn(), make_intrusive(rsa_pms.length(), (const char*)rsa_pms.data())); @@ -392,7 +392,7 @@ refine connection Handshake_Conn += { function proc_dh_client_key_exchange(rec: HandshakeRecord, Yc: bytestring) : bool %{ if ( ssl_dh_client_params ) - BifEvent::enqueue_ssl_dh_client_params(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_dh_client_params(bro_analyzer(), bro_analyzer()->Conn(), make_intrusive(Yc.length(), (const char*)Yc.data())); @@ -402,7 +402,7 @@ refine connection Handshake_Conn += { function proc_ecdh_client_key_exchange(rec: HandshakeRecord, point: bytestring) : bool %{ if ( ssl_ecdh_client_params ) - BifEvent::enqueue_ssl_ecdh_client_params(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_ecdh_client_params(bro_analyzer(), bro_analyzer()->Conn(), make_intrusive(point.length(), (const char*)point.data())); @@ -418,7 +418,7 @@ refine connection Handshake_Conn += { ha->Assign(0, val_mgr->Count(digitally_signed_algorithms->HashAlgorithm())); ha->Assign(1, val_mgr->Count(digitally_signed_algorithms->SignatureAlgorithm())); - BifEvent::enqueue_ssl_extension_signed_certificate_timestamp(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_extension_signed_certificate_timestamp(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, version, make_intrusive(logid.length(), reinterpret_cast(logid.begin())), @@ -433,7 +433,7 @@ refine connection Handshake_Conn += { function proc_dhe_server_key_exchange(rec: HandshakeRecord, p: bytestring, g: bytestring, Ys: bytestring, signed_params: ServerKeyExchangeSignature) : bool %{ if ( ssl_ecdh_server_params ) - BifEvent::enqueue_ssl_dh_server_params(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_dh_server_params(bro_analyzer(), bro_analyzer()->Conn(), make_intrusive(p.length(), (const char*) p.data()), make_intrusive(g.length(), (const char*) g.data()), @@ -456,7 +456,7 @@ refine connection Handshake_Conn += { ha->Assign(1, val_mgr->Count(256)); } - BifEvent::enqueue_ssl_server_signature(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_server_signature(bro_analyzer(), bro_analyzer()->Conn(), std::move(ha), make_intrusive(${signed_params.signature}.length(), (const char*)(${signed_params.signature}).data()) ); @@ -468,7 +468,7 @@ refine connection Handshake_Conn += { function proc_dh_anon_server_key_exchange(rec: HandshakeRecord, p: bytestring, g: bytestring, Ys: bytestring) : bool %{ if ( ssl_dh_server_params ) - BifEvent::enqueue_ssl_dh_server_params(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_dh_server_params(bro_analyzer(), bro_analyzer()->Conn(), make_intrusive(p.length(), (const char*) p.data()), make_intrusive(g.length(), (const char*) g.data()), @@ -481,7 +481,7 @@ refine connection Handshake_Conn += { function proc_handshake(is_orig: bool, msg_type: uint8, length: uint24) : bool %{ if ( ssl_handshake_message ) - BifEvent::enqueue_ssl_handshake_message(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_handshake_message(bro_analyzer(), bro_analyzer()->Conn(), is_orig, msg_type, to_int()(length)); return true; @@ -513,7 +513,7 @@ refine connection Handshake_Conn += { blist->Assign(blist->Size(), make_intrusive(binder->binder().length(), (const char*) binder->binder().data())); } - BifEvent::enqueue_ssl_extension_pre_shared_key_client_hello(bro_analyzer(), bro_analyzer()->Conn(), + zeek::BifEvent::enqueue_ssl_extension_pre_shared_key_client_hello(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(slist), std::move(blist)); return true; @@ -524,7 +524,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_pre_shared_key_client_hello ) return true; - BifEvent::enqueue_ssl_extension_pre_shared_key_server_hello(bro_analyzer(), + zeek::BifEvent::enqueue_ssl_extension_pre_shared_key_server_hello(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, selected_identity); return true; diff --git a/src/analyzer/protocol/syslog/syslog-analyzer.pac b/src/analyzer/protocol/syslog/syslog-analyzer.pac index 72acb78653..f464abf3b3 100644 --- a/src/analyzer/protocol/syslog/syslog-analyzer.pac +++ b/src/analyzer/protocol/syslog/syslog-analyzer.pac @@ -15,7 +15,7 @@ flow Syslog_Flow return true; if ( ${m.has_pri} ) - BifEvent::enqueue_syslog_message( + zeek::BifEvent::enqueue_syslog_message( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), ${m.PRI.facility}, @@ -23,7 +23,7 @@ flow Syslog_Flow make_intrusive(${m.msg}.length(), (const char*)${m.msg}.begin()) ); else - BifEvent::enqueue_syslog_message( + zeek::BifEvent::enqueue_syslog_message( connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), 999, diff --git a/src/analyzer/protocol/xmpp/xmpp-analyzer.pac b/src/analyzer/protocol/xmpp/xmpp-analyzer.pac index 6c06809098..62bcec8fc5 100644 --- a/src/analyzer/protocol/xmpp/xmpp-analyzer.pac +++ b/src/analyzer/protocol/xmpp/xmpp-analyzer.pac @@ -33,7 +33,7 @@ refine connection XMPP_Conn += { { bro_analyzer()->StartTLS(); if ( xmpp_starttls ) - BifEvent::enqueue_xmpp_starttls(bro_analyzer(), bro_analyzer()->Conn()); + zeek::BifEvent::enqueue_xmpp_starttls(bro_analyzer(), bro_analyzer()->Conn()); } else if ( !is_orig && token == "proceed" ) reporter->Weird(bro_analyzer()->Conn(), "XMPP: proceed without starttls"); diff --git a/testing/btest/plugins/protocol-plugin/src/foo-analyzer.pac b/testing/btest/plugins/protocol-plugin/src/foo-analyzer.pac index 1ef3650e84..0c1fdbfa1a 100644 --- a/testing/btest/plugins/protocol-plugin/src/foo-analyzer.pac +++ b/testing/btest/plugins/protocol-plugin/src/foo-analyzer.pac @@ -4,7 +4,7 @@ refine connection Foo_Conn += { function Foo_data(msg: Foo_Message): bool %{ auto data = make_intrusive(${msg.data}.length(), (const char*) ${msg.data}.data()); - BifEvent::enqueue_foo_message(bro_analyzer(), bro_analyzer()->Conn(), std::move(data)); + zeek::BifEvent::enqueue_foo_message(bro_analyzer(), bro_analyzer()->Conn(), std::move(data)); return true; %} From 4debad8caf40ca30294497ca11bc2bca67beb56f Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 14 May 2020 18:00:18 -0700 Subject: [PATCH 060/151] Switch zeek::id::lookup to zeek::id::find For parity with Scope since it now uses Find instead of Lookup --- NEWS | 8 +- aux/bifcl | 2 +- src/DNS_Mgr.cc | 2 +- src/Discard.cc | 10 +- src/EventHandler.cc | 4 +- src/File.cc | 2 +- src/Func.cc | 28 ++-- src/ID.cc | 34 ++--- src/ID.h | 22 +-- src/IP.cc | 32 ++--- src/NetVar.cc | 130 +++++++++--------- src/Reporter.cc | 14 +- src/RuleCondition.cc | 2 +- src/RuleMatcher.cc | 2 +- src/Sessions.cc | 4 +- src/SmithWaterman.cc | 8 +- src/Stats.cc | 2 +- src/Stmt.cc | 4 +- src/TunnelEncapsulation.h | 2 +- src/Type.cc | 4 +- src/Val.cc | 4 +- src/Var.cc | 8 +- src/Var.h | 22 +-- src/analyzer/Manager.cc | 6 +- .../protocol/bittorrent/BitTorrentTracker.cc | 10 +- src/analyzer/protocol/dns/DNS.cc | 22 +-- src/analyzer/protocol/http/HTTP.cc | 4 +- src/analyzer/protocol/icmp/ICMP.cc | 12 +- src/analyzer/protocol/irc/IRC.cc | 4 +- src/analyzer/protocol/krb/krb-padata.pac | 2 +- src/analyzer/protocol/krb/krb-types.pac | 4 +- src/analyzer/protocol/login/Login.cc | 14 +- src/analyzer/protocol/mime/MIME.cc | 4 +- .../protocol/mqtt/commands/publish.pac | 2 +- src/analyzer/protocol/rpc/Portmap.cc | 8 +- src/analyzer/protocol/sip/sip-analyzer.pac | 4 +- .../protocol/socks/socks-analyzer.pac | 8 +- .../protocol/ssl/tls-handshake-analyzer.pac | 4 +- src/analyzer/protocol/tcp/TCP.cc | 4 +- src/analyzer/protocol/tcp/TCP_Reassembler.cc | 4 +- src/analyzer/protocol/teredo/Teredo.cc | 6 +- src/analyzer/protocol/udp/UDP.cc | 6 +- src/broker/Data.cc | 2 +- src/broker/Manager.cc | 10 +- src/broker/Store.cc | 2 +- src/broker/comm.bif | 8 +- src/file_analysis/Manager.cc | 6 +- src/file_analysis/analyzer/entropy/Entropy.cc | 2 +- src/file_analysis/analyzer/x509/OCSP.cc | 2 +- src/file_analysis/analyzer/x509/X509.cc | 2 +- src/file_analysis/analyzer/x509/functions.bif | 2 +- src/iosource/Packet.cc | 4 +- src/legacy-netvar-init.cc | 112 +++++++-------- src/logging/Manager.cc | 8 +- src/probabilistic/Hasher.cc | 2 +- src/stats.bif | 2 +- src/strings.bif | 2 +- src/zeek-setup.cc | 6 +- src/zeek.bif | 28 ++-- 59 files changed, 339 insertions(+), 339 deletions(-) diff --git a/NEWS b/NEWS index f9dba96980..d81d76a4d8 100644 --- a/NEWS +++ b/NEWS @@ -159,15 +159,15 @@ Deprecated Functionality - ``ID::ID_Val()`` is deprecated, use ``ID::GetVal()``. -- ``internal_type()`` is deprecated, use ``zeek::id::lookup_type()``. +- ``internal_type()`` is deprecated, use ``zeek::id::find_type()``. - ``internal_val()`` and ``internal_const_val()`` are deprecated, use - ``zeek::id::lookup_val()`` or ``zeek::id::lookup_const()``. + ``zeek::id::find_val()`` or ``zeek::id::find_const()``. -- ``internal_func()`` is deprecated, use ``zeek::id::lookup_func()``. +- ``internal_func()`` is deprecated, use ``zeek::id::find_func()``. - ``opt_internal_val()`` is deprecated, use ``lookup_ID()`` or - ``zeek::id::lookup_val()``. + ``zeek::id::find_val()``. - ``Val::Type()`` is deprecated, use ``Val::GetType``. diff --git a/aux/bifcl b/aux/bifcl index b155d04585..2c7ded074f 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit b155d04585c61c8fdd0768e1f2a403b27447bb9d +Subproject commit 2c7ded074fdea124fcae7845d1f8e77879925270 diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index a69ebbe4ce..5b8746e249 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -452,7 +452,7 @@ void DNS_Mgr::InitSource() void DNS_Mgr::InitPostScript() { - dm_rec = zeek::id::lookup_type("dns_mapping")->AsRecordType(); + dm_rec = zeek::id::find_type("dns_mapping")->AsRecordType(); // Registering will call Init() iosource_mgr->Register(this, true); diff --git a/src/Discard.cc b/src/Discard.cc index 20a40b0590..6e5aee9826 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -16,12 +16,12 @@ Discarder::Discarder() { - check_ip = zeek::id::lookup_func("discarder_check_ip"); - check_tcp = zeek::id::lookup_func("discarder_check_tcp"); - check_udp = zeek::id::lookup_func("discarder_check_udp"); - check_icmp = zeek::id::lookup_func("discarder_check_icmp"); + check_ip = zeek::id::find_func("discarder_check_ip"); + check_tcp = zeek::id::find_func("discarder_check_tcp"); + check_udp = zeek::id::find_func("discarder_check_udp"); + check_icmp = zeek::id::find_func("discarder_check_icmp"); - discarder_maxlen = static_cast(zeek::id::lookup_val("discarder_maxlen")->AsCount()); + discarder_maxlen = static_cast(zeek::id::find_val("discarder_maxlen")->AsCount()); } Discarder::~Discarder() diff --git a/src/EventHandler.cc b/src/EventHandler.cc index f9c3e72d47..580d48be27 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -127,7 +127,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) return; RecordType* args = FType()->Args(); - static auto call_argument_vector = zeek::id::lookup_type("call_argument_vector"); + static auto call_argument_vector = zeek::id::find_type("call_argument_vector"); auto vargs = make_intrusive(call_argument_vector); for ( int i = 0; i < args->NumFields(); i++ ) @@ -136,7 +136,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) const auto& ftype = args->GetFieldType(i); auto fdefault = args->FieldDefault(i); - static auto call_argument = zeek::id::lookup_type("call_argument"); + static auto call_argument = zeek::id::find_type("call_argument"); auto rec = make_intrusive(call_argument); rec->Assign(0, make_intrusive(fname)); diff --git a/src/File.cc b/src/File.cc index 9fdafe2651..05c16d2efb 100644 --- a/src/File.cc +++ b/src/File.cc @@ -278,7 +278,7 @@ RecordVal* BroFile::Rotate() if ( f == stdin || f == stdout || f == stderr ) return nullptr; - static auto rotate_info = zeek::id::lookup_type("rotate_info"); + static auto rotate_info = zeek::id::find_type("rotate_info"); RecordVal* info = new RecordVal(rotate_info); FILE* newf = rotate_file(name, info); diff --git a/src/Func.cc b/src/Func.cc index 1ae7e0b8a7..aaa0f9d35a 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -748,21 +748,21 @@ void builtin_error(const char* msg, BroObj* arg) void init_builtin_funcs() { - ProcStats = zeek::id::lookup_type("ProcStats")->AsRecordType(); - NetStats = zeek::id::lookup_type("NetStats")->AsRecordType(); - MatcherStats = zeek::id::lookup_type("MatcherStats")->AsRecordType(); - ConnStats = zeek::id::lookup_type("ConnStats")->AsRecordType(); - ReassemblerStats = zeek::id::lookup_type("ReassemblerStats")->AsRecordType(); - DNSStats = zeek::id::lookup_type("DNSStats")->AsRecordType(); - GapStats = zeek::id::lookup_type("GapStats")->AsRecordType(); - EventStats = zeek::id::lookup_type("EventStats")->AsRecordType(); - TimerStats = zeek::id::lookup_type("TimerStats")->AsRecordType(); - FileAnalysisStats = zeek::id::lookup_type("FileAnalysisStats")->AsRecordType(); - ThreadStats = zeek::id::lookup_type("ThreadStats")->AsRecordType(); - BrokerStats = zeek::id::lookup_type("BrokerStats")->AsRecordType(); - ReporterStats = zeek::id::lookup_type("ReporterStats")->AsRecordType(); + ProcStats = zeek::id::find_type("ProcStats")->AsRecordType(); + NetStats = zeek::id::find_type("NetStats")->AsRecordType(); + MatcherStats = zeek::id::find_type("MatcherStats")->AsRecordType(); + ConnStats = zeek::id::find_type("ConnStats")->AsRecordType(); + ReassemblerStats = zeek::id::find_type("ReassemblerStats")->AsRecordType(); + DNSStats = zeek::id::find_type("DNSStats")->AsRecordType(); + GapStats = zeek::id::find_type("GapStats")->AsRecordType(); + EventStats = zeek::id::find_type("EventStats")->AsRecordType(); + TimerStats = zeek::id::find_type("TimerStats")->AsRecordType(); + FileAnalysisStats = zeek::id::find_type("FileAnalysisStats")->AsRecordType(); + ThreadStats = zeek::id::find_type("ThreadStats")->AsRecordType(); + BrokerStats = zeek::id::find_type("BrokerStats")->AsRecordType(); + ReporterStats = zeek::id::find_type("ReporterStats")->AsRecordType(); - var_sizes = zeek::id::lookup_type("var_sizes")->AsTableType(); + var_sizes = zeek::id::find_type("var_sizes")->AsTableType(); #include "zeek.bif.func_init" #include "stats.bif.func_init" diff --git a/src/ID.cc b/src/ID.cc index da0bc8e6ae..c72137d534 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -31,12 +31,12 @@ IntrusivePtr zeek::id::count_set; IntrusivePtr zeek::id::string_vec; IntrusivePtr zeek::id::index_vec; -const IntrusivePtr& zeek::id::lookup(std::string_view name) +const IntrusivePtr& zeek::id::find(std::string_view name) { return global_scope()->Find(name); } -const IntrusivePtr& zeek::id::lookup_type(std::string_view name) +const IntrusivePtr& zeek::id::find_type(std::string_view name) { auto id = global_scope()->Find(name); @@ -47,7 +47,7 @@ const IntrusivePtr& zeek::id::lookup_type(std::string_view name) return id->GetType(); } -const IntrusivePtr& zeek::id::lookup_val(std::string_view name) +const IntrusivePtr& zeek::id::find_val(std::string_view name) { auto id = global_scope()->Find(name); @@ -58,7 +58,7 @@ const IntrusivePtr& zeek::id::lookup_val(std::string_view name) return id->GetVal(); } -const IntrusivePtr& zeek::id::lookup_const(std::string_view name) +const IntrusivePtr& zeek::id::find_const(std::string_view name) { auto id = global_scope()->Find(name); @@ -73,9 +73,9 @@ const IntrusivePtr& zeek::id::lookup_const(std::string_view name) return id->GetVal(); } -IntrusivePtr zeek::id::lookup_func(std::string_view name) +IntrusivePtr zeek::id::find_func(std::string_view name) { - const auto& v = zeek::id::lookup_val(name); + const auto& v = zeek::id::find_val(name); if ( ! v ) return nullptr; @@ -89,17 +89,17 @@ IntrusivePtr zeek::id::lookup_func(std::string_view name) void zeek::id::detail::init() { - conn_id = lookup_type("conn_id"); - endpoint = lookup_type("endpoint"); - connection = lookup_type("connection"); - fa_file = lookup_type("fa_file"); - fa_metadata = lookup_type("fa_metadata"); - transport_proto = lookup_type("transport_proto"); - string_set = lookup_type("string_set"); - string_array = lookup_type("string_array"); - count_set = lookup_type("count_set"); - string_vec = lookup_type("string_vec"); - index_vec = lookup_type("index_vec"); + conn_id = zeek::id::find_type("conn_id"); + endpoint = zeek::id::find_type("endpoint"); + connection = zeek::id::find_type("connection"); + fa_file = zeek::id::find_type("fa_file"); + fa_metadata = zeek::id::find_type("fa_metadata"); + transport_proto = zeek::id::find_type("transport_proto"); + string_set = zeek::id::find_type("string_set"); + string_array = zeek::id::find_type("string_array"); + count_set = zeek::id::find_type("count_set"); + string_vec = zeek::id::find_type("string_vec"); + index_vec = zeek::id::find_type("index_vec"); } ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) diff --git a/src/ID.h b/src/ID.h index 065c144c89..631bff4179 100644 --- a/src/ID.h +++ b/src/ID.h @@ -166,7 +166,7 @@ namespace zeek { namespace id { * @return The identifier, which may reference a nil object if no such * name exists. */ -const IntrusivePtr& lookup(std::string_view name); +const IntrusivePtr& find(std::string_view name); /** * Lookup an ID by its name and return its type. A fatal occurs if the ID @@ -174,7 +174,7 @@ const IntrusivePtr& lookup(std::string_view name); * @param name The identifier name to lookup * @return The type of the identifier. */ -const IntrusivePtr& lookup_type(std::string_view name); +const IntrusivePtr& find_type(std::string_view name); /** * Lookup an ID by its name and return its type (as cast to @c T). @@ -183,8 +183,8 @@ const IntrusivePtr& lookup_type(std::string_view name); * @return The type of the identifier. */ template -IntrusivePtr lookup_type(std::string_view name) - { return cast_intrusive(lookup_type(name)); } +IntrusivePtr find_type(std::string_view name) + { return cast_intrusive(find_type(name)); } /** * Lookup an ID by its name and return its value. A fatal occurs if the ID @@ -192,7 +192,7 @@ IntrusivePtr lookup_type(std::string_view name) * @param name The identifier name to lookup * @return The current value of the identifier */ -const IntrusivePtr& lookup_val(std::string_view name); +const IntrusivePtr& find_val(std::string_view name); /** * Lookup an ID by its name and return its value (as cast to @c T). @@ -201,8 +201,8 @@ const IntrusivePtr& lookup_val(std::string_view name); * @return The current value of the identifier. */ template -IntrusivePtr lookup_val(std::string_view name) - { return cast_intrusive(lookup_val(name)); } +IntrusivePtr find_val(std::string_view name) + { return cast_intrusive(find_val(name)); } /** * Lookup an ID by its name and return its value. A fatal occurs if the ID @@ -210,7 +210,7 @@ IntrusivePtr lookup_val(std::string_view name) * @param name The identifier name to lookup * @return The current value of the identifier */ -const IntrusivePtr& lookup_const(std::string_view name); +const IntrusivePtr& find_const(std::string_view name); /** * Lookup an ID by its name and return its value (as cast to @c T). @@ -219,8 +219,8 @@ const IntrusivePtr& lookup_const(std::string_view name); * @return The current value of the identifier. */ template -IntrusivePtr lookup_const(std::string_view name) - { return cast_intrusive(lookup_const(name)); } +IntrusivePtr find_const(std::string_view name) + { return cast_intrusive(find_const(name)); } /** * Lookup an ID by its name and return the function it references. @@ -228,7 +228,7 @@ IntrusivePtr lookup_const(std::string_view name) * @param name The identifier name to lookup * @return The current function value the identifier references. */ -IntrusivePtr lookup_func(std::string_view name); +IntrusivePtr find_func(std::string_view name); extern IntrusivePtr conn_id; extern IntrusivePtr endpoint; diff --git a/src/IP.cc b/src/IP.cc index a451cf26d8..40e76b68d1 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -37,14 +37,14 @@ static RecordType* ip6_mob_be_type = nullptr; static inline RecordType* hdrType(RecordType*& type, const char* name) { if ( ! type ) - type = zeek::id::lookup_type(name)->AsRecordType(); + type = zeek::id::find_type(name)->AsRecordType(); return type; } static IntrusivePtr BuildOptionsVal(const u_char* data, int len) { - auto vv = make_intrusive(zeek::id::lookup_type("ip6_options")); + auto vv = make_intrusive(zeek::id::find_type("ip6_options")); while ( len > 0 ) { @@ -95,7 +95,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const rv->Assign(6, make_intrusive(IPAddr(ip6->ip6_dst))); if ( ! chain ) chain = make_intrusive( - zeek::id::lookup_type("ip6_ext_hdr_chain")); + zeek::id::find_type("ip6_ext_hdr_chain")); rv->Assign(7, std::move(chain)); } break; @@ -367,7 +367,7 @@ IntrusivePtr IP_Hdr::ToPktHdrVal() const static RecordType* pkt_hdr_type = nullptr; if ( ! pkt_hdr_type ) - pkt_hdr_type = zeek::id::lookup_type("pkt_hdr")->AsRecordType(); + pkt_hdr_type = zeek::id::find_type("pkt_hdr")->AsRecordType(); return ToPktHdrVal(make_intrusive(pkt_hdr_type), 0); } @@ -385,9 +385,9 @@ IntrusivePtr IP_Hdr::ToPktHdrVal(IntrusivePtr pkt_hdr, int if ( ! tcp_hdr_type ) { - tcp_hdr_type = zeek::id::lookup_type("tcp_hdr")->AsRecordType(); - udp_hdr_type = zeek::id::lookup_type("udp_hdr")->AsRecordType(); - icmp_hdr_type = zeek::id::lookup_type("icmp_hdr")->AsRecordType(); + tcp_hdr_type = zeek::id::find_type("tcp_hdr")->AsRecordType(); + udp_hdr_type = zeek::id::find_type("udp_hdr")->AsRecordType(); + icmp_hdr_type = zeek::id::find_type("icmp_hdr")->AsRecordType(); } if ( ip4 ) @@ -697,18 +697,18 @@ IntrusivePtr IPv6_Hdr_Chain::ToVal() const { if ( ! ip6_ext_hdr_type ) { - ip6_ext_hdr_type = zeek::id::lookup_type("ip6_ext_hdr")->AsRecordType(); - ip6_hopopts_type = zeek::id::lookup_type("ip6_hopopts")->AsRecordType(); - ip6_dstopts_type = zeek::id::lookup_type("ip6_dstopts")->AsRecordType(); - ip6_routing_type = zeek::id::lookup_type("ip6_routing")->AsRecordType(); - ip6_fragment_type = zeek::id::lookup_type("ip6_fragment")->AsRecordType(); - ip6_ah_type = zeek::id::lookup_type("ip6_ah")->AsRecordType(); - ip6_esp_type = zeek::id::lookup_type("ip6_esp")->AsRecordType(); - ip6_mob_type = zeek::id::lookup_type("ip6_mobility_hdr")->AsRecordType(); + ip6_ext_hdr_type = zeek::id::find_type("ip6_ext_hdr")->AsRecordType(); + ip6_hopopts_type = zeek::id::find_type("ip6_hopopts")->AsRecordType(); + ip6_dstopts_type = zeek::id::find_type("ip6_dstopts")->AsRecordType(); + ip6_routing_type = zeek::id::find_type("ip6_routing")->AsRecordType(); + ip6_fragment_type = zeek::id::find_type("ip6_fragment")->AsRecordType(); + ip6_ah_type = zeek::id::find_type("ip6_ah")->AsRecordType(); + ip6_esp_type = zeek::id::find_type("ip6_esp")->AsRecordType(); + ip6_mob_type = zeek::id::find_type("ip6_mobility_hdr")->AsRecordType(); } auto rval = make_intrusive( - zeek::id::lookup_type("ip6_ext_hdr_chain")); + zeek::id::find_type("ip6_ext_hdr_chain")); for ( size_t i = 1; i < chain.size(); ++i ) { diff --git a/src/NetVar.cc b/src/NetVar.cc index 3d39a08da6..535350b4eb 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -198,14 +198,14 @@ void init_event_handlers() void init_general_global_var() { - table_expire_interval = zeek::id::lookup_val("table_expire_interval")->AsInterval(); - table_expire_delay = zeek::id::lookup_val("table_expire_delay")->AsInterval(); - table_incremental_step = zeek::id::lookup_val("table_incremental_step")->AsCount(); - packet_filter_default = zeek::id::lookup_val("packet_filter_default")->AsBool(); - sig_max_group_size = zeek::id::lookup_val("sig_max_group_size")->AsCount(); - check_for_unused_event_handlers = zeek::id::lookup_val("check_for_unused_event_handlers")->AsBool(); - record_all_packets = zeek::id::lookup_val("record_all_packets")->AsBool(); - bits_per_uid = zeek::id::lookup_val("bits_per_uid")->AsCount(); + table_expire_interval = zeek::id::find_val("table_expire_interval")->AsInterval(); + table_expire_delay = zeek::id::find_val("table_expire_delay")->AsInterval(); + table_incremental_step = zeek::id::find_val("table_incremental_step")->AsCount(); + packet_filter_default = zeek::id::find_val("packet_filter_default")->AsBool(); + sig_max_group_size = zeek::id::find_val("sig_max_group_size")->AsCount(); + check_for_unused_event_handlers = zeek::id::find_val("check_for_unused_event_handlers")->AsBool(); + record_all_packets = zeek::id::find_val("record_all_packets")->AsBool(); + bits_per_uid = zeek::id::find_val("bits_per_uid")->AsCount(); } extern void zeek_legacy_netvar_init(); @@ -220,102 +220,102 @@ void init_net_var() zeek::id::detail::init(); zeek_legacy_netvar_init(); - ignore_checksums = zeek::id::lookup_val("ignore_checksums")->AsBool(); - partial_connection_ok = zeek::id::lookup_val("partial_connection_ok")->AsBool(); - tcp_SYN_ack_ok = zeek::id::lookup_val("tcp_SYN_ack_ok")->AsBool(); - tcp_match_undelivered = zeek::id::lookup_val("tcp_match_undelivered")->AsBool(); + ignore_checksums = zeek::id::find_val("ignore_checksums")->AsBool(); + partial_connection_ok = zeek::id::find_val("partial_connection_ok")->AsBool(); + tcp_SYN_ack_ok = zeek::id::find_val("tcp_SYN_ack_ok")->AsBool(); + tcp_match_undelivered = zeek::id::find_val("tcp_match_undelivered")->AsBool(); - encap_hdr_size = zeek::id::lookup_val("encap_hdr_size")->AsCount(); + encap_hdr_size = zeek::id::find_val("encap_hdr_size")->AsCount(); - frag_timeout = zeek::id::lookup_val("frag_timeout")->AsInterval(); + frag_timeout = zeek::id::find_val("frag_timeout")->AsInterval(); - tcp_SYN_timeout = zeek::id::lookup_val("tcp_SYN_timeout")->AsInterval(); - tcp_session_timer = zeek::id::lookup_val("tcp_session_timer")->AsInterval(); - tcp_connection_linger = zeek::id::lookup_val("tcp_connection_linger")->AsInterval(); - tcp_attempt_delay = zeek::id::lookup_val("tcp_attempt_delay")->AsInterval(); - tcp_close_delay = zeek::id::lookup_val("tcp_close_delay")->AsInterval(); - tcp_reset_delay = zeek::id::lookup_val("tcp_reset_delay")->AsInterval(); - tcp_partial_close_delay = zeek::id::lookup_val("tcp_partial_close_delay")->AsInterval(); + tcp_SYN_timeout = zeek::id::find_val("tcp_SYN_timeout")->AsInterval(); + tcp_session_timer = zeek::id::find_val("tcp_session_timer")->AsInterval(); + tcp_connection_linger = zeek::id::find_val("tcp_connection_linger")->AsInterval(); + tcp_attempt_delay = zeek::id::find_val("tcp_attempt_delay")->AsInterval(); + tcp_close_delay = zeek::id::find_val("tcp_close_delay")->AsInterval(); + tcp_reset_delay = zeek::id::find_val("tcp_reset_delay")->AsInterval(); + tcp_partial_close_delay = zeek::id::find_val("tcp_partial_close_delay")->AsInterval(); - tcp_max_initial_window = zeek::id::lookup_val("tcp_max_initial_window")->AsCount(); - tcp_max_above_hole_without_any_acks = zeek::id::lookup_val("tcp_max_above_hole_without_any_acks")->AsCount(); - tcp_excessive_data_without_further_acks = zeek::id::lookup_val("tcp_excessive_data_without_further_acks")->AsCount(); - tcp_max_old_segments = zeek::id::lookup_val("tcp_max_old_segments")->AsCount(); + tcp_max_initial_window = zeek::id::find_val("tcp_max_initial_window")->AsCount(); + tcp_max_above_hole_without_any_acks = zeek::id::find_val("tcp_max_above_hole_without_any_acks")->AsCount(); + tcp_excessive_data_without_further_acks = zeek::id::find_val("tcp_excessive_data_without_further_acks")->AsCount(); + tcp_max_old_segments = zeek::id::find_val("tcp_max_old_segments")->AsCount(); - non_analyzed_lifetime = zeek::id::lookup_val("non_analyzed_lifetime")->AsInterval(); - tcp_inactivity_timeout = zeek::id::lookup_val("tcp_inactivity_timeout")->AsInterval(); - udp_inactivity_timeout = zeek::id::lookup_val("udp_inactivity_timeout")->AsInterval(); - icmp_inactivity_timeout = zeek::id::lookup_val("icmp_inactivity_timeout")->AsInterval(); + non_analyzed_lifetime = zeek::id::find_val("non_analyzed_lifetime")->AsInterval(); + tcp_inactivity_timeout = zeek::id::find_val("tcp_inactivity_timeout")->AsInterval(); + udp_inactivity_timeout = zeek::id::find_val("udp_inactivity_timeout")->AsInterval(); + icmp_inactivity_timeout = zeek::id::find_val("icmp_inactivity_timeout")->AsInterval(); - tcp_storm_thresh = zeek::id::lookup_val("tcp_storm_thresh")->AsCount(); - tcp_storm_interarrival_thresh = zeek::id::lookup_val("tcp_storm_interarrival_thresh")->AsInterval(); + tcp_storm_thresh = zeek::id::find_val("tcp_storm_thresh")->AsCount(); + tcp_storm_interarrival_thresh = zeek::id::find_val("tcp_storm_interarrival_thresh")->AsInterval(); tcp_content_deliver_all_orig = - bool(zeek::id::lookup_val("tcp_content_deliver_all_orig")->AsBool()); + bool(zeek::id::find_val("tcp_content_deliver_all_orig")->AsBool()); tcp_content_deliver_all_resp = - bool(zeek::id::lookup_val("tcp_content_deliver_all_resp")->AsBool()); + bool(zeek::id::find_val("tcp_content_deliver_all_resp")->AsBool()); udp_content_deliver_all_orig = - bool(zeek::id::lookup_val("udp_content_deliver_all_orig")->AsBool()); + bool(zeek::id::find_val("udp_content_deliver_all_orig")->AsBool()); udp_content_deliver_all_resp = - bool(zeek::id::lookup_val("udp_content_deliver_all_resp")->AsBool()); + bool(zeek::id::find_val("udp_content_deliver_all_resp")->AsBool()); udp_content_delivery_ports_use_resp = - bool(zeek::id::lookup_val("udp_content_delivery_ports_use_resp")->AsBool()); + bool(zeek::id::find_val("udp_content_delivery_ports_use_resp")->AsBool()); - dns_session_timeout = zeek::id::lookup_val("dns_session_timeout")->AsInterval(); - rpc_timeout = zeek::id::lookup_val("rpc_timeout")->AsInterval(); + dns_session_timeout = zeek::id::find_val("dns_session_timeout")->AsInterval(); + rpc_timeout = zeek::id::find_val("rpc_timeout")->AsInterval(); - watchdog_interval = int(zeek::id::lookup_val("watchdog_interval")->AsInterval()); + watchdog_interval = int(zeek::id::find_val("watchdog_interval")->AsInterval()); - max_timer_expires = zeek::id::lookup_val("max_timer_expires")->AsCount(); + max_timer_expires = zeek::id::find_val("max_timer_expires")->AsCount(); - mime_segment_length = zeek::id::lookup_val("mime_segment_length")->AsCount(); - mime_segment_overlap_length = zeek::id::lookup_val("mime_segment_overlap_length")->AsCount(); + mime_segment_length = zeek::id::find_val("mime_segment_length")->AsCount(); + mime_segment_overlap_length = zeek::id::find_val("mime_segment_overlap_length")->AsCount(); - http_entity_data_delivery_size = zeek::id::lookup_val("http_entity_data_delivery_size")->AsCount(); - truncate_http_URI = zeek::id::lookup_val("truncate_http_URI")->AsInt(); + http_entity_data_delivery_size = zeek::id::find_val("http_entity_data_delivery_size")->AsCount(); + truncate_http_URI = zeek::id::find_val("truncate_http_URI")->AsInt(); - dns_skip_all_auth = zeek::id::lookup_val("dns_skip_all_auth")->AsBool(); - dns_skip_all_addl = zeek::id::lookup_val("dns_skip_all_addl")->AsBool(); - dns_max_queries = zeek::id::lookup_val("dns_max_queries")->AsCount(); + dns_skip_all_auth = zeek::id::find_val("dns_skip_all_auth")->AsBool(); + dns_skip_all_addl = zeek::id::find_val("dns_skip_all_addl")->AsBool(); + dns_max_queries = zeek::id::find_val("dns_max_queries")->AsCount(); stp_delta = 0.0; - if ( const auto& v = zeek::id::lookup_val("stp_delta") ) stp_delta = v->AsInterval(); + if ( const auto& v = zeek::id::find_val("stp_delta") ) stp_delta = v->AsInterval(); stp_idle_min = 0.0; - if ( const auto& v = zeek::id::lookup_val("stp_idle_min") ) stp_delta = v->AsInterval(); + if ( const auto& v = zeek::id::find_val("stp_idle_min") ) stp_delta = v->AsInterval(); orig_addr_anonymization = 0; - if ( const auto& id = zeek::id::lookup("orig_addr_anonymization") ) + if ( const auto& id = zeek::id::find("orig_addr_anonymization") ) if ( const auto& v = id->GetVal() ) orig_addr_anonymization = v->AsInt(); resp_addr_anonymization = 0; - if ( const auto& id = zeek::id::lookup("resp_addr_anonymization") ) + if ( const auto& id = zeek::id::find("resp_addr_anonymization") ) if ( const auto& v = id->GetVal() ) resp_addr_anonymization = v->AsInt(); other_addr_anonymization = 0; - if ( const auto& id = zeek::id::lookup("other_addr_anonymization") ) + if ( const auto& id = zeek::id::find("other_addr_anonymization") ) if ( const auto& v = id->GetVal() ) other_addr_anonymization = v->AsInt(); connection_status_update_interval = 0.0; - if ( const auto& id = zeek::id::lookup("connection_status_update_interval") ) + if ( const auto& id = zeek::id::find("connection_status_update_interval") ) if ( const auto& v = id->GetVal() ) connection_status_update_interval = v->AsInterval(); - expensive_profiling_multiple = zeek::id::lookup_val("expensive_profiling_multiple")->AsCount(); - profiling_interval = zeek::id::lookup_val("profiling_interval")->AsInterval(); - segment_profiling = zeek::id::lookup_val("segment_profiling")->AsBool(); + expensive_profiling_multiple = zeek::id::find_val("expensive_profiling_multiple")->AsCount(); + profiling_interval = zeek::id::find_val("profiling_interval")->AsInterval(); + segment_profiling = zeek::id::find_val("segment_profiling")->AsBool(); - pkt_profile_mode = zeek::id::lookup_val("pkt_profile_mode")->InternalInt(); - pkt_profile_freq = zeek::id::lookup_val("pkt_profile_freq")->AsDouble(); + pkt_profile_mode = zeek::id::find_val("pkt_profile_mode")->InternalInt(); + pkt_profile_freq = zeek::id::find_val("pkt_profile_freq")->AsDouble(); - load_sample_freq = zeek::id::lookup_val("load_sample_freq")->AsCount(); + load_sample_freq = zeek::id::find_val("load_sample_freq")->AsCount(); - dpd_reassemble_first_packets = zeek::id::lookup_val("dpd_reassemble_first_packets")->AsBool(); - dpd_buffer_size = zeek::id::lookup_val("dpd_buffer_size")->AsCount(); - dpd_match_only_beginning = zeek::id::lookup_val("dpd_match_only_beginning")->AsBool(); - dpd_late_match_stop = zeek::id::lookup_val("dpd_late_match_stop")->AsBool(); - dpd_ignore_ports = zeek::id::lookup_val("dpd_ignore_ports")->AsBool(); + dpd_reassemble_first_packets = zeek::id::find_val("dpd_reassemble_first_packets")->AsBool(); + dpd_buffer_size = zeek::id::find_val("dpd_buffer_size")->AsCount(); + dpd_match_only_beginning = zeek::id::find_val("dpd_match_only_beginning")->AsBool(); + dpd_late_match_stop = zeek::id::find_val("dpd_late_match_stop")->AsBool(); + dpd_ignore_ports = zeek::id::find_val("dpd_ignore_ports")->AsBool(); - timer_mgr_inactivity_timeout = zeek::id::lookup_val("timer_mgr_inactivity_timeout")->AsInterval(); + timer_mgr_inactivity_timeout = zeek::id::find_val("timer_mgr_inactivity_timeout")->AsInterval(); } diff --git a/src/Reporter.cc b/src/Reporter.cc index 77dec0c326..923d74615f 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -63,13 +63,13 @@ Reporter::~Reporter() void Reporter::InitOptions() { - info_to_stderr = zeek::id::lookup_val("Reporter::info_to_stderr")->AsBool(); - warnings_to_stderr = zeek::id::lookup_val("Reporter::warnings_to_stderr")->AsBool(); - errors_to_stderr = zeek::id::lookup_val("Reporter::errors_to_stderr")->AsBool(); - weird_sampling_rate = zeek::id::lookup_val("Weird::sampling_rate")->AsCount(); - weird_sampling_threshold = zeek::id::lookup_val("Weird::sampling_threshold")->AsCount(); - weird_sampling_duration = zeek::id::lookup_val("Weird::sampling_duration")->AsInterval(); - auto wl_val = zeek::id::lookup_val("Weird::sampling_whitelist")->AsTableVal(); + info_to_stderr = zeek::id::find_val("Reporter::info_to_stderr")->AsBool(); + warnings_to_stderr = zeek::id::find_val("Reporter::warnings_to_stderr")->AsBool(); + errors_to_stderr = zeek::id::find_val("Reporter::errors_to_stderr")->AsBool(); + weird_sampling_rate = zeek::id::find_val("Weird::sampling_rate")->AsCount(); + weird_sampling_threshold = zeek::id::find_val("Weird::sampling_threshold")->AsCount(); + weird_sampling_duration = zeek::id::find_val("Weird::sampling_duration")->AsInterval(); + auto wl_val = zeek::id::find_val("Weird::sampling_whitelist")->AsTableVal(); auto wl_table = wl_val->AsTable(); HashKey* k; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 9cb335e8e0..86c5bbdb63 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -144,7 +144,7 @@ RuleConditionEval::RuleConditionEval(const char* func) if ( f->Yield()->Tag() != TYPE_BOOL ) rules_error("eval function type must yield a 'bool'", func); - static auto signature_state = zeek::id::lookup_type("signature_state"); + static auto signature_state = zeek::id::find_type("signature_state"); TypeList tl; tl.Append(signature_state); tl.Append(base_type(TYPE_STRING)); diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index 75baa10f9b..2e79ed185f 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -80,7 +80,7 @@ RuleHdrTest::RuleHdrTest(Prot arg_prot, Comp arg_comp, vector arg_v) Val* RuleMatcher::BuildRuleStateValue(const Rule* rule, const RuleEndpointState* state) const { - static auto signature_state = zeek::id::lookup_type("signature_state"); + static auto signature_state = zeek::id::find_type("signature_state"); RecordVal* val = new RecordVal(signature_state); val->Assign(0, make_intrusive(rule->ID())); val->Assign(1, state->GetAnalyzer()->ConnVal()); diff --git a/src/Sessions.cc b/src/Sessions.cc index 56a40d0964..f28f335968 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -81,7 +81,7 @@ NetSessions::NetSessions() dump_this_packet = false; num_packets_processed = 0; - static auto pkt_profile_file = zeek::id::lookup_val("pkt_profile_file"); + static auto pkt_profile_file = zeek::id::find_val("pkt_profile_file"); if ( pkt_profile_mode && pkt_profile_freq > 0 && pkt_profile_file ) pkt_profiler = new PacketProfiler(pkt_profile_mode, @@ -1219,7 +1219,7 @@ bool NetSessions::IsLikelyServerPort(uint32_t port, TransportProto proto) const if ( ! have_cache ) { - auto likely_server_ports = zeek::id::lookup_val("likely_server_ports"); + auto likely_server_ports = zeek::id::find_val("likely_server_ports"); auto lv = likely_server_ports->ToPureListVal(); for ( int i = 0; i < lv->Length(); i++ ) port_cache.insert(lv->Idx(i)->InternalUnsigned()); diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index 3f10077f6d..6409fa2d1b 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -59,19 +59,19 @@ bool BroSubstring::DoesCover(const BroSubstring* bst) const VectorVal* BroSubstring::VecToPolicy(Vec* vec) { RecordType* sw_substring_type = - zeek::id::lookup_type("sw_substring")->AsRecordType(); + zeek::id::find_type("sw_substring")->AsRecordType(); if ( ! sw_substring_type ) return nullptr; RecordType* sw_align_type = - zeek::id::lookup_type("sw_align")->AsRecordType(); + zeek::id::find_type("sw_align")->AsRecordType(); if ( ! sw_align_type ) return nullptr; - auto sw_align_vec_type = zeek::id::lookup_type("sw_align_vec"); + auto sw_align_vec_type = zeek::id::find_type("sw_align_vec"); auto result = - make_intrusive(zeek::id::lookup_type("sw_substring_vec")); + make_intrusive(zeek::id::find_type("sw_substring_vec")); if ( vec ) { diff --git a/src/Stats.cc b/src/Stats.cc index 5f47644f74..2b2c187c73 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -342,7 +342,7 @@ SampleLogger::SampleLogger() static TableType* load_sample_info = nullptr; if ( ! load_sample_info ) - load_sample_info = zeek::id::lookup_type("load_sample_info")->AsTableType(); + load_sample_info = zeek::id::find_type("load_sample_info")->AsTableType(); load_samples = new TableVal({NewRef{}, load_sample_info}); } diff --git a/src/Stmt.cc b/src/Stmt.cc index 9dda3e1bdd..015378633a 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -201,7 +201,7 @@ static IntrusivePtr lookup_enum_val(const char* module_name, const char static void print_log(const std::vector>& vals) { auto plval = lookup_enum_val("Log", "PRINTLOG"); - auto record = make_intrusive(zeek::id::lookup_type("Log::PrintLogInfo")->AsRecordType()); + auto record = make_intrusive(zeek::id::find_type("Log::PrintLogInfo")->AsRecordType()); auto vec = make_intrusive(zeek::id::string_vec); for ( const auto& val : vals ) @@ -237,7 +237,7 @@ IntrusivePtr PrintStmt::DoExec(std::vector> vals, } static auto print_log_type = static_cast( - zeek::id::lookup_val("Log::print_to_log")->AsEnum()); + zeek::id::find_val("Log::print_to_log")->AsEnum()); switch ( print_log_type ) { case BifEnum::Log::REDIRECT_NONE: diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 36933153d7..3b2a06db49 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -198,7 +198,7 @@ public: IntrusivePtr ToVal() const { auto vv = make_intrusive( - zeek::id::lookup_type("EncapsulatingConnVector")); + zeek::id::find_type("EncapsulatingConnVector")); if ( conns ) { diff --git a/src/Type.cc b/src/Type.cc index c7fd3cdbaa..17c2dad221 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -796,8 +796,8 @@ static string container_type_name(const BroType* ft) IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const { - static auto record_field = zeek::id::lookup_type("record_field"); - static auto record_field_table = zeek::id::lookup_type("record_field_table"); + static auto record_field = zeek::id::find_type("record_field"); + static auto record_field_table = zeek::id::find_type("record_field_table"); auto rval = make_intrusive(record_field_table); for ( int i = 0; i < NumFields(); ++i ) diff --git a/src/Val.cc b/src/Val.cc index e721f42dc0..94ee1ebca7 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -411,7 +411,7 @@ bool Val::WouldOverflow(const BroType* from_type, const BroType* to_type, const IntrusivePtr Val::GetRecordFields() { - static auto record_field_table = zeek::id::lookup_type("record_field_table"); + static auto record_field_table = zeek::id::find_type("record_field_table"); auto t = GetType().get(); if ( t->Tag() != TYPE_RECORD && t->Tag() != TYPE_TYPE ) @@ -1931,7 +1931,7 @@ IntrusivePtr TableVal::LookupSubnets(const SubNetVal* search) if ( ! subnets ) reporter->InternalError("LookupSubnets called on wrong table type"); - auto result = make_intrusive(zeek::id::lookup_type("subnet_vec")); + auto result = make_intrusive(zeek::id::find_type("subnet_vec")); auto matches = subnets->FindAll(search); for ( auto element : matches ) diff --git a/src/Var.cc b/src/Var.cc index a58a1dbe4c..73f0944c5e 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -658,7 +658,7 @@ void end_func(IntrusivePtr body) Val* internal_val(const char* name) { - return zeek::id::lookup_val(name).get(); + return zeek::id::find_val(name).get(); } id_list gather_outer_ids(Scope* scope, Stmt* body) @@ -683,7 +683,7 @@ id_list gather_outer_ids(Scope* scope, Stmt* body) Val* internal_const_val(const char* name) { - return zeek::id::lookup_const(name).get(); + return zeek::id::find_const(name).get(); } Val* opt_internal_val(const char* name) @@ -761,12 +761,12 @@ ListVal* internal_list_val(const char* name) BroType* internal_type(const char* name) { - return zeek::id::lookup_type(name).get(); + return zeek::id::find_type(name).get(); } Func* internal_func(const char* name) { - const auto& v = zeek::id::lookup_val(name); + const auto& v = zeek::id::find_val(name); if ( v ) return v->AsFunc(); diff --git a/src/Var.h b/src/Var.h index 49a60e32e3..67d8928639 100644 --- a/src/Var.h +++ b/src/Var.h @@ -40,37 +40,37 @@ extern void end_func(IntrusivePtr body); // Gather all IDs referenced inside a body that aren't part of a given scope. extern id_list gather_outer_ids(Scope* scope, Stmt* body); -[[deprecated("Remove in v4.1. Use zeek::id::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find_val().")]] extern Val* internal_val(const char* name); -[[deprecated("Remove in v4.1. Use zeek::id::lookup_const().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find_const().")]] extern Val* internal_const_val(const char* name); // internal error if not const -[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find() or zeek::id::find_val().")]] extern Val* opt_internal_val(const char* name); // returns nil if not defined -[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find() or zeek::id::find_val().")]] extern double opt_internal_double(const char* name); -[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find() or zeek::id::find_val().")]] extern bro_int_t opt_internal_int(const char* name); -[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find() or zeek::id::find_val().")]] extern bro_uint_t opt_internal_unsigned(const char* name); -[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find() or zeek::id::find_val().")]] extern StringVal* opt_internal_string(const char* name); -[[deprecated("Remove in v4.1. Use zeek::id::lookup() or zeek::id::lookup_val().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find() or zeek::id::find_val().")]] extern TableVal* opt_internal_table(const char* name); // nil if not defined -[[deprecated("Remove in v4.1. Use zeek::id::lookup(), zeek::id::lookup_val(), and/or TableVal::ToPureListVal().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find(), zeek::id::find_val(), and/or TableVal::ToPureListVal().")]] extern ListVal* internal_list_val(const char* name); -[[deprecated("Remove in v4.1. Use zeek::id::lookup_type().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find_type().")]] extern BroType* internal_type(const char* name); -[[deprecated("Remove in v4.1. Use zeek::id::lookup_func().")]] +[[deprecated("Remove in v4.1. Use zeek::id::find_func().")]] extern Func* internal_func(const char* name); [[deprecated("Remove in v4.1. Use event_registry->Register().")]] diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index 9e339280da..2925f012cb 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -438,8 +438,8 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) if ( tcp_contents && ! reass ) { - static auto tcp_content_delivery_ports_orig = zeek::id::lookup_val("tcp_content_delivery_ports_orig"); - static auto tcp_content_delivery_ports_resp = zeek::id::lookup_val("tcp_content_delivery_ports_resp"); + static auto tcp_content_delivery_ports_orig = zeek::id::find_val("tcp_content_delivery_ports_orig"); + static auto tcp_content_delivery_ports_resp = zeek::id::find_val("tcp_content_delivery_ports_resp"); const auto& dport = val_mgr->Port(ntohs(conn->RespPort()), TRANSPORT_TCP); if ( ! reass ) @@ -462,7 +462,7 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) uint16_t resp_port = ntohs(conn->RespPort()); if ( resp_port == 22 || resp_port == 23 || resp_port == 513 ) { - static auto stp_skip_src = zeek::id::lookup_val("stp_skip_src"); + static auto stp_skip_src = zeek::id::find_val("stp_skip_src"); AddrVal src(conn->OrigAddr()); if ( ! stp_skip_src->Lookup(&src) ) diff --git a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc index 5c8f56b148..5f35156fef 100644 --- a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc +++ b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc @@ -27,15 +27,15 @@ BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) if ( ! bt_tracker_headers ) { bt_tracker_headers = - zeek::id::lookup_type("bt_tracker_headers")->AsTableType(); + zeek::id::find_type("bt_tracker_headers")->AsTableType(); bittorrent_peer = - zeek::id::lookup_type("bittorrent_peer")->AsRecordType(); + zeek::id::find_type("bittorrent_peer")->AsRecordType(); bittorrent_peer_set = - zeek::id::lookup_type("bittorrent_peer_set")->AsTableType(); + zeek::id::find_type("bittorrent_peer_set")->AsTableType(); bittorrent_benc_value = - zeek::id::lookup_type("bittorrent_benc_value")->AsRecordType(); + zeek::id::find_type("bittorrent_benc_value")->AsRecordType(); bittorrent_benc_dir = - zeek::id::lookup_type("bittorrent_benc_dir")->AsTableType(); + zeek::id::find_type("bittorrent_benc_dir")->AsTableType(); } keep_alive = false; diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 12d6dc4f1b..d2283a31b1 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -91,8 +91,8 @@ void DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) int skip_addl = dns_skip_all_addl; if ( msg.ancount > 0 ) { // We did an answer, so can potentially skip auth/addl. - static auto dns_skip_auth = zeek::id::lookup_val("dns_skip_auth"); - static auto dns_skip_addl = zeek::id::lookup_val("dns_skip_addl"); + static auto dns_skip_auth = zeek::id::find_val("dns_skip_auth"); + static auto dns_skip_addl = zeek::id::find_val("dns_skip_addl"); skip_auth = skip_auth || msg.nscount == 0 || dns_skip_auth->Lookup(&server); @@ -595,7 +595,7 @@ bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, if ( dns_SOA_reply && ! msg->skip_event ) { - static auto dns_soa = zeek::id::lookup_type("dns_soa"); + static auto dns_soa = zeek::id::find_type("dns_soa"); auto r = make_intrusive(dns_soa); r->Assign(0, make_intrusive(new BroString(mname, mname_end - mname, true))); r->Assign(1, make_intrusive(new BroString(rname, rname_end - rname, true))); @@ -1439,7 +1439,7 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query) IntrusivePtr DNS_MsgInfo::BuildHdrVal() { - static auto dns_msg = zeek::id::lookup_type("dns_msg"); + static auto dns_msg = zeek::id::find_type("dns_msg"); auto r = make_intrusive(dns_msg); r->Assign(0, val_mgr->Count(id)); @@ -1461,7 +1461,7 @@ IntrusivePtr DNS_MsgInfo::BuildHdrVal() IntrusivePtr DNS_MsgInfo::BuildAnswerVal() { - static auto dns_answer = zeek::id::lookup_type("dns_answer"); + static auto dns_answer = zeek::id::find_type("dns_answer"); auto r = make_intrusive(dns_answer); r->Assign(0, val_mgr->Count(int(answer_type))); @@ -1477,7 +1477,7 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() { // We have to treat the additional record type in EDNS differently // than a regular resource record. - static auto dns_edns_additional = zeek::id::lookup_type("dns_edns_additional"); + static auto dns_edns_additional = zeek::id::find_type("dns_edns_additional"); auto r = make_intrusive(dns_edns_additional); r->Assign(0, val_mgr->Count(int(answer_type))); @@ -1511,7 +1511,7 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) { - static auto dns_tsig_additional = zeek::id::lookup_type("dns_tsig_additional"); + static auto dns_tsig_additional = zeek::id::find_type("dns_tsig_additional"); auto r = make_intrusive(dns_tsig_additional); double rtime = tsig->time_s + tsig->time_ms / 1000.0; @@ -1531,7 +1531,7 @@ IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) { - static auto dns_rrsig_rr = zeek::id::lookup_type("dns_rrsig_rr"); + static auto dns_rrsig_rr = zeek::id::find_type("dns_rrsig_rr"); auto r = make_intrusive(dns_rrsig_rr); r->Assign(0, query_name); @@ -1552,7 +1552,7 @@ IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) { - static auto dns_dnskey_rr = zeek::id::lookup_type("dns_dnskey_rr"); + static auto dns_dnskey_rr = zeek::id::find_type("dns_dnskey_rr"); auto r = make_intrusive(dns_dnskey_rr); r->Assign(0, query_name); @@ -1568,7 +1568,7 @@ IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) { - static auto dns_nsec3_rr = zeek::id::lookup_type("dns_nsec3_rr"); + static auto dns_nsec3_rr = zeek::id::find_type("dns_nsec3_rr"); auto r = make_intrusive(dns_nsec3_rr); r->Assign(0, query_name); @@ -1588,7 +1588,7 @@ IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) IntrusivePtr DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) { - static auto dns_ds_rr = zeek::id::lookup_type("dns_ds_rr"); + static auto dns_ds_rr = zeek::id::find_type("dns_ds_rr"); auto r = make_intrusive(dns_ds_rr); r->Assign(0, query_name); diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index 875f371a43..e2cc88b465 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -615,7 +615,7 @@ HTTP_Message::~HTTP_Message() IntrusivePtr HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) { - static auto http_message_stat = zeek::id::lookup_type("http_message_stat"); + static auto http_message_stat = zeek::id::find_type("http_message_stat"); auto stat = make_intrusive(http_message_stat); int field = 0; stat->Assign(field++, make_intrusive(start_time, TYPE_TIME)); @@ -1152,7 +1152,7 @@ void HTTP_Analyzer::GenStats() { if ( http_stats ) { - static auto http_stats_rec = zeek::id::lookup_type("http_stats_rec"); + static auto http_stats_rec = zeek::id::find_type("http_stats_rec"); auto r = make_intrusive(http_stats_rec); r->Assign(0, val_mgr->Count(num_requests)); r->Assign(1, val_mgr->Count(num_replies)); diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 947efce0db..efb6068bd2 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -225,7 +225,7 @@ ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, { if ( ! icmp_conn_val ) { - static auto icmp_conn = zeek::id::lookup_type("icmp_conn"); + static auto icmp_conn = zeek::id::find_type("icmp_conn"); icmp_conn_val = make_intrusive(icmp_conn); icmp_conn_val->Assign(0, make_intrusive(Conn()->OrigAddr())); @@ -351,7 +351,7 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP4Context(int len, const u_char } } - static auto icmp_context = zeek::id::lookup_type("icmp_context"); + static auto icmp_context = zeek::id::find_type("icmp_context"); auto iprec = make_intrusive(icmp_context); auto id_val = make_intrusive(zeek::id::conn_id); @@ -411,7 +411,7 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP6Context(int len, const u_char } } - static auto icmp_context = zeek::id::lookup_type("icmp_context"); + static auto icmp_context = zeek::id::find_type("icmp_context"); auto iprec = make_intrusive(icmp_context); auto id_val = make_intrusive(zeek::id::conn_id); @@ -729,13 +729,13 @@ IntrusivePtr ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha if ( ! icmp6_nd_option_type ) { - icmp6_nd_option_type = zeek::id::lookup_type("icmp6_nd_option")->AsRecordType(); + icmp6_nd_option_type = zeek::id::find_type("icmp6_nd_option")->AsRecordType(); icmp6_nd_prefix_info_type = - zeek::id::lookup_type("icmp6_nd_prefix_info")->AsRecordType(); + zeek::id::find_type("icmp6_nd_prefix_info")->AsRecordType(); } auto vv = make_intrusive( - zeek::id::lookup_type("icmp6_nd_options")); + zeek::id::find_type("icmp6_nd_options")); while ( caplen > 0 ) { diff --git a/src/analyzer/protocol/irc/IRC.cc b/src/analyzer/protocol/irc/IRC.cc index 1bab5d6c5d..ba73af3ec6 100644 --- a/src/analyzer/protocol/irc/IRC.cc +++ b/src/analyzer/protocol/irc/IRC.cc @@ -44,8 +44,8 @@ inline void IRC_Analyzer::SkipLeadingWhitespace(string& str) void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) { - static auto irc_join_list = zeek::id::lookup_type("irc_join_list"); - static auto irc_join_info = zeek::id::lookup_type("irc_join_info"); + static auto irc_join_list = zeek::id::find_type("irc_join_list"); + static auto irc_join_info = zeek::id::find_type("irc_join_info"); tcp::TCP_ApplicationAnalyzer::DeliverStream(length, line, orig); if ( starttls ) diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index 7f77d5db0d..a3c5d55741 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -13,7 +13,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a %code{ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) { - auto vv = make_intrusive(zeek::id::lookup_type("KRB::Type_Value_Vector")); + auto vv = make_intrusive(zeek::id::find_type("KRB::Type_Value_Vector")); if ( ! data->data()->has_padata() ) return vv.release(); diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index e7163596b2..4a53fca79e 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -35,7 +35,7 @@ VectorVal* proc_cipher_list(const Array* list) VectorVal* proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) { - auto addrs = make_intrusive(zeek::id::lookup_type("KRB::Host_Address_Vector")); + auto addrs = make_intrusive(zeek::id::find_type("KRB::Host_Address_Vector")); for ( uint i = 0; i < list->addresses()->size(); ++i ) { @@ -94,7 +94,7 @@ RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list) { - auto tickets = make_intrusive(zeek::id::lookup_type("KRB::Ticket_Vector")); + auto tickets = make_intrusive(zeek::id::find_type("KRB::Ticket_Vector")); for ( uint i = 0; i < list->tickets()->size(); ++i ) { diff --git a/src/analyzer/protocol/login/Login.cc b/src/analyzer/protocol/login/Login.cc index 56fb7d1188..63d9c12541 100644 --- a/src/analyzer/protocol/login/Login.cc +++ b/src/analyzer/protocol/login/Login.cc @@ -45,13 +45,13 @@ Login_Analyzer::Login_Analyzer(const char* name, Connection* conn) if ( ! re_skip_authentication ) { - IntrusivePtr skip_authentication = zeek::id::lookup_val("skip_authentication")->AsTableVal()->ToPureListVal(); - IntrusivePtr direct_login_prompts = zeek::id::lookup_val("direct_login_prompts")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_prompts = zeek::id::lookup_val("login_prompts")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_non_failure_msgs = zeek::id::lookup_val("login_non_failure_msgs")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_failure_msgs = zeek::id::lookup_val("login_failure_msgs")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_success_msgs = zeek::id::lookup_val("login_success_msgs")->AsTableVal()->ToPureListVal(); - IntrusivePtr login_timeouts = zeek::id::lookup_val("login_timeouts")->AsTableVal()->ToPureListVal(); + IntrusivePtr skip_authentication = zeek::id::find_val("skip_authentication")->AsTableVal()->ToPureListVal(); + IntrusivePtr direct_login_prompts = zeek::id::find_val("direct_login_prompts")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_prompts = zeek::id::find_val("login_prompts")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_non_failure_msgs = zeek::id::find_val("login_non_failure_msgs")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_failure_msgs = zeek::id::find_val("login_failure_msgs")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_success_msgs = zeek::id::find_val("login_success_msgs")->AsTableVal()->ToPureListVal(); + IntrusivePtr login_timeouts = zeek::id::find_val("login_timeouts")->AsTableVal()->ToPureListVal(); #ifdef USE_PERFTOOLS_DEBUG HeapLeakChecker::Disabler disabler; diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index e181666488..95d23bbad9 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -1289,7 +1289,7 @@ void MIME_Entity::DebugPrintHeaders() IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) { - static auto mime_header_rec = zeek::id::lookup_type("mime_header_rec"); + static auto mime_header_rec = zeek::id::find_type("mime_header_rec"); auto header_record = make_intrusive(mime_header_rec); header_record->Assign(0, new_string_val(h->get_name())); auto upper_hn = new_string_val(h->get_name()); @@ -1301,7 +1301,7 @@ IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) IntrusivePtr MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) { - static auto mime_header_list = zeek::id::lookup_type("mime_header_list"); + static auto mime_header_list = zeek::id::find_type("mime_header_list"); auto t = make_intrusive(mime_header_list); for ( unsigned int i = 0; i < hlist.size(); ++i ) diff --git a/src/analyzer/protocol/mqtt/commands/publish.pac b/src/analyzer/protocol/mqtt/commands/publish.pac index ea8e60198e..d8211be638 100644 --- a/src/analyzer/protocol/mqtt/commands/publish.pac +++ b/src/analyzer/protocol/mqtt/commands/publish.pac @@ -31,7 +31,7 @@ refine flow MQTT_Flow += { reinterpret_cast(${msg.topic.str}.begin()))); auto len = ${msg.payload}.length(); - static auto max_payload_size = zeek::id::lookup("MQTT::max_payload_size"); + static auto max_payload_size = zeek::id::find("MQTT::max_payload_size"); auto max = max_payload_size->GetVal()->AsCount(); if ( len > static_cast(max) ) diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index f185e4f67e..4c1c0ffb6c 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -138,7 +138,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu event = success ? pm_request_dump : pm_attempt_dump; if ( success ) { - static auto pm_mappings = zeek::id::lookup_type("pm_mappings"); + static auto pm_mappings = zeek::id::find_type("pm_mappings"); TableVal* mappings = new TableVal(pm_mappings); uint32_t nmap = 0; @@ -194,7 +194,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) { - static auto pm_mapping = zeek::id::lookup_type("pm_mapping"); + static auto pm_mapping = zeek::id::find_type("pm_mapping"); RecordVal* mapping = new RecordVal(pm_mapping); mapping->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -215,7 +215,7 @@ Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) { - static auto pm_port_request = zeek::id::lookup_type("pm_port_request"); + static auto pm_port_request = zeek::id::find_type("pm_port_request"); RecordVal* pr = new RecordVal(pm_port_request); pr->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -236,7 +236,7 @@ Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) Val* PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) { - static auto pm_callit_request = zeek::id::lookup_type("pm_callit_request"); + static auto pm_callit_request = zeek::id::find_type("pm_callit_request"); RecordVal* c = new RecordVal(pm_callit_request); c->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); diff --git a/src/analyzer/protocol/sip/sip-analyzer.pac b/src/analyzer/protocol/sip/sip-analyzer.pac index 39b465ab7a..91f4db8723 100644 --- a/src/analyzer/protocol/sip/sip-analyzer.pac +++ b/src/analyzer/protocol/sip/sip-analyzer.pac @@ -67,7 +67,7 @@ refine flow SIP_Flow += { function build_sip_headers_val(): BroVal %{ - static auto mime_header_list = zeek::id::lookup_type("mime_header_list"); + static auto mime_header_list = zeek::id::find_type("mime_header_list"); TableVal* t = new TableVal(mime_header_list); for ( unsigned int i = 0; i < headers.size(); ++i ) @@ -102,7 +102,7 @@ refine flow SIP_Flow += { function build_sip_header_val(name: const_bytestring, value: const_bytestring): BroVal %{ - static auto mime_header_rec = zeek::id::lookup_type("mime_header_rec"); + static auto mime_header_rec = zeek::id::find_type("mime_header_rec"); RecordVal* header_record = new RecordVal(mime_header_rec); IntrusivePtr name_val; diff --git a/src/analyzer/protocol/socks/socks-analyzer.pac b/src/analyzer/protocol/socks/socks-analyzer.pac index b347e42263..fe45150215 100644 --- a/src/analyzer/protocol/socks/socks-analyzer.pac +++ b/src/analyzer/protocol/socks/socks-analyzer.pac @@ -24,7 +24,7 @@ refine connection SOCKS_Conn += { %{ if ( socks_request ) { - static auto socks_address = zeek::id::lookup_type("SOCKS::Address"); + static auto socks_address = zeek::id::find_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); sa->Assign(0, make_intrusive(htonl(${request.addr}))); @@ -49,7 +49,7 @@ refine connection SOCKS_Conn += { %{ if ( socks_reply ) { - static auto socks_address = zeek::id::lookup_type("SOCKS::Address"); + static auto socks_address = zeek::id::find_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); sa->Assign(0, make_intrusive(htonl(${reply.addr}))); @@ -82,7 +82,7 @@ refine connection SOCKS_Conn += { return false; } - static auto socks_address = zeek::id::lookup_type("SOCKS::Address"); + static auto socks_address = zeek::id::find_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); // This is dumb and there must be a better way (checking for presence of a field)... @@ -122,7 +122,7 @@ refine connection SOCKS_Conn += { function socks5_reply(reply: SOCKS5_Reply): bool %{ - static auto socks_address = zeek::id::lookup_type("SOCKS::Address"); + static auto socks_address = zeek::id::find_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); // This is dumb and there must be a better way (checking for presence of a field)... diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index 6a8a97f7c8..ca7801c395 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -155,7 +155,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_signature_algorithm ) return true; - auto slist = make_intrusive(zeek::id::lookup_type("signature_and_hashalgorithm_vec")); + auto slist = make_intrusive(zeek::id::find_type("signature_and_hashalgorithm_vec")); if ( supported_signature_algorithms ) { @@ -492,7 +492,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_pre_shared_key_server_hello ) return true; - auto slist = make_intrusive(zeek::id::lookup_type("psk_identity_vec")); + auto slist = make_intrusive(zeek::id::find_type("psk_identity_vec")); if ( identities && identities->identities() ) { diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index 6233c3a0ad..3c30638692 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -107,7 +107,7 @@ static RecordVal* build_syn_packet_val(bool is_orig, const IP_Hdr* ip, options += opt_len; } - static auto SYN_packet = zeek::id::lookup_type("SYN_packet"); + static auto SYN_packet = zeek::id::find_type("SYN_packet"); RecordVal* v = new RecordVal(SYN_packet); v->Assign(0, val_mgr->Bool(is_orig)); @@ -2078,7 +2078,7 @@ bool TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int capl RecordVal* TCPStats_Endpoint::BuildStats() { - static auto endpoint_stats = zeek::id::lookup_type("endpoint_stats"); + static auto endpoint_stats = zeek::id::find_type("endpoint_stats"); RecordVal* stats = new RecordVal(endpoint_stats); stats->Assign(0, val_mgr->Count(num_pkts)); diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.cc b/src/analyzer/protocol/tcp/TCP_Reassembler.cc index 1b251cfa10..9ff61bf66a 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.cc +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.cc @@ -42,8 +42,8 @@ TCP_Reassembler::TCP_Reassembler(analyzer::Analyzer* arg_dst_analyzer, if ( ::tcp_contents ) { - static auto tcp_content_delivery_ports_orig = zeek::id::lookup_val("tcp_content_delivery_ports_orig"); - static auto tcp_content_delivery_ports_resp = zeek::id::lookup_val("tcp_content_delivery_ports_resp"); + static auto tcp_content_delivery_ports_orig = zeek::id::find_val("tcp_content_delivery_ports_orig"); + static auto tcp_content_delivery_ports_resp = zeek::id::find_val("tcp_content_delivery_ports_resp"); const auto& dst_port_val = val_mgr->Port(ntohs(tcp_analyzer->Conn()->RespPort()), TRANSPORT_TCP); const auto& ports = IsOrig() ? diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index d5e8790fe3..05bcdf2f35 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -104,9 +104,9 @@ IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const if ( ! teredo_hdr_type ) { - teredo_hdr_type = zeek::id::lookup_type("teredo_hdr")->AsRecordType(); - teredo_auth_type = zeek::id::lookup_type("teredo_auth")->AsRecordType(); - teredo_origin_type = zeek::id::lookup_type("teredo_origin")->AsRecordType(); + teredo_hdr_type = zeek::id::find_type("teredo_hdr")->AsRecordType(); + teredo_auth_type = zeek::id::find_type("teredo_auth")->AsRecordType(); + teredo_origin_type = zeek::id::find_type("teredo_origin")->AsRecordType(); } auto teredo_hdr = make_intrusive(teredo_hdr_type); diff --git a/src/analyzer/protocol/udp/UDP.cc b/src/analyzer/protocol/udp/UDP.cc index 518050a1c7..a68cd531ab 100644 --- a/src/analyzer/protocol/udp/UDP.cc +++ b/src/analyzer/protocol/udp/UDP.cc @@ -134,9 +134,9 @@ void UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig, if ( udp_contents ) { - static auto udp_content_ports = zeek::id::lookup_val("udp_content_ports"); - static auto udp_content_delivery_ports_orig = zeek::id::lookup_val("udp_content_delivery_ports_orig"); - static auto udp_content_delivery_ports_resp = zeek::id::lookup_val("udp_content_delivery_ports_resp"); + static auto udp_content_ports = zeek::id::find_val("udp_content_ports"); + static auto udp_content_delivery_ports_orig = zeek::id::find_val("udp_content_delivery_ports_orig"); + static auto udp_content_delivery_ports_resp = zeek::id::find_val("udp_content_delivery_ports_resp"); bool do_udp_contents = false; const auto& sport_val = val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP); const auto& dport_val = val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index b2fa59152d..6cce2f625c 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -1154,7 +1154,7 @@ IntrusivePtr bro_broker::DataVal::castTo(BroType* t) BroType* bro_broker::DataVal::ScriptDataType() { if ( ! script_data_type ) - script_data_type = zeek::id::lookup_type("Broker::Data").get(); + script_data_type = zeek::id::find_type("Broker::Data").get(); return script_data_type; } diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index ac90d2a342..c6939849a7 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -148,8 +148,8 @@ void Manager::InitPostScript() default_log_topic_prefix = get_option("Broker::default_log_topic_prefix")->AsString()->CheckString(); log_topic_func = get_option("Broker::log_topic")->AsFunc(); - log_id_type = zeek::id::lookup_type("Log::ID")->AsEnumType(); - writer_id_type = zeek::id::lookup_type("Log::Writer")->AsEnumType(); + log_id_type = zeek::id::find_type("Log::ID")->AsEnumType(); + writer_id_type = zeek::id::find_type("Log::Writer")->AsEnumType(); opaque_of_data_type = new OpaqueType("Broker::Data"); opaque_of_set_iterator = new OpaqueType("Broker::SetIterator"); @@ -157,7 +157,7 @@ void Manager::InitPostScript() opaque_of_vector_iterator = new OpaqueType("Broker::VectorIterator"); opaque_of_record_iterator = new OpaqueType("Broker::RecordIterator"); opaque_of_store_handle = new OpaqueType("Broker::Store"); - vector_of_data_type = make_intrusive(zeek::id::lookup_type("Broker::Data")); + vector_of_data_type = make_intrusive(zeek::id::find_type("Broker::Data")); // Register as a "dont-count" source first, we may change that later. iosource_mgr->Register(this, true); @@ -1245,13 +1245,13 @@ void Manager::ProcessStatus(broker::status stat) if ( ! event ) return; - auto ei = zeek::id::lookup_type("Broker::EndpointInfo")->AsRecordType(); + auto ei = zeek::id::find_type("Broker::EndpointInfo")->AsRecordType(); auto endpoint_info = make_intrusive(ei); if ( ctx ) { endpoint_info->Assign(0, make_intrusive(to_string(ctx->node))); - auto ni = zeek::id::lookup_type("Broker::NetworkInfo")->AsRecordType(); + auto ni = zeek::id::find_type("Broker::NetworkInfo")->AsRecordType(); auto network_info = make_intrusive(ni); if ( ctx->network ) diff --git a/src/broker/Store.cc b/src/broker/Store.cc index a996923d75..0e6bf5b4f6 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -15,7 +15,7 @@ EnumVal* query_status(bool success) if ( ! store_query_status ) { - store_query_status = zeek::id::lookup_type("Broker::QueryStatus")->AsEnumType(); + store_query_status = zeek::id::find_type("Broker::QueryStatus")->AsEnumType(); success_val = store_query_status->Lookup("Broker", "SUCCESS"); failure_val = store_query_status->Lookup("Broker", "FAILURE"); } diff --git a/src/broker/comm.bif b/src/broker/comm.bif index 77f29830af..796ba003c5 100644 --- a/src/broker/comm.bif +++ b/src/broker/comm.bif @@ -94,14 +94,14 @@ function Broker::__unpeer%(a: string, p: port%): bool function Broker::__peers%(%): PeerInfos %{ bro_broker::Manager::ScriptScopeGuard ssg; - auto rval = make_intrusive(zeek::id::lookup_type("Broker::PeerInfos")); + auto rval = make_intrusive(zeek::id::find_type("Broker::PeerInfos")); auto i = 0; for ( auto& p : broker_mgr->Peers() ) { - auto pi = zeek::id::lookup_type("Broker::PeerInfo")->AsRecordType(); - auto ei = zeek::id::lookup_type("Broker::EndpointInfo")->AsRecordType(); - auto ni = zeek::id::lookup_type("Broker::NetworkInfo")->AsRecordType(); + auto pi = zeek::id::find_type("Broker::PeerInfo")->AsRecordType(); + auto ei = zeek::id::find_type("Broker::EndpointInfo")->AsRecordType(); + auto ni = zeek::id::find_type("Broker::NetworkInfo")->AsRecordType(); auto peer_info = new RecordVal(pi); auto endpoint_info = new RecordVal(ei); auto network_info = new RecordVal(ni); diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index 85934166aa..2975025a4a 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -431,7 +431,7 @@ string Manager::GetFileID(const analyzer::Tag& tag, Connection* c, bool is_orig) bool Manager::IsDisabled(const analyzer::Tag& tag) { if ( ! disabled ) - disabled = zeek::id::lookup_const("Files::disable")->AsTableVal(); + disabled = zeek::id::find_const("Files::disable")->AsTableVal(); auto index = val_mgr->Count(bool(tag)); auto yield = disabled->Lookup(index.get()); @@ -498,8 +498,8 @@ string Manager::DetectMIME(const u_char* data, uint64_t len) const IntrusivePtr file_analysis::GenMIMEMatchesVal(const RuleMatcher::MIME_Matches& m) { - static auto mime_matches = zeek::id::lookup_type("mime_matches"); - static auto mime_match = zeek::id::lookup_type("mime_match"); + static auto mime_matches = zeek::id::find_type("mime_matches"); + static auto mime_match = zeek::id::find_type("mime_match"); auto rval = make_intrusive(mime_matches); for ( RuleMatcher::MIME_Matches::const_iterator it = m.begin(); diff --git a/src/file_analysis/analyzer/entropy/Entropy.cc b/src/file_analysis/analyzer/entropy/Entropy.cc index c2a35b27cb..7eb2dc17ec 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.cc +++ b/src/file_analysis/analyzer/entropy/Entropy.cc @@ -60,7 +60,7 @@ void Entropy::Finalize() montepi = scc = ent = mean = chisq = 0.0; entropy->Get(&ent, &chisq, &mean, &montepi, &scc); - static auto entropy_test_result = zeek::id::lookup_type("entropy_test_result"); + static auto entropy_test_result = zeek::id::find_type("entropy_test_result"); auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index 568837216e..5bd8a8a3c3 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -634,7 +634,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp) //ocsp_resp_record->Assign(7, make_intrusive(len, buf)); //BIO_reset(bio); - certs_vector = new VectorVal(zeek::id::lookup_type("x509_opaque_vector")); + certs_vector = new VectorVal(zeek::id::find_type("x509_opaque_vector")); vl.emplace_back(AdoptRef{}, certs_vector); #if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER) diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index a3c3e00136..9c5fe8a6d9 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -391,7 +391,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) else if ( gen->type == GEN_IPADD ) { if ( ips == nullptr ) - ips = new VectorVal(zeek::id::lookup_type("addr_vec")); + ips = new VectorVal(zeek::id::find_type("addr_vec")); uint32_t* addr = (uint32_t*) gen->d.ip->data; diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index 5cf3fe0e1b..aba1042da7 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -556,7 +556,7 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str } int num_certs = sk_X509_num(chain); - chainVector = new VectorVal(zeek::id::lookup_type("x509_opaque_vector")); + chainVector = new VectorVal(zeek::id::find_type("x509_opaque_vector")); for ( int i = 0; i < num_certs; i++ ) { diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index 616de91fcc..45aaf02072 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -594,8 +594,8 @@ void Packet::ProcessLayer2() IntrusivePtr Packet::ToRawPktHdrVal() const { - static auto raw_pkt_hdr_type = zeek::id::lookup_type("raw_pkt_hdr"); - static auto l2_hdr_type = zeek::id::lookup_type("l2_hdr"); + static auto raw_pkt_hdr_type = zeek::id::find_type("raw_pkt_hdr"); + static auto l2_hdr_type = zeek::id::find_type("l2_hdr"); auto pkt_hdr = make_intrusive(raw_pkt_hdr_type); RecordVal* l2_hdr = new RecordVal(l2_hdr_type); diff --git a/src/legacy-netvar-init.cc b/src/legacy-netvar-init.cc index 926fff6ae9..f5f7ee52f0 100644 --- a/src/legacy-netvar-init.cc +++ b/src/legacy-netvar-init.cc @@ -12,69 +12,69 @@ void zeek_legacy_netvar_init() ::connection_type = zeek::id::connection.get(); ::fa_file_type = zeek::id::fa_file.get(); ::fa_metadata_type = zeek::id::fa_metadata.get(); - ::icmp_conn = zeek::id::lookup_type("icmp_conn")->AsRecordType(); - ::icmp_context = zeek::id::lookup_type("icmp_context")->AsRecordType(); - ::signature_state = zeek::id::lookup_type("signature_state")->AsRecordType(); - ::SYN_packet = zeek::id::lookup_type("SYN_packet")->AsRecordType(); - ::pcap_packet = zeek::id::lookup_type("pcap_packet")->AsRecordType(); - ::raw_pkt_hdr_type = zeek::id::lookup_type("raw_pkt_hdr")->AsRecordType(); - ::l2_hdr_type = zeek::id::lookup_type("l2_hdr")->AsRecordType(); + ::icmp_conn = zeek::id::find_type("icmp_conn")->AsRecordType(); + ::icmp_context = zeek::id::find_type("icmp_context")->AsRecordType(); + ::signature_state = zeek::id::find_type("signature_state")->AsRecordType(); + ::SYN_packet = zeek::id::find_type("SYN_packet")->AsRecordType(); + ::pcap_packet = zeek::id::find_type("pcap_packet")->AsRecordType(); + ::raw_pkt_hdr_type = zeek::id::find_type("raw_pkt_hdr")->AsRecordType(); + ::l2_hdr_type = zeek::id::find_type("l2_hdr")->AsRecordType(); ::transport_proto = zeek::id::transport_proto.get(); ::string_set = zeek::id::string_set.get(); ::string_array = zeek::id::string_array.get(); ::count_set = zeek::id::count_set.get(); ::string_vec = zeek::id::string_vec.get(); ::index_vec = zeek::id::index_vec.get(); - ::mime_matches = zeek::id::lookup_type("mime_matches")->AsVectorType(); - ::mime_match = zeek::id::lookup_type("mime_match")->AsRecordType(); - ::socks_address = zeek::id::lookup_type("SOCKS::Address")->AsRecordType(); - ::mime_header_rec = zeek::id::lookup_type("mime_header_rec")->AsRecordType(); - ::mime_header_list = zeek::id::lookup_type("mime_header_list")->AsTableType(); - ::http_stats_rec = zeek::id::lookup_type("http_stats_rec")->AsRecordType(); - ::http_message_stat = zeek::id::lookup_type("http_message_stat")->AsRecordType(); - ::pm_mapping = zeek::id::lookup_type("pm_mapping")->AsRecordType(); - ::pm_mappings = zeek::id::lookup_type("pm_mappings")->AsTableType(); - ::pm_port_request = zeek::id::lookup_type("pm_port_request")->AsRecordType(); - ::pm_callit_request = zeek::id::lookup_type("pm_callit_request")->AsRecordType(); - ::geo_location = zeek::id::lookup_type("geo_location")->AsRecordType(); - ::entropy_test_result = zeek::id::lookup_type("entropy_test_result")->AsRecordType(); - ::dns_msg = zeek::id::lookup_type("dns_msg")->AsRecordType(); - ::dns_answer = zeek::id::lookup_type("dns_answer")->AsRecordType(); - ::dns_soa = zeek::id::lookup_type("dns_soa")->AsRecordType(); - ::dns_edns_additional = zeek::id::lookup_type("dns_edns_additional")->AsRecordType(); - ::dns_tsig_additional = zeek::id::lookup_type("dns_tsig_additional")->AsRecordType(); - ::dns_rrsig_rr = zeek::id::lookup_type("dns_rrsig_rr")->AsRecordType(); - ::dns_dnskey_rr = zeek::id::lookup_type("dns_dnskey_rr")->AsRecordType(); - ::dns_nsec3_rr = zeek::id::lookup_type("dns_nsec3_rr")->AsRecordType(); - ::dns_ds_rr = zeek::id::lookup_type("dns_ds_rr")->AsRecordType(); - ::rotate_info = zeek::id::lookup_type("rotate_info")->AsRecordType(); - ::irc_join_list = zeek::id::lookup_type("irc_join_list")->AsTableType(); - ::irc_join_info = zeek::id::lookup_type("irc_join_info")->AsRecordType(); - ::script_id = zeek::id::lookup_type("script_id")->AsRecordType(); - ::id_table = zeek::id::lookup_type("id_table")->AsTableType(); - ::record_field = zeek::id::lookup_type("record_field")->AsRecordType(); - ::record_field_table = zeek::id::lookup_type("record_field_table")->AsTableType(); - ::call_argument = zeek::id::lookup_type("call_argument")->AsRecordType(); - ::call_argument_vector = zeek::id::lookup_type("call_argument_vector")->AsVectorType(); + ::mime_matches = zeek::id::find_type("mime_matches")->AsVectorType(); + ::mime_match = zeek::id::find_type("mime_match")->AsRecordType(); + ::socks_address = zeek::id::find_type("SOCKS::Address")->AsRecordType(); + ::mime_header_rec = zeek::id::find_type("mime_header_rec")->AsRecordType(); + ::mime_header_list = zeek::id::find_type("mime_header_list")->AsTableType(); + ::http_stats_rec = zeek::id::find_type("http_stats_rec")->AsRecordType(); + ::http_message_stat = zeek::id::find_type("http_message_stat")->AsRecordType(); + ::pm_mapping = zeek::id::find_type("pm_mapping")->AsRecordType(); + ::pm_mappings = zeek::id::find_type("pm_mappings")->AsTableType(); + ::pm_port_request = zeek::id::find_type("pm_port_request")->AsRecordType(); + ::pm_callit_request = zeek::id::find_type("pm_callit_request")->AsRecordType(); + ::geo_location = zeek::id::find_type("geo_location")->AsRecordType(); + ::entropy_test_result = zeek::id::find_type("entropy_test_result")->AsRecordType(); + ::dns_msg = zeek::id::find_type("dns_msg")->AsRecordType(); + ::dns_answer = zeek::id::find_type("dns_answer")->AsRecordType(); + ::dns_soa = zeek::id::find_type("dns_soa")->AsRecordType(); + ::dns_edns_additional = zeek::id::find_type("dns_edns_additional")->AsRecordType(); + ::dns_tsig_additional = zeek::id::find_type("dns_tsig_additional")->AsRecordType(); + ::dns_rrsig_rr = zeek::id::find_type("dns_rrsig_rr")->AsRecordType(); + ::dns_dnskey_rr = zeek::id::find_type("dns_dnskey_rr")->AsRecordType(); + ::dns_nsec3_rr = zeek::id::find_type("dns_nsec3_rr")->AsRecordType(); + ::dns_ds_rr = zeek::id::find_type("dns_ds_rr")->AsRecordType(); + ::rotate_info = zeek::id::find_type("rotate_info")->AsRecordType(); + ::irc_join_list = zeek::id::find_type("irc_join_list")->AsTableType(); + ::irc_join_info = zeek::id::find_type("irc_join_info")->AsRecordType(); + ::script_id = zeek::id::find_type("script_id")->AsRecordType(); + ::id_table = zeek::id::find_type("id_table")->AsTableType(); + ::record_field = zeek::id::find_type("record_field")->AsRecordType(); + ::record_field_table = zeek::id::find_type("record_field_table")->AsTableType(); + ::call_argument = zeek::id::find_type("call_argument")->AsRecordType(); + ::call_argument_vector = zeek::id::find_type("call_argument_vector")->AsVectorType(); - ::log_rotate_base_time = zeek::id::lookup_val("log_rotate_base_time")->AsStringVal(); - ::pkt_profile_file = zeek::id::lookup_val("pkt_profile_file").get(); - ::likely_server_ports = zeek::id::lookup_val("likely_server_ports")->AsTableVal(); - ::tcp_content_delivery_ports_orig = zeek::id::lookup_val("tcp_content_delivery_ports_orig")->AsTableVal(); - ::tcp_content_delivery_ports_resp = zeek::id::lookup_val("tcp_content_delivery_ports_resp")->AsTableVal(); - ::stp_skip_src = zeek::id::lookup_val("stp_skip_src")->AsTableVal(); - ::dns_skip_auth = zeek::id::lookup_val("dns_skip_auth")->AsTableVal(); - ::dns_skip_addl = zeek::id::lookup_val("dns_skip_addl")->AsTableVal(); - ::udp_content_ports = zeek::id::lookup_val("udp_content_ports")->AsTableVal(); - ::udp_content_delivery_ports_orig = zeek::id::lookup_val("udp_content_delivery_ports_orig")->AsTableVal(); - ::udp_content_delivery_ports_resp = zeek::id::lookup_val("udp_content_delivery_ports_resp")->AsTableVal(); - ::profiling_file = zeek::id::lookup_val("profiling_file").get(); - ::global_hash_seed = zeek::id::lookup_val("global_hash_seed")->AsStringVal(); - ::tcp_reassembler_ports_orig = zeek::id::lookup_val("tcp_reassembler_ports_orig")->AsTableVal(); - ::tcp_reassembler_ports_resp = zeek::id::lookup_val("tcp_reassembler_ports_resp")->AsTableVal(); - ::peer_description = zeek::id::lookup_val("peer_description")->AsStringVal(); - ::trace_output_file = zeek::id::lookup_val("trace_output_file")->AsStringVal(); - ::cmd_line_bpf_filter = zeek::id::lookup_val("cmd_line_bpf_filter")->AsStringVal(); + ::log_rotate_base_time = zeek::id::find_val("log_rotate_base_time")->AsStringVal(); + ::pkt_profile_file = zeek::id::find_val("pkt_profile_file").get(); + ::likely_server_ports = zeek::id::find_val("likely_server_ports")->AsTableVal(); + ::tcp_content_delivery_ports_orig = zeek::id::find_val("tcp_content_delivery_ports_orig")->AsTableVal(); + ::tcp_content_delivery_ports_resp = zeek::id::find_val("tcp_content_delivery_ports_resp")->AsTableVal(); + ::stp_skip_src = zeek::id::find_val("stp_skip_src")->AsTableVal(); + ::dns_skip_auth = zeek::id::find_val("dns_skip_auth")->AsTableVal(); + ::dns_skip_addl = zeek::id::find_val("dns_skip_addl")->AsTableVal(); + ::udp_content_ports = zeek::id::find_val("udp_content_ports")->AsTableVal(); + ::udp_content_delivery_ports_orig = zeek::id::find_val("udp_content_delivery_ports_orig")->AsTableVal(); + ::udp_content_delivery_ports_resp = zeek::id::find_val("udp_content_delivery_ports_resp")->AsTableVal(); + ::profiling_file = zeek::id::find_val("profiling_file").get(); + ::global_hash_seed = zeek::id::find_val("global_hash_seed")->AsStringVal(); + ::tcp_reassembler_ports_orig = zeek::id::find_val("tcp_reassembler_ports_orig")->AsTableVal(); + ::tcp_reassembler_ports_resp = zeek::id::find_val("tcp_reassembler_ports_resp")->AsTableVal(); + ::peer_description = zeek::id::find_val("peer_description")->AsStringVal(); + ::trace_output_file = zeek::id::find_val("trace_output_file")->AsStringVal(); + ::cmd_line_bpf_filter = zeek::id::find_val("cmd_line_bpf_filter")->AsStringVal(); auto anon_id = global_scope()->Lookup("preserve_orig_addr"); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index fae52407df..e351ee2fe3 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -313,7 +313,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) streams[idx]->event = event ? event_registry->Lookup(event->Name()) : nullptr; streams[idx]->columns = columns->Ref()->AsRecordType(); - streams[idx]->enable_remote = zeek::id::lookup_val("Log::enable_remote_logging")->AsBool(); + streams[idx]->enable_remote = zeek::id::find_val("Log::enable_remote_logging")->AsBool(); DBG_LOG(DBG_LOGGING, "Created new logging stream '%s', raising event %s", streams[idx]->name.c_str(), event ? streams[idx]->event->Name() : ""); @@ -1193,7 +1193,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken // Still need to set the WriterInfo's rotation parameters, which we // computed above. - static auto log_rotate_base_time = zeek::id::lookup_val("log_rotate_base_time"); + static auto log_rotate_base_time = zeek::id::find_val("log_rotate_base_time"); static auto base_time = log_rotate_base_time->AsString()->CheckString(); winfo->info->rotation_interval = winfo->interval; @@ -1276,7 +1276,7 @@ bool Manager::WriteFromRemote(EnumVal* id, EnumVal* writer, const string& path, void Manager::SendAllWritersTo(const broker::endpoint_info& ei) { - auto et = zeek::id::lookup_type("Log::Writer")->AsEnumType(); + auto et = zeek::id::find_type("Log::Writer")->AsEnumType(); for ( vector::iterator s = streams.begin(); s != streams.end(); ++s ) { @@ -1453,7 +1453,7 @@ void Manager::InstallRotationTimer(WriterInfo* winfo) if ( ! winfo->open_time ) winfo->open_time = network_time; - static auto log_rotate_base_time = zeek::id::lookup_val("log_rotate_base_time"); + static auto log_rotate_base_time = zeek::id::find_val("log_rotate_base_time"); static auto base_time = log_rotate_base_time->AsString()->CheckString(); double base = parse_rotate_base_time(base_time); diff --git a/src/probabilistic/Hasher.cc b/src/probabilistic/Hasher.cc index 805e927a46..d1765c4fdf 100644 --- a/src/probabilistic/Hasher.cc +++ b/src/probabilistic/Hasher.cc @@ -23,7 +23,7 @@ Hasher::seed_t Hasher::MakeSeed(const void* data, size_t size) assert(sizeof(tmpseed) == 16); - static auto global_hash_seed = zeek::id::lookup_val("global_hash_seed"); + static auto global_hash_seed = zeek::id::find_val("global_hash_seed"); if ( data ) hash_update(ctx, data, size); diff --git a/src/stats.bif b/src/stats.bif index 8451a6ed21..314f0b3de2 100644 --- a/src/stats.bif +++ b/src/stats.bif @@ -470,7 +470,7 @@ function get_reporter_stats%(%): ReporterStats auto r = make_intrusive(ReporterStats); int n = 0; - auto weirds_by_type = make_intrusive(zeek::id::lookup_type("table_string_of_count")); + auto weirds_by_type = make_intrusive(zeek::id::find_type("table_string_of_count")); for ( auto& kv : reporter->GetWeirdsByType() ) { diff --git a/src/strings.bif b/src/strings.bif index 17e57a279b..1390534d25 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -204,7 +204,7 @@ static IntrusivePtr do_split_string(StringVal* str_val, int max_num_sep) { // string_vec is used early in the version script - do not use the NetVar. - auto rval = make_intrusive(zeek::id::lookup_type("string_vec")); + auto rval = make_intrusive(zeek::id::find_type("string_vec")); const u_char* s = str_val->Bytes(); int n = str_val->Len(); const u_char* end_of_s = s + n; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index d995971d32..14cf82fe25 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -361,7 +361,7 @@ static std::vector get_script_signature_files() // Parse rule files defined on the script level. char* script_signature_files = - copy_string(zeek::id::lookup_val("signature_files")->AsString()->CheckString()); + copy_string(zeek::id::find_val("signature_files")->AsString()->CheckString()); char* tmp = script_signature_files; char* s; @@ -722,7 +722,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, if ( ! options.pcap_file && ! options.interface ) { - const auto& interfaces_val = zeek::id::lookup_val("interfaces"); + const auto& interfaces_val = zeek::id::find_val("interfaces"); if ( interfaces_val ) { char* interfaces_str = @@ -780,7 +780,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, if ( profiling_interval > 0 ) { - const auto& profiling_file = zeek::id::lookup_val("profiling_file"); + const auto& profiling_file = zeek::id::find_val("profiling_file"); profiling_logger = new ProfileLogger(profiling_file->AsFile(), profiling_interval); diff --git a/src/zeek.bif b/src/zeek.bif index a61ffd55a4..96c68189a9 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1051,7 +1051,7 @@ function find_entropy%(data: string%): entropy_test_result e.Feed(data->Bytes(), data->Len()); e.Get(&ent, &chisq, &mean, &montepi, &scc); - static auto entropy_test_result = zeek::id::lookup_type("entropy_test_result"); + static auto entropy_test_result = zeek::id::find_type("entropy_test_result"); auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); @@ -1103,7 +1103,7 @@ function entropy_test_finish%(handle: opaque of entropy%): entropy_test_result montepi = scc = ent = mean = chisq = 0.0; static_cast(handle)->Get(&ent, &chisq, &mean, &montepi, &scc); - static auto entropy_test_result = zeek::id::lookup_type("entropy_test_result"); + static auto entropy_test_result = zeek::id::find_type("entropy_test_result"); auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent, TYPE_DOUBLE)); ent_result->Assign(1, make_intrusive(chisq, TYPE_DOUBLE)); @@ -1826,7 +1826,7 @@ function record_type_to_vector%(rt: string%): string_vec %{ auto result = make_intrusive(zeek::id::string_vec); - RecordType* type = zeek::id::lookup_type(rt->CheckString())->AsRecordType(); + RecordType* type = zeek::id::find_type(rt->CheckString())->AsRecordType(); for ( int i = 0; i < type->NumFields(); ++i ) result->Assign(i+1, make_intrusive(type->FieldName(i))); @@ -1891,7 +1891,7 @@ function reading_traces%(%): bool ## .. zeek:see:: reading_live_traffic reading_traces function packet_source%(%): PacketSource %{ - auto ps_type = zeek::id::lookup_type("PacketSource")->AsRecordType(); + auto ps_type = zeek::id::find_type("PacketSource")->AsRecordType(); auto ps = iosource_mgr->GetPktSrc(); auto r = make_intrusive(ps_type); @@ -1941,14 +1941,14 @@ function global_sizes%(%): var_sizes ## .. zeek:see:: global_sizes function global_ids%(%): id_table %{ - static auto id_table = zeek::id::lookup_type("id_table"); + static auto id_table = zeek::id::find_type("id_table"); auto ids = make_intrusive(id_table); const auto& globals = global_scope()->Vars(); for ( const auto& global : globals ) { ID* id = global.second.get(); - static auto script_id = zeek::id::lookup_type("script_id"); + static auto script_id = zeek::id::find_type("script_id"); auto rec = make_intrusive(script_id); rec->Assign(0, make_intrusive(type_name(id->GetType()->Tag()))); rec->Assign(1, val_mgr->Bool(id->IsExport())); @@ -1994,7 +1994,7 @@ function lookup_ID%(id: string%) : any ## Returns: A table that describes the fields of a record. function record_fields%(rec: any%): record_field_table %{ - static auto record_field_table = zeek::id::lookup_type("record_field_table"); + static auto record_field_table = zeek::id::find_type("record_field_table"); if ( rec->GetType()->Tag() == TYPE_STRING ) { @@ -2189,7 +2189,7 @@ function is_v6_subnet%(s: subnet%): bool ## Returns: The vector of addresses contained in the routing header data. function routing0_data_to_addrs%(s: string%): addr_vec %{ - auto rval = make_intrusive(zeek::id::lookup_type("addr_vec")); + auto rval = make_intrusive(zeek::id::find_type("addr_vec")); int len = s->Len(); const u_char* bytes = s->Bytes(); @@ -3385,7 +3385,7 @@ function dump_current_packet%(file_name: string%) : bool ## .. zeek:see:: dump_current_packet dump_packet function get_current_packet%(%) : pcap_packet %{ - static auto pcap_packet = zeek::id::lookup_type("pcap_packet"); + static auto pcap_packet = zeek::id::find_type("pcap_packet"); const Packet* p; auto pkt = make_intrusive(pcap_packet); @@ -3427,7 +3427,7 @@ function get_current_packet_header%(%) : raw_pkt_hdr return p->ToRawPktHdrVal(); } - static auto raw_pkt_hdr_type = zeek::id::lookup_type("raw_pkt_hdr"); + static auto raw_pkt_hdr_type = zeek::id::find_type("raw_pkt_hdr"); auto hdr = make_intrusive(raw_pkt_hdr_type); return hdr; %} @@ -3998,7 +3998,7 @@ function mmdb_open_asn_db%(f: string%) : bool ## .. zeek:see:: lookup_asn function lookup_location%(a: addr%) : geo_location %{ - static auto geo_location = zeek::id::lookup_type("geo_location"); + static auto geo_location = zeek::id::find_type("geo_location"); auto location = make_intrusive(geo_location); #ifdef USE_GEOIP @@ -4630,7 +4630,7 @@ function rotate_file%(f: file%): rotate_info return info; // Record indicating error. - static auto rotate_info = zeek::id::lookup_type("rotate_info"); + static auto rotate_info = zeek::id::find_type("rotate_info"); info = make_intrusive(rotate_info); info->Assign(0, val_mgr->EmptyString()); info->Assign(1, val_mgr->EmptyString()); @@ -4650,7 +4650,7 @@ function rotate_file%(f: file%): rotate_info ## .. zeek:see:: rotate_file calc_next_rotate function rotate_file_by_name%(f: string%): rotate_info %{ - static auto rotate_info = zeek::id::lookup_type("rotate_info"); + static auto rotate_info = zeek::id::find_type("rotate_info"); auto info = make_intrusive(rotate_info); bool is_pkt_dumper = false; @@ -4705,7 +4705,7 @@ function rotate_file_by_name%(f: string%): rotate_info ## .. zeek:see:: rotate_file rotate_file_by_name function calc_next_rotate%(i: interval%) : interval %{ - static auto log_rotate_base_time = zeek::id::lookup_val("log_rotate_base_time"); + static auto log_rotate_base_time = zeek::id::find_val("log_rotate_base_time"); static auto base_time = log_rotate_base_time->AsString()->CheckString(); double base = parse_rotate_base_time(base_time); From 440b0623acc0f72f9c863298526ec1b86ae58cf8 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 14 May 2020 19:31:43 -0700 Subject: [PATCH 061/151] Deprecate RecordVal(RecordType*) ctor Replaced with one that takes IntrusivePtr --- NEWS | 3 + src/CompHash.cc | 2 +- src/DNS_Mgr.cc | 4 +- src/DNS_Mgr.h | 2 +- src/Expr.cc | 6 +- src/Func.cc | 26 ++-- src/IP.cc | 129 +++++++----------- src/SmithWaterman.cc | 18 +-- src/Stmt.cc | 4 +- src/Val.cc | 6 +- src/Val.h | 1 + src/Var.cc | 2 +- .../protocol/bittorrent/BitTorrentTracker.cc | 37 +++-- src/analyzer/protocol/icmp/ICMP.cc | 11 +- src/analyzer/protocol/teredo/Teredo.cc | 13 +- src/broker/Data.cc | 2 +- src/broker/Manager.cc | 4 +- src/broker/comm.bif | 6 +- src/input/Manager.cc | 4 +- src/stats.bif | 26 ++-- src/supervisor/Supervisor.cc | 8 +- src/zeek.bif | 2 +- 22 files changed, 135 insertions(+), 181 deletions(-) diff --git a/NEWS b/NEWS index d81d76a4d8..909d9356b2 100644 --- a/NEWS +++ b/NEWS @@ -184,6 +184,9 @@ Deprecated Functionality equivalent name now in ``zeek::BifCont::``, and changed to ``IntrusivePtr`` if the old name was some ``Val*`` type. +- Constructors for ``Val`` types that take a ``BroType*`` are all generally + deprecated, with alternatives that instead take an ``IntrusivePtr`` argument. + Zeek 3.1.0 ========== diff --git a/src/CompHash.cc b/src/CompHash.cc index b018919b2b..2e0a6590e7 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -927,7 +927,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, ASSERT(int(values.size()) == num_fields); - auto rv = make_intrusive(rt); + auto rv = make_intrusive(IntrusivePtr{NewRef{}, rt}); for ( int i = 0; i < num_fields; ++i ) rv->Assign(i, values[i]); diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 5b8746e249..021df5d191 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -381,8 +381,6 @@ DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode) mode = arg_mode; - dm_rec = nullptr; - cache_name = dir = nullptr; asyncs_pending = 0; @@ -452,7 +450,7 @@ void DNS_Mgr::InitSource() void DNS_Mgr::InitPostScript() { - dm_rec = zeek::id::find_type("dns_mapping")->AsRecordType(); + dm_rec = zeek::id::find_type("dns_mapping"); // Registering will call Init() iosource_mgr->Register(this, true); diff --git a/src/DNS_Mgr.h b/src/DNS_Mgr.h index 3b386fb07d..3ff0d3c307 100644 --- a/src/DNS_Mgr.h +++ b/src/DNS_Mgr.h @@ -149,7 +149,7 @@ protected: bool did_init; - RecordType* dm_rec; + IntrusivePtr dm_rec; typedef std::list CallbackList; diff --git a/src/Expr.cc b/src/Expr.cc index 8e70088fc6..7dfba4020f 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3031,12 +3031,12 @@ IntrusivePtr RecordConstructorExpr::InitVal(const BroType* t, IntrusivePtr< IntrusivePtr RecordConstructorExpr::Fold(Val* v) const { ListVal* lv = v->AsListVal(); - RecordType* rt = type->AsRecordType(); + auto rt = cast_intrusive(type); if ( lv->Length() != rt->NumFields() ) RuntimeErrorWithCallStack("inconsistency evaluating record constructor"); - auto rv = make_intrusive(rt); + auto rv = make_intrusive(std::move(rt)); for ( int i = 0; i < lv->Length(); ++i ) rv->Assign(i, lv->Idx(i)); @@ -3643,7 +3643,7 @@ IntrusivePtr RecordCoerceExpr::InitVal(const BroType* t, IntrusivePtr IntrusivePtr RecordCoerceExpr::Fold(Val* v) const { - auto val = make_intrusive(GetType()->AsRecordType()); + auto val = make_intrusive(GetType()); RecordType* val_type = val->GetType()->AsRecordType(); RecordVal* rv = v->AsRecordVal(); diff --git a/src/Func.cc b/src/Func.cc index aaa0f9d35a..a40b384a17 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -748,19 +748,19 @@ void builtin_error(const char* msg, BroObj* arg) void init_builtin_funcs() { - ProcStats = zeek::id::find_type("ProcStats")->AsRecordType(); - NetStats = zeek::id::find_type("NetStats")->AsRecordType(); - MatcherStats = zeek::id::find_type("MatcherStats")->AsRecordType(); - ConnStats = zeek::id::find_type("ConnStats")->AsRecordType(); - ReassemblerStats = zeek::id::find_type("ReassemblerStats")->AsRecordType(); - DNSStats = zeek::id::find_type("DNSStats")->AsRecordType(); - GapStats = zeek::id::find_type("GapStats")->AsRecordType(); - EventStats = zeek::id::find_type("EventStats")->AsRecordType(); - TimerStats = zeek::id::find_type("TimerStats")->AsRecordType(); - FileAnalysisStats = zeek::id::find_type("FileAnalysisStats")->AsRecordType(); - ThreadStats = zeek::id::find_type("ThreadStats")->AsRecordType(); - BrokerStats = zeek::id::find_type("BrokerStats")->AsRecordType(); - ReporterStats = zeek::id::find_type("ReporterStats")->AsRecordType(); + ProcStats = zeek::id::find_type("ProcStats"); + NetStats = zeek::id::find_type("NetStats"); + MatcherStats = zeek::id::find_type("MatcherStats"); + ConnStats = zeek::id::find_type("ConnStats"); + ReassemblerStats = zeek::id::find_type("ReassemblerStats"); + DNSStats = zeek::id::find_type("DNSStats"); + GapStats = zeek::id::find_type("GapStats"); + EventStats = zeek::id::find_type("EventStats"); + TimerStats = zeek::id::find_type("TimerStats"); + FileAnalysisStats = zeek::id::find_type("FileAnalysisStats"); + ThreadStats = zeek::id::find_type("ThreadStats"); + BrokerStats = zeek::id::find_type("BrokerStats"); + ReporterStats = zeek::id::find_type("ReporterStats"); var_sizes = zeek::id::find_type("var_sizes")->AsTableType(); diff --git a/src/IP.cc b/src/IP.cc index 40e76b68d1..647461d526 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -13,43 +13,15 @@ #include "BroString.h" #include "Reporter.h" -static RecordType* ip4_hdr_type = nullptr; -static RecordType* ip6_hdr_type = nullptr; -static RecordType* ip6_ext_hdr_type = nullptr; -static RecordType* ip6_option_type = nullptr; -static RecordType* ip6_hopopts_type = nullptr; -static RecordType* ip6_dstopts_type = nullptr; -static RecordType* ip6_routing_type = nullptr; -static RecordType* ip6_fragment_type = nullptr; -static RecordType* ip6_ah_type = nullptr; -static RecordType* ip6_esp_type = nullptr; -static RecordType* ip6_mob_type = nullptr; -static RecordType* ip6_mob_msg_type = nullptr; -static RecordType* ip6_mob_brr_type = nullptr; -static RecordType* ip6_mob_hoti_type = nullptr; -static RecordType* ip6_mob_coti_type = nullptr; -static RecordType* ip6_mob_hot_type = nullptr; -static RecordType* ip6_mob_cot_type = nullptr; -static RecordType* ip6_mob_bu_type = nullptr; -static RecordType* ip6_mob_back_type = nullptr; -static RecordType* ip6_mob_be_type = nullptr; - -static inline RecordType* hdrType(RecordType*& type, const char* name) - { - if ( ! type ) - type = zeek::id::find_type(name)->AsRecordType(); - - return type; - } - static IntrusivePtr BuildOptionsVal(const u_char* data, int len) { auto vv = make_intrusive(zeek::id::find_type("ip6_options")); while ( len > 0 ) { + static auto ip6_option_type = zeek::id::find_type("ip6_option"); const struct ip6_opt* opt = (const struct ip6_opt*) data; - auto rv = make_intrusive(hdrType(ip6_option_type, "ip6_option")); + auto rv = make_intrusive(ip6_option_type); rv->Assign(0, val_mgr->Count(opt->ip6o_type)); if ( opt->ip6o_type == 0 ) @@ -84,7 +56,8 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const switch ( type ) { case IPPROTO_IPV6: { - rv = make_intrusive(hdrType(ip6_hdr_type, "ip6_hdr")); + static auto ip6_hdr_type = zeek::id::find_type("ip6_hdr"); + rv = make_intrusive(ip6_hdr_type); const struct ip6_hdr* ip6 = (const struct ip6_hdr*)data; rv->Assign(0, val_mgr->Count((ntohl(ip6->ip6_flow) & 0x0ff00000)>>20)); rv->Assign(1, val_mgr->Count(ntohl(ip6->ip6_flow) & 0x000fffff)); @@ -102,7 +75,8 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_HOPOPTS: { - rv = make_intrusive(hdrType(ip6_hopopts_type, "ip6_hopopts")); + static auto ip6_hopopts_type = zeek::id::find_type("ip6_hopopts"); + rv = make_intrusive(ip6_hopopts_type); const struct ip6_hbh* hbh = (const struct ip6_hbh*)data; rv->Assign(0, val_mgr->Count(hbh->ip6h_nxt)); rv->Assign(1, val_mgr->Count(hbh->ip6h_len)); @@ -114,7 +88,8 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_DSTOPTS: { - rv = make_intrusive(hdrType(ip6_dstopts_type, "ip6_dstopts")); + static auto ip6_dstopts_type = zeek::id::find_type("ip6_dstopts"); + rv = make_intrusive(ip6_dstopts_type); const struct ip6_dest* dst = (const struct ip6_dest*)data; rv->Assign(0, val_mgr->Count(dst->ip6d_nxt)); rv->Assign(1, val_mgr->Count(dst->ip6d_len)); @@ -125,7 +100,8 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_ROUTING: { - rv = make_intrusive(hdrType(ip6_routing_type, "ip6_routing")); + static auto ip6_routing_type = zeek::id::find_type("ip6_routing"); + rv = make_intrusive(ip6_routing_type); const struct ip6_rthdr* rt = (const struct ip6_rthdr*)data; rv->Assign(0, val_mgr->Count(rt->ip6r_nxt)); rv->Assign(1, val_mgr->Count(rt->ip6r_len)); @@ -138,7 +114,8 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_FRAGMENT: { - rv = make_intrusive(hdrType(ip6_fragment_type, "ip6_fragment")); + static auto ip6_fragment_type = zeek::id::find_type("ip6_fragment"); + rv = make_intrusive(ip6_fragment_type); const struct ip6_frag* frag = (const struct ip6_frag*)data; rv->Assign(0, val_mgr->Count(frag->ip6f_nxt)); rv->Assign(1, val_mgr->Count(frag->ip6f_reserved)); @@ -151,7 +128,8 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_AH: { - rv = make_intrusive(hdrType(ip6_ah_type, "ip6_ah")); + static auto ip6_ah_type = zeek::id::find_type("ip6_ah"); + rv = make_intrusive(ip6_ah_type); rv->Assign(0, val_mgr->Count(((ip6_ext*)data)->ip6e_nxt)); rv->Assign(1, val_mgr->Count(((ip6_ext*)data)->ip6e_len)); rv->Assign(2, val_mgr->Count(ntohs(((uint16_t*)data)[1]))); @@ -170,7 +148,8 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_ESP: { - rv = make_intrusive(hdrType(ip6_esp_type, "ip6_esp")); + static auto ip6_esp_type = zeek::id::find_type("ip6_esp"); + rv = make_intrusive(ip6_esp_type); const uint32_t* esp = (const uint32_t*)data; rv->Assign(0, val_mgr->Count(ntohl(esp[0]))); rv->Assign(1, val_mgr->Count(ntohl(esp[1]))); @@ -180,7 +159,8 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const #ifdef ENABLE_MOBILE_IPV6 case IPPROTO_MOBILITY: { - rv = make_intrusive(hdrType(ip6_mob_type, "ip6_mobility_hdr")); + static auto ip6_mob_type = zeek::id::find_type("ip6_mobility_hdr"); + rv = make_intrusive(ip6_mob_type); const struct ip6_mobility* mob = (const struct ip6_mobility*) data; rv->Assign(0, val_mgr->Count(mob->ip6mob_payload)); rv->Assign(1, val_mgr->Count(mob->ip6mob_len)); @@ -188,16 +168,26 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const rv->Assign(3, val_mgr->Count(mob->ip6mob_rsv)); rv->Assign(4, val_mgr->Count(ntohs(mob->ip6mob_chksum))); - auto msg = make_intrusive(hdrType(ip6_mob_msg_type, "ip6_mobility_msg")); + static auto ip6_mob_msg_type = zeek::id::find_type("ip6_mobility_msg"); + auto msg = make_intrusive(ip6_mob_msg_type); msg->Assign(0, val_mgr->Count(mob->ip6mob_type)); uint16_t off = sizeof(ip6_mobility); const u_char* msg_data = data + off; + static auto ip6_mob_brr_type = zeek::id::find_type("ip6_mobility_brr"); + static auto ip6_mob_hoti_type = zeek::id::find_type("ip6_mobility_hoti"); + static auto ip6_mob_coti_type = zeek::id::find_type("ip6_mobility_coti"); + static auto ip6_mob_hot_type = zeek::id::find_type("ip6_mobility_hot"); + static auto ip6_mob_cot_type = zeek::id::find_type("ip6_mobility_cot"); + static auto ip6_mob_bu_type = zeek::id::find_type("ip6_mobility_bu"); + static auto ip6_mob_back_type = zeek::id::find_type("ip6_mobility_back"); + static auto ip6_mob_be_type = zeek::id::find_type("ip6_mobility_be"); + switch ( mob->ip6mob_type ) { case 0: { - auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_brr")); + auto m = make_intrusive(ip6_mob_brr_type); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); off += sizeof(uint16_t); m->Assign(1, BuildOptionsVal(data + off, Length() - off)); @@ -207,7 +197,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case 1: { - auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_hoti")); + auto m = make_intrusive(ip6_mobility_hoti_type); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); off += sizeof(uint16_t) + sizeof(uint64_t); @@ -218,7 +208,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case 2: { - auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_coti")); + auto m = make_intrusive(ip6_mobility_coti_type); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); off += sizeof(uint16_t) + sizeof(uint64_t); @@ -229,7 +219,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case 3: { - auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_hot")); + auto m = make_intrusive(ip6_mobility_hot_type); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(2, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t)))))); @@ -241,7 +231,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case 4: { - auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_cot")); + auto m = make_intrusive(ip6_mobility_cot_type); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(2, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t)))))); @@ -253,7 +243,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case 5: { - auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_bu")); + auto m = make_intrusive(ip6_mobility_bu_type); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(1, val_mgr->Bool(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x8000)); m->Assign(2, val_mgr->Bool(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x4000)); @@ -268,7 +258,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case 6: { - auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_back")); + auto m = make_intrusive(ip6_mobility_back_type); m->Assign(0, val_mgr->Count(*((uint8_t*)msg_data))); m->Assign(1, val_mgr->Bool(*((uint8_t*)(msg_data + sizeof(uint8_t))) & 0x80)); m->Assign(2, val_mgr->Count(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))))); @@ -281,7 +271,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case 7: { - auto m = make_intrusive(hdrType(ip6_mob_brr_type, "ip6_mobility_be")); + auto m = make_intrusive(ip6_mobility_be_type); m->Assign(0, val_mgr->Count(*((uint8_t*)msg_data))); const in6_addr* hoa = (const in6_addr*)(msg_data + sizeof(uint16_t)); m->Assign(1, make_intrusive(IPAddr(*hoa))); @@ -339,7 +329,8 @@ IntrusivePtr IP_Hdr::ToIPHdrVal() const if ( ip4 ) { - rval = make_intrusive(hdrType(ip4_hdr_type, "ip4_hdr")); + static auto ip4_hdr_type = zeek::id::find_type("ip4_hdr"); + rval = make_intrusive(ip4_hdr_type); rval->Assign(0, val_mgr->Count(ip4->ip_hl * 4)); rval->Assign(1, val_mgr->Count(ip4->ip_tos)); rval->Assign(2, val_mgr->Count(ntohs(ip4->ip_len))); @@ -364,11 +355,7 @@ RecordVal* IP_Hdr::BuildIPHdrVal() const IntrusivePtr IP_Hdr::ToPktHdrVal() const { - static RecordType* pkt_hdr_type = nullptr; - - if ( ! pkt_hdr_type ) - pkt_hdr_type = zeek::id::find_type("pkt_hdr")->AsRecordType(); - + static auto pkt_hdr_type = zeek::id::find_type("pkt_hdr"); return ToPktHdrVal(make_intrusive(pkt_hdr_type), 0); } @@ -379,16 +366,9 @@ RecordVal* IP_Hdr::BuildPktHdrVal() const IntrusivePtr IP_Hdr::ToPktHdrVal(IntrusivePtr pkt_hdr, int sindex) const { - static RecordType* tcp_hdr_type = nullptr; - static RecordType* udp_hdr_type = nullptr; - static RecordType* icmp_hdr_type = nullptr; - - if ( ! tcp_hdr_type ) - { - tcp_hdr_type = zeek::id::find_type("tcp_hdr")->AsRecordType(); - udp_hdr_type = zeek::id::find_type("udp_hdr")->AsRecordType(); - icmp_hdr_type = zeek::id::find_type("icmp_hdr")->AsRecordType(); - } + static auto tcp_hdr_type = zeek::id::find_type("tcp_hdr"); + static auto udp_hdr_type = zeek::id::find_type("udp_hdr"); + static auto icmp_hdr_type = zeek::id::find_type("icmp_hdr"); if ( ip4 ) pkt_hdr->Assign(sindex + 0, ToIPHdrVal()); @@ -695,20 +675,15 @@ void IPv6_Hdr_Chain::ProcessDstOpts(const struct ip6_dest* d, uint16_t len) IntrusivePtr IPv6_Hdr_Chain::ToVal() const { - if ( ! ip6_ext_hdr_type ) - { - ip6_ext_hdr_type = zeek::id::find_type("ip6_ext_hdr")->AsRecordType(); - ip6_hopopts_type = zeek::id::find_type("ip6_hopopts")->AsRecordType(); - ip6_dstopts_type = zeek::id::find_type("ip6_dstopts")->AsRecordType(); - ip6_routing_type = zeek::id::find_type("ip6_routing")->AsRecordType(); - ip6_fragment_type = zeek::id::find_type("ip6_fragment")->AsRecordType(); - ip6_ah_type = zeek::id::find_type("ip6_ah")->AsRecordType(); - ip6_esp_type = zeek::id::find_type("ip6_esp")->AsRecordType(); - ip6_mob_type = zeek::id::find_type("ip6_mobility_hdr")->AsRecordType(); - } - - auto rval = make_intrusive( - zeek::id::find_type("ip6_ext_hdr_chain")); + static auto ip6_ext_hdr_type = zeek::id::find_type("ip6_ext_hdr"); + static auto ip6_hopopts_type = zeek::id::find_type("ip6_hopopts"); + static auto ip6_dstopts_type = zeek::id::find_type("ip6_dstopts"); + static auto ip6_routing_type = zeek::id::find_type("ip6_routing"); + static auto ip6_fragment_type = zeek::id::find_type("ip6_fragment"); + static auto ip6_ah_type = zeek::id::find_type("ip6_ah"); + static auto ip6_esp_type = zeek::id::find_type("ip6_esp"); + static auto ip6_ext_hdr_chain_type = zeek::id::find_type("ip6_ext_hdr_chain"); + auto rval = make_intrusive(ip6_ext_hdr_chain_type); for ( size_t i = 1; i < chain.size(); ++i ) { diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index 6409fa2d1b..ac32f6f28d 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -58,20 +58,12 @@ bool BroSubstring::DoesCover(const BroSubstring* bst) const VectorVal* BroSubstring::VecToPolicy(Vec* vec) { - RecordType* sw_substring_type = - zeek::id::find_type("sw_substring")->AsRecordType(); - if ( ! sw_substring_type ) - return nullptr; + static auto sw_substring_type = zeek::id::find_type("sw_substring"); + static auto sw_align_type = zeek::id::find_type("sw_align"); + static auto sw_align_vec_type = zeek::id::find_type("sw_align_vec"); + static auto sw_substring_vec_type = zeek::id::find_type("sw_substring_vec"); - RecordType* sw_align_type = - zeek::id::find_type("sw_align")->AsRecordType(); - if ( ! sw_align_type ) - return nullptr; - - auto sw_align_vec_type = zeek::id::find_type("sw_align_vec"); - - auto result = - make_intrusive(zeek::id::find_type("sw_substring_vec")); + auto result = make_intrusive(sw_substring_vec_type); if ( vec ) { diff --git a/src/Stmt.cc b/src/Stmt.cc index 015378633a..18c66b00c8 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -201,7 +201,7 @@ static IntrusivePtr lookup_enum_val(const char* module_name, const char static void print_log(const std::vector>& vals) { auto plval = lookup_enum_val("Log", "PRINTLOG"); - auto record = make_intrusive(zeek::id::find_type("Log::PrintLogInfo")->AsRecordType()); + auto record = make_intrusive(zeek::id::find_type("Log::PrintLogInfo")); auto vec = make_intrusive(zeek::id::string_vec); for ( const auto& val : vals ) @@ -1662,7 +1662,7 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const switch ( t->Tag() ) { case TYPE_RECORD: - v = new RecordVal(t->AsRecordType()); + v = new RecordVal(cast_intrusive(t)); break; case TYPE_VECTOR: v = new VectorVal(cast_intrusive(t)); diff --git a/src/Val.cc b/src/Val.cc index 94ee1ebca7..4e39ac676e 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2691,7 +2691,7 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo TypeTag tag = type->Tag(); if ( tag == TYPE_RECORD ) - def = make_intrusive(type->AsRecordType()); + def = make_intrusive(cast_intrusive(type)); else if ( tag == TYPE_TABLE ) def = make_intrusive(IntrusivePtr{NewRef{}, type->AsTableType()}, @@ -2788,7 +2788,7 @@ IntrusivePtr RecordVal::CoerceTo(const RecordType* t, Val* aggr, bool return nullptr; if ( ! aggr ) - aggr = new RecordVal(const_cast(t->AsRecordType())); + aggr = new RecordVal({NewRef{}, const_cast(t)}); RecordVal* ar = aggr->AsRecordVal(); RecordType* ar_t = aggr->GetType()->AsRecordType(); @@ -2932,7 +2932,7 @@ IntrusivePtr RecordVal::DoClone(CloneState* state) // record. As we cannot guarantee that it will ber zeroed out at the // approproate time (as it seems to be guaranteed for the original record) // we don't touch it. - auto rv = make_intrusive(GetType()->AsRecordType(), false); + auto rv = make_intrusive(GetType(), false); rv->origin = nullptr; state->NewClone(this, rv); diff --git a/src/Val.h b/src/Val.h index 92c2194277..f093ada039 100644 --- a/src/Val.h +++ b/src/Val.h @@ -930,6 +930,7 @@ protected: class RecordVal final : public Val, public notifier::Modifiable { public: + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit RecordVal(RecordType* t, bool init_fields = true); explicit RecordVal(IntrusivePtr t, bool init_fields = true); diff --git a/src/Var.cc b/src/Var.cc index 73f0944c5e..f89d1b1473 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -241,7 +241,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, if ( t->Tag() == TYPE_RECORD ) { - aggr = make_intrusive(t->AsRecordType()); + aggr = make_intrusive(cast_intrusive(t)); if ( init && t ) // Have an initialization and type is not deduced. diff --git a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc index 5f35156fef..2257f22043 100644 --- a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc +++ b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc @@ -15,11 +15,11 @@ using namespace analyzer::bittorrent; -static TableType* bt_tracker_headers = nullptr; -static RecordType* bittorrent_peer; -static TableType* bittorrent_peer_set; -static RecordType* bittorrent_benc_value; -static TableType* bittorrent_benc_dir; +static IntrusivePtr bt_tracker_headers; +static IntrusivePtr bittorrent_peer; +static IntrusivePtr bittorrent_peer_set; +static IntrusivePtr bittorrent_benc_value; +static IntrusivePtr bittorrent_benc_dir; BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) : tcp::TCP_ApplicationAnalyzer("BITTORRENTTRACKER", c) @@ -27,15 +27,15 @@ BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) if ( ! bt_tracker_headers ) { bt_tracker_headers = - zeek::id::find_type("bt_tracker_headers")->AsTableType(); + zeek::id::find_type("bt_tracker_headers"); bittorrent_peer = - zeek::id::find_type("bittorrent_peer")->AsRecordType(); + zeek::id::find_type("bittorrent_peer"); bittorrent_peer_set = - zeek::id::find_type("bittorrent_peer_set")->AsTableType(); + zeek::id::find_type("bittorrent_peer_set"); bittorrent_benc_value = - zeek::id::find_type("bittorrent_benc_value")->AsRecordType(); + zeek::id::find_type("bittorrent_benc_value"); bittorrent_benc_dir = - zeek::id::find_type("bittorrent_benc_dir")->AsTableType(); + zeek::id::find_type("bittorrent_benc_dir"); } keep_alive = false; @@ -45,7 +45,7 @@ BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) req_buf_pos = req_buf; req_buf_len = 0; req_val_uri = nullptr; - req_val_headers = new TableVal({NewRef{}, bt_tracker_headers}); + req_val_headers = new TableVal(bt_tracker_headers); res_state = BTT_RES_STATUS; res_allow_blank_line = false; @@ -53,9 +53,9 @@ BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) res_buf_pos = res_buf; res_buf_len = 0; res_status = 0; - res_val_headers = new TableVal({NewRef{}, bt_tracker_headers}); - res_val_peers = new TableVal({NewRef{}, bittorrent_peer_set}); - res_val_benc = new TableVal({NewRef{}, bittorrent_benc_dir}); + res_val_headers = new TableVal(bt_tracker_headers); + res_val_peers = new TableVal(bittorrent_peer_set); + res_val_benc = new TableVal(bittorrent_benc_dir); InitBencParser(); @@ -136,8 +136,7 @@ void BitTorrentTracker_Analyzer::ClientRequest(int len, const u_char* data) req_buf_len -= (req_buf_pos - req_buf); memmove(req_buf, req_buf_pos, req_buf_len); req_buf_pos = req_buf; - req_val_headers = - new TableVal({NewRef{}, bt_tracker_headers}); + req_val_headers = new TableVal(bt_tracker_headers); } } } @@ -199,9 +198,9 @@ void BitTorrentTracker_Analyzer::ServerReply(int len, const u_char* data) res_buf_pos = res_buf; res_status = 0; - res_val_headers = new TableVal({NewRef{}, bt_tracker_headers}); - res_val_peers = new TableVal({NewRef{}, bittorrent_peer_set}); - res_val_benc = new TableVal({NewRef{}, bittorrent_benc_dir}); + res_val_headers = new TableVal(bt_tracker_headers); + res_val_peers = new TableVal(bittorrent_peer_set); + res_val_benc = new TableVal(bittorrent_benc_dir); InitBencParser(); } diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index efb6068bd2..0a0eb3f1b8 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -724,15 +724,8 @@ void ICMP_Analyzer::Context6(double t, const struct icmp* icmpp, IntrusivePtr ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) { - static RecordType* icmp6_nd_option_type = nullptr; - static RecordType* icmp6_nd_prefix_info_type = nullptr; - - if ( ! icmp6_nd_option_type ) - { - icmp6_nd_option_type = zeek::id::find_type("icmp6_nd_option")->AsRecordType(); - icmp6_nd_prefix_info_type = - zeek::id::find_type("icmp6_nd_prefix_info")->AsRecordType(); - } + static auto icmp6_nd_option_type = zeek::id::find_type("icmp6_nd_option"); + static auto icmp6_nd_prefix_info_type = zeek::id::find_type("icmp6_nd_prefix_info"); auto vv = make_intrusive( zeek::id::find_type("icmp6_nd_options")); diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index 05bcdf2f35..33df0e10e1 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -98,16 +98,9 @@ bool TeredoEncapsulation::DoParse(const u_char* data, int& len, IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const { - static RecordType* teredo_hdr_type = nullptr; - static RecordType* teredo_auth_type = nullptr; - static RecordType* teredo_origin_type = nullptr; - - if ( ! teredo_hdr_type ) - { - teredo_hdr_type = zeek::id::find_type("teredo_hdr")->AsRecordType(); - teredo_auth_type = zeek::id::find_type("teredo_auth")->AsRecordType(); - teredo_origin_type = zeek::id::find_type("teredo_origin")->AsRecordType(); - } + static auto teredo_hdr_type = zeek::id::find_type("teredo_hdr"); + static auto teredo_auth_type = zeek::id::find_type("teredo_auth"); + static auto teredo_origin_type = zeek::id::find_type("teredo_origin"); auto teredo_hdr = make_intrusive(teredo_hdr_type); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 6cce2f625c..de449b820f 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -387,7 +387,7 @@ struct val_converter { else if ( type->Tag() == TYPE_RECORD ) { auto rt = type->AsRecordType(); - auto rval = make_intrusive(rt); + auto rval = make_intrusive(IntrusivePtr{NewRef{}, rt}); auto idx = 0u; for ( auto i = 0u; i < static_cast(rt->NumFields()); ++i ) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index c6939849a7..b60ceed282 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -1245,13 +1245,13 @@ void Manager::ProcessStatus(broker::status stat) if ( ! event ) return; - auto ei = zeek::id::find_type("Broker::EndpointInfo")->AsRecordType(); + static auto ei = zeek::id::find_type("Broker::EndpointInfo"); auto endpoint_info = make_intrusive(ei); if ( ctx ) { endpoint_info->Assign(0, make_intrusive(to_string(ctx->node))); - auto ni = zeek::id::find_type("Broker::NetworkInfo")->AsRecordType(); + static auto ni = zeek::id::find_type("Broker::NetworkInfo"); auto network_info = make_intrusive(ni); if ( ctx->network ) diff --git a/src/broker/comm.bif b/src/broker/comm.bif index 796ba003c5..a8d3ca5389 100644 --- a/src/broker/comm.bif +++ b/src/broker/comm.bif @@ -99,9 +99,9 @@ function Broker::__peers%(%): PeerInfos for ( auto& p : broker_mgr->Peers() ) { - auto pi = zeek::id::find_type("Broker::PeerInfo")->AsRecordType(); - auto ei = zeek::id::find_type("Broker::EndpointInfo")->AsRecordType(); - auto ni = zeek::id::find_type("Broker::NetworkInfo")->AsRecordType(); + const auto& pi = zeek::id::find_type("Broker::PeerInfo"); + const auto& ei = zeek::id::find_type("Broker::EndpointInfo"); + const auto& ni = zeek::id::find_type("Broker::NetworkInfo"); auto peer_info = new RecordVal(pi); auto endpoint_info = new RecordVal(ei); auto network_info = new RecordVal(ni); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index e9f80cb6ad..9c0060801d 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1906,7 +1906,7 @@ RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType *request_type, { assert(position != nullptr); // we need the pointer to point to data; - RecordVal* rec = new RecordVal(request_type->AsRecordType()); + RecordVal* rec = new RecordVal({NewRef{}, request_type}); assert(list != nullptr); int maxpos = list->Length(); @@ -1936,7 +1936,7 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v { assert(position != nullptr); // we need the pointer to point to data. - RecordVal* rec = new RecordVal(request_type->AsRecordType()); + RecordVal* rec = new RecordVal({NewRef{}, request_type}); for ( int i = 0; i < request_type->NumFields(); i++ ) { Val* fieldVal = nullptr; diff --git a/src/stats.bif b/src/stats.bif index 314f0b3de2..22008bc3ed 100644 --- a/src/stats.bif +++ b/src/stats.bif @@ -4,19 +4,19 @@ #include "threading/Manager.h" #include "broker/Manager.h" -RecordType* ProcStats; -RecordType* NetStats; -RecordType* MatcherStats; -RecordType* ReassemblerStats; -RecordType* DNSStats; -RecordType* ConnStats; -RecordType* GapStats; -RecordType* EventStats; -RecordType* ThreadStats; -RecordType* TimerStats; -RecordType* FileAnalysisStats; -RecordType* BrokerStats; -RecordType* ReporterStats; +IntrusivePtr ProcStats; +IntrusivePtr NetStats; +IntrusivePtr MatcherStats; +IntrusivePtr ReassemblerStats; +IntrusivePtr DNSStats; +IntrusivePtr ConnStats; +IntrusivePtr GapStats; +IntrusivePtr EventStats; +IntrusivePtr ThreadStats; +IntrusivePtr TimerStats; +IntrusivePtr FileAnalysisStats; +IntrusivePtr BrokerStats; +IntrusivePtr ReporterStats; %%} ## Returns packet capture statistics. Statistics include the number of diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 2856f188b2..6dd4c65506 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1172,7 +1172,7 @@ IntrusivePtr Supervisor::Node::ToRecord() const static IntrusivePtr supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role) { - static auto node_type = global_scope()->Find("Cluster::NodeType")->GetType()->AsEnumType(); + static auto node_type = zeek::id::find_type("Cluster::NodeType"); switch ( role ) { case BifEnum::Supervisor::LOGGER: @@ -1193,9 +1193,9 @@ bool Supervisor::SupervisedNode::InitCluster() const if ( config.cluster.empty() ) return false; - const auto& cluster_node_type = global_scope()->Find("Cluster::Node")->GetType()->AsRecordType(); - const auto& cluster_nodes_id = global_scope()->Find("Cluster::nodes"); - const auto& cluster_manager_is_logger_id = global_scope()->Find("Cluster::manager_is_logger"); + const auto& cluster_node_type = zeek::id::find_type("Cluster::Node"); + const auto& cluster_nodes_id = zeek::id::find("Cluster::nodes"); + const auto& cluster_manager_is_logger_id = zeek::id::find("Cluster::manager_is_logger"); auto cluster_nodes = cluster_nodes_id->GetVal()->AsTableVal(); auto has_logger = false; std::optional manager_name; diff --git a/src/zeek.bif b/src/zeek.bif index 96c68189a9..1eaf579c79 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1891,7 +1891,7 @@ function reading_traces%(%): bool ## .. zeek:see:: reading_live_traffic reading_traces function packet_source%(%): PacketSource %{ - auto ps_type = zeek::id::find_type("PacketSource")->AsRecordType(); + static auto ps_type = zeek::id::find_type("PacketSource"); auto ps = iosource_mgr->GetPktSrc(); auto r = make_intrusive(ps_type); From 902f93671cf3f114ee70b3a3afab2e3937db8bdc Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 14 May 2020 20:44:38 -0700 Subject: [PATCH 062/151] Change protected EnumVal ctor to use IntrusivePtr --- src/Type.cc | 4 ++-- src/Val.h | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Type.cc b/src/Type.cc index 17c2dad221..cb4f604cda 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1182,7 +1182,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, AddNameInternal(module_name, name, val, is_export); if ( vals.find(val) == vals.end() ) - vals[val] = make_intrusive(this, val); + vals[val] = make_intrusive(IntrusivePtr{NewRef{}, this}, val); set types = BroType::GetAliases(GetName()); set::const_iterator it; @@ -1238,7 +1238,7 @@ IntrusivePtr EnumType::GetVal(bro_int_t i) if ( it == vals.end() ) { - rval = make_intrusive(this, i); + rval = make_intrusive(IntrusivePtr{NewRef{}, this}, i); vals[i] = rval; } else diff --git a/src/Val.h b/src/Val.h index f093ada039..d94d94624c 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1011,9 +1011,8 @@ protected: template friend IntrusivePtr make_intrusive(Ts&&... args); - EnumVal(EnumType* t, int i) : Val(bro_int_t(i), {NewRef{}, t}) - { - } + EnumVal(IntrusivePtr t, int i) : Val(bro_int_t(i), std::move(t)) + {} void ValDescribe(ODesc* d) const override; IntrusivePtr DoClone(CloneState* state) override; From 62282c02260d4cfb4cc11d0593fe633290436149 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 14 May 2020 22:15:12 -0700 Subject: [PATCH 063/151] Switch EnumType::GetVal() to return const-ref --- src/Stmt.cc | 5 +- src/Type.cc | 11 ++- src/Type.h | 2 +- src/analyzer/protocol/rpc/MOUNT.cc | 20 +++--- src/analyzer/protocol/rpc/NFS.cc | 12 ++-- src/broker/Data.cc | 3 +- src/broker/Store.cc | 3 +- src/input/Manager.cc | 108 +++++++++++++---------------- src/logging/Manager.cc | 2 +- 9 files changed, 76 insertions(+), 90 deletions(-) diff --git a/src/Stmt.cc b/src/Stmt.cc index 18c66b00c8..d0b9bac64e 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -200,8 +200,9 @@ static IntrusivePtr lookup_enum_val(const char* module_name, const char static void print_log(const std::vector>& vals) { - auto plval = lookup_enum_val("Log", "PRINTLOG"); - auto record = make_intrusive(zeek::id::find_type("Log::PrintLogInfo")); + static auto plval = lookup_enum_val("Log", "PRINTLOG"); + static auto lpli = zeek::id::find_type("Log::PrintLogInfo"); + auto record = make_intrusive(lpli); auto vec = make_intrusive(zeek::id::string_vec); for ( const auto& val : vals ) diff --git a/src/Type.cc b/src/Type.cc index cb4f604cda..d5d17f7a3f 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1231,20 +1231,17 @@ EnumType::enum_name_list EnumType::Names() const return n; } -IntrusivePtr EnumType::GetVal(bro_int_t i) +const IntrusivePtr& EnumType::GetVal(bro_int_t i) { auto it = vals.find(i); - IntrusivePtr rval; if ( it == vals.end() ) { - rval = make_intrusive(IntrusivePtr{NewRef{}, this}, i); - vals[i] = rval; + auto ev = make_intrusive(IntrusivePtr{NewRef{}, this}, i); + return vals.emplace(i, std::move(ev)).first->second; } - else - rval = it->second; - return rval; + return it->second; } void EnumType::DescribeReST(ODesc* d, bool roles_only) const diff --git a/src/Type.h b/src/Type.h index 5787424c58..0351c8a6ee 100644 --- a/src/Type.h +++ b/src/Type.h @@ -723,7 +723,7 @@ public: void DescribeReST(ODesc* d, bool roles_only = false) const override; - IntrusivePtr GetVal(bro_int_t i); + const IntrusivePtr& GetVal(bro_int_t i); protected: void AddNameInternal(const std::string& module_name, diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index 501f5a8563..ab5193725d 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -79,7 +79,7 @@ bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_statu double last_time, int reply_len) { EventHandlerPtr event = nullptr; - Val* reply = nullptr; + IntrusivePtr reply; BifEnum::MOUNT3::status_t mount_status = BifEnum::MOUNT3::MNT3_OK; bool rpc_success = ( rpc_status == BifEnum::RPC_SUCCESS ); @@ -114,19 +114,17 @@ bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_statu break; case BifEnum::MOUNT3::PROC_MNT: - reply = mount3_mnt_reply(buf, n, mount_status); + reply = {AdoptRef{}, mount3_mnt_reply(buf, n, mount_status)}; event = mount_proc_mnt; break; case BifEnum::MOUNT3::PROC_UMNT: - reply = nullptr; n = 0; mount_status = BifEnum::MOUNT3::MNT3_OK; event = mount_proc_umnt; break; case BifEnum::MOUNT3::PROC_UMNT_ALL: - reply = nullptr; n = 0; mount_status = BifEnum::MOUNT3::MNT3_OK; event = mount_proc_umnt; @@ -139,7 +137,7 @@ bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_statu // Otherwise DeliverRPC would complain about // excess_RPC. n = 0; - reply = zeek::BifType::Enum::MOUNT3::proc_t->GetVal(c->Proc()).release(); + reply = zeek::BifType::Enum::MOUNT3::proc_t->GetVal(c->Proc()); event = mount_proc_not_implemented; } else @@ -148,9 +146,7 @@ bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_statu if ( rpc_success && ! buf ) { - // There was a parse error. We have to unref the reply. (see - // also comments in RPC_BuildCall. - Unref(reply); + // There was a parse error. reply = nullptr; return false; } @@ -172,12 +168,11 @@ bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_statu vl.emplace_back(AdoptRef{}, request); if ( reply ) - vl.emplace_back(AdoptRef{}, reply); + vl.emplace_back(reply); analyzer->EnqueueConnEvent(event, std::move(vl)); } - else - Unref(reply); + return true; } @@ -221,7 +216,8 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, EnumVal* MOUNT_Interp::mount3_auth_flavor(const u_char*& buf, int& n) { BifEnum::MOUNT3::auth_flavor_t t = (BifEnum::MOUNT3::auth_flavor_t)extract_XDR_uint32(buf, n); - return zeek::BifType::Enum::MOUNT3::auth_flavor_t->GetVal(t).release(); + auto rval = zeek::BifType::Enum::MOUNT3::auth_flavor_t->GetVal(t); + return rval.release(); } StringVal* MOUNT_Interp::mount3_fh(const u_char*& buf, int& n) diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index 3e343f2e73..c97bcf7b3c 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -251,7 +251,8 @@ bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, // Otherwise DeliverRPC would complain about // excess_RPC. n = 0; - reply = zeek::BifType::Enum::NFS3::proc_t->GetVal(c->Proc()).release(); + auto ev = zeek::BifType::Enum::NFS3::proc_t->GetVal(c->Proc()); + reply = ev.release(); event = nfs_proc_not_implemented; } else @@ -438,13 +439,15 @@ RecordVal* NFS_Interp::nfs3_fattr(const u_char*& buf, int& n) EnumVal* NFS_Interp::nfs3_time_how(const u_char*& buf, int& n) { BifEnum::NFS3::time_how_t t = (BifEnum::NFS3::time_how_t)extract_XDR_uint32(buf, n); - return zeek::BifType::Enum::NFS3::time_how_t->GetVal(t).release(); + auto rval = zeek::BifType::Enum::NFS3::time_how_t->GetVal(t); + return rval.release(); } EnumVal* NFS_Interp::nfs3_ftype(const u_char*& buf, int& n) { BifEnum::NFS3::file_type_t t = (BifEnum::NFS3::file_type_t)extract_XDR_uint32(buf, n); - return zeek::BifType::Enum::NFS3::file_type_t->GetVal(t).release(); + auto rval = zeek::BifType::Enum::NFS3::file_type_t->GetVal(t); + return rval.release(); } RecordVal* NFS_Interp::nfs3_wcc_attr(const u_char*& buf, int& n) @@ -533,7 +536,8 @@ RecordVal* NFS_Interp::nfs3_pre_op_attr(const u_char*& buf, int& n) EnumVal *NFS_Interp::nfs3_stable_how(const u_char*& buf, int& n) { BifEnum::NFS3::stable_how_t stable = (BifEnum::NFS3::stable_how_t)extract_XDR_uint32(buf, n); - return zeek::BifType::Enum::NFS3::stable_how_t->GetVal(stable).release(); + auto rval = zeek::BifType::Enum::NFS3::stable_how_t->GetVal(stable); + return rval.release(); } RecordVal* NFS_Interp::nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) diff --git a/src/broker/Data.cc b/src/broker/Data.cc index de449b820f..395afc4cc1 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -196,7 +196,8 @@ struct val_converter { if ( i == -1 ) return nullptr; - return etype->GetVal(i).release(); + auto rval = etype->GetVal(i); + return rval.release(); } return nullptr; diff --git a/src/broker/Store.cc b/src/broker/Store.cc index 0e6bf5b4f6..c66b993ebd 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -20,7 +20,8 @@ EnumVal* query_status(bool success) failure_val = store_query_status->Lookup("Broker", "FAILURE"); } - return store_query_status->GetVal(success ? success_val : failure_val).release(); + auto rval = store_query_status->GetVal(success ? success_val : failure_val); + return rval.release(); } void StoreHandleVal::ValDescribe(ODesc* d) const diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 9c0060801d..4b80d657a1 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1072,8 +1072,8 @@ void Manager::SendEntry(ReaderFrontend* reader, Value* *vals) else if ( i->stream_type == EVENT_STREAM ) { - EnumVal* type = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); - readFields = SendEventStreamEvent(i, type, vals); + auto type = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW); + readFields = SendEventStreamEvent(i, type.release(), vals); } else if ( i->stream_type == ANALYSIS_STREAM ) @@ -1166,7 +1166,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) // call stream first to determine if we really add / change the entry if ( stream->pred && ! convert_error ) { - EnumVal* ev; + IntrusivePtr ev; int startpos = 0; bool pred_convert_error = false; predidx = ValueToRecordVal(i, vals, stream->itype, &startpos, pred_convert_error); @@ -1177,15 +1177,15 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) if ( ! pred_convert_error ) { if ( updated ) - ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED); else - ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW); bool result; if ( stream->num_val_fields > 0 ) // we have values - result = CallPred(stream->pred, 3, ev, predidx->Ref(), valval->Ref()); + result = CallPred(stream->pred, 3, ev.release(), predidx->Ref(), valval->Ref()); else // no values - result = CallPred(stream->pred, 2, ev, predidx->Ref()); + result = CallPred(stream->pred, 2, ev.release(), predidx->Ref()); if ( result == false ) { @@ -1265,7 +1265,6 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) if ( stream->event ) { - EnumVal* ev; int startpos = 0; Val* predidx = ValueToRecordVal(i, vals, stream->itype, &startpos, convert_error); @@ -1278,20 +1277,20 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) else if ( updated ) { // in case of update send back the old value. assert ( stream->num_val_fields > 0 ); - ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); + auto ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED); assert ( oldval != nullptr ); - SendEvent(stream->event, 4, stream->description->Ref(), ev, predidx, oldval.release()); + SendEvent(stream->event, 4, stream->description->Ref(), ev.release(), predidx, oldval.release()); } else { - ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + auto ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW); if ( stream->num_val_fields == 0 ) { Ref(stream->description); - SendEvent(stream->event, 3, stream->description->Ref(), ev, predidx); + SendEvent(stream->event, 3, stream->description->Ref(), ev.release(), predidx); } else - SendEvent(stream->event, 4, stream->description->Ref(), ev, predidx, valval->Ref()); + SendEvent(stream->event, 4, stream->description->Ref(), ev.release(), predidx, valval->Ref()); } } @@ -1335,9 +1334,8 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) while ( ( ih = stream->lastDict->NextEntry(lastDictIdxKey, c) ) ) { IntrusivePtr val; - - Val* predidx = nullptr; - EnumVal* ev = nullptr; + IntrusivePtr predidx; + IntrusivePtr ev; int startpos = 0; if ( stream->pred || stream->event ) @@ -1346,25 +1344,21 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) assert(idx != nullptr); val = stream->tab->Lookup(idx.get()); assert(val != nullptr); - predidx = ListValToRecordVal(idx.get(), stream->itype, &startpos); - ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); + predidx = {AdoptRef{}, ListValToRecordVal(idx.get(), stream->itype, &startpos)}; + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED); } if ( stream->pred ) { // ask predicate, if we want to expire this element... - Ref(ev); - Ref(predidx); - - bool result = CallPred(stream->pred, 3, ev, predidx, IntrusivePtr{val}.release()); + bool result = CallPred(stream->pred, 3, ev->Ref(), predidx->Ref(), + val->Ref()); if ( result == false ) { // Keep it. Hence - we quit and simply go to the next entry of lastDict // ah well - and we have to add the entry to currDict... - Unref(predidx); - Unref(ev); stream->currDict->Insert(lastDictIdxKey, stream->lastDict->RemoveEntry(lastDictIdxKey)); delete lastDictIdxKey; continue; @@ -1372,17 +1366,8 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) } if ( stream->event ) - { - Ref(predidx); - Ref(ev); - SendEvent(stream->event, 4, stream->description->Ref(), ev, predidx, IntrusivePtr{val}.release()); - } - - if ( predidx ) // if we have a stream or an event... - Unref(predidx); - - if ( ev ) - Unref(ev); + SendEvent(stream->event, 4, stream->description->Ref(), ev->Ref(), + predidx->Ref(), val->Ref()); stream->tab->Delete(ih->idxkey); stream->lastDict->Remove(lastDictIdxKey); // delete in next line @@ -1454,8 +1439,8 @@ void Manager::Put(ReaderFrontend* reader, Value* *vals) else if ( i->stream_type == EVENT_STREAM ) { - EnumVal* type = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); - readFields = SendEventStreamEvent(i, type, vals); + auto type = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW); + readFields = SendEventStreamEvent(i, type.release(), vals); } else if ( i->stream_type == ANALYSIS_STREAM ) @@ -1581,7 +1566,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) // predicate if we want the update or not if ( stream->pred ) { - EnumVal* ev; + IntrusivePtr ev; int startpos = 0; bool pred_convert_error = false; Val* predidx = ValueToRecordVal(i, vals, stream->itype, &startpos, pred_convert_error); @@ -1591,18 +1576,18 @@ int Manager::PutTable(Stream* i, const Value* const *vals) else { if ( updated ) - ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED); else - ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW); bool result; if ( stream->num_val_fields > 0 ) // we have values { Ref(valval); - result = CallPred(stream->pred, 3, ev, predidx, valval); + result = CallPred(stream->pred, 3, ev.release(), predidx, valval); } else // no values - result = CallPred(stream->pred, 2, ev, predidx); + result = CallPred(stream->pred, 2, ev.release(), predidx); if ( result == false ) { @@ -1619,7 +1604,6 @@ int Manager::PutTable(Stream* i, const Value* const *vals) if ( stream->event ) { - EnumVal* ev; int startpos = 0; bool event_convert_error = false; Val* predidx = ValueToRecordVal(i, vals, stream->itype, &startpos, event_convert_error); @@ -1632,20 +1616,20 @@ int Manager::PutTable(Stream* i, const Value* const *vals) { // in case of update send back the old value. assert ( stream->num_val_fields > 0 ); - ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); + auto ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED); assert ( oldval != nullptr ); SendEvent(stream->event, 4, stream->description->Ref(), - ev, predidx, oldval.release()); + ev.release(), predidx, oldval.release()); } else { - ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW).release(); + auto ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_NEW); if ( stream->num_val_fields == 0 ) SendEvent(stream->event, 4, stream->description->Ref(), - ev, predidx); + ev.release(), predidx); else SendEvent(stream->event, 4, stream->description->Ref(), - ev, predidx, valval->Ref()); + ev.release(), predidx, valval->Ref()); } } @@ -1724,9 +1708,9 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) Unref(predidx); else { - EnumVal* ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); + auto ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED); - streamresult = CallPred(stream->pred, 3, ev, predidx, IntrusivePtr{val}.release()); + streamresult = CallPred(stream->pred, 3, ev.release(), predidx, IntrusivePtr{val}.release()); if ( streamresult == false ) { @@ -1743,8 +1727,8 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) { Ref(idxval); assert(val != nullptr); - EnumVal* ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); - SendEvent(stream->event, 4, stream->description->Ref(), ev, idxval, IntrusivePtr{val}.release()); + auto ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED); + SendEvent(stream->event, 4, stream->description->Ref(), ev.release(), idxval, IntrusivePtr{val}.release()); } } @@ -1758,8 +1742,8 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) else if ( i->stream_type == EVENT_STREAM ) { - EnumVal* type = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); - readVals = SendEventStreamEvent(i, type, vals); + auto type = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED); + readVals = SendEventStreamEvent(i, type.release(), vals); success = true; } @@ -2385,7 +2369,8 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ return nullptr; } - return request_type->AsEnumType()->GetVal(index).release(); + auto rval = request_type->AsEnumType()->GetVal(index); + return rval.release(); } default: @@ -2583,7 +2568,8 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co return nullptr; } - return t->GetVal(intval).release(); + auto rval = t->GetVal(intval); + return rval.release(); } default: @@ -2711,19 +2697,19 @@ void Manager::ErrorHandler(const Stream* i, ErrorType et, bool reporter_send, co // send our script level error event if ( i->error_event ) { - EnumVal* ev; + IntrusivePtr ev; switch (et) { case ErrorType::INFO: - ev = zeek::BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::INFO).release(); + ev = zeek::BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::INFO); break; case ErrorType::WARNING: - ev = zeek::BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::WARNING).release(); + ev = zeek::BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::WARNING); break; case ErrorType::ERROR: - ev = zeek::BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::ERROR).release(); + ev = zeek::BifType::Enum::Reporter::Level->GetVal(BifEnum::Reporter::ERROR); break; default: @@ -2732,7 +2718,7 @@ void Manager::ErrorHandler(const Stream* i, ErrorType et, bool reporter_send, co } StringVal* message = new StringVal(buf); - SendEvent(i->error_event, 3, i->description->Ref(), message, ev); + SendEvent(i->error_event, 3, i->description->Ref(), message, ev.release()); } if ( reporter_send ) diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index e351ee2fe3..cbaf7c53e7 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1290,7 +1290,7 @@ void Manager::SendAllWritersTo(const broker::endpoint_info& ei) i != stream->writers.end(); i++ ) { WriterFrontend* writer = i->second->writer; - auto writer_val = et->GetVal(i->first.first); + const auto& writer_val = et->GetVal(i->first.first); broker_mgr->PublishLogCreate((*s)->id, writer_val.get(), *i->second->info, From 8fc89491bfe5d9ea63765e33d4aeb9e88ebbf820 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 14 May 2020 23:04:50 -0700 Subject: [PATCH 064/151] fixup! Deprecate Scope::Lookup(), replace with Scope::Find() --- src/zeek.bif | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zeek.bif b/src/zeek.bif index 1eaf579c79..f649eb2727 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -3906,7 +3906,7 @@ static Val* mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, static bool mmdb_try_open_loc () { // City database is always preferred over Country database. - const auto& mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->GetVal(); + const auto& mmdb_dir_val = global_scope()->Find("mmdb_dir")->GetVal(); std::string mmdb_dir = mmdb_dir_val->AsString()->CheckString(); if ( ! mmdb_dir.empty() ) @@ -3934,7 +3934,7 @@ static bool mmdb_try_open_loc () static bool mmdb_try_open_asn () { - const auto& mmdb_dir_val = global_scope()->Lookup("mmdb_dir")->GetVal(); + const auto& mmdb_dir_val = global_scope()->Find("mmdb_dir")->GetVal(); std::string mmdb_dir = mmdb_dir_val->AsString()->CheckString(); if ( ! mmdb_dir.empty() ) From 4a2221b8782fdb9c3d76bdd4a8ea342942e038eb Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 14 May 2020 23:31:47 -0700 Subject: [PATCH 065/151] Deprecate OpaqueVal/HashVal ctors that take OpaqueType* Replaced with ones that take IntrusivePtr --- src/OpaqueVal.cc | 21 +++++++++------------ src/OpaqueVal.h | 6 +++++- src/Type.h | 20 ++++++++++---------- src/broker/Data.cc | 10 +++++----- src/broker/Data.h | 10 +++++----- src/broker/Manager.cc | 12 ++++++------ src/broker/Store.cc | 2 +- src/broker/Store.h | 2 +- src/zeek-setup.cc | 40 ++++++++++++++++++++-------------------- 9 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 5f561ae9f5..703efba33b 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -37,9 +37,11 @@ OpaqueMgr* OpaqueMgr::mgr() return &mgr; } -OpaqueVal::OpaqueVal(OpaqueType* t) : Val(IntrusivePtr{NewRef{}, t}) - { - } +OpaqueVal::OpaqueVal(OpaqueType* t) : OpaqueVal({NewRef{}, t}) + {} + +OpaqueVal::OpaqueVal(IntrusivePtr t) : Val(std::move(t)) + {} OpaqueVal::~OpaqueVal() { @@ -204,11 +206,14 @@ IntrusivePtr HashVal::DoGet() return val_mgr->EmptyString(); } -HashVal::HashVal(OpaqueType* t) : OpaqueVal(t) +HashVal::HashVal(IntrusivePtr t) : OpaqueVal(std::move(t)) { valid = false; } +HashVal::HashVal(OpaqueType* t) : HashVal({NewRef{}, t}) + {} + MD5Val::MD5Val() : HashVal(md5_type) { } @@ -700,14 +705,6 @@ BloomFilterVal::BloomFilterVal() bloom_filter = nullptr; } -BloomFilterVal::BloomFilterVal(OpaqueType* t) - : OpaqueVal(t) - { - type = nullptr; - hash = nullptr; - bloom_filter = nullptr; - } - BloomFilterVal::BloomFilterVal(probabilistic::BloomFilter* bf) : OpaqueVal(bloomfilter_type) { diff --git a/src/OpaqueVal.h b/src/OpaqueVal.h index 6ad65a4df3..6071dbf951 100644 --- a/src/OpaqueVal.h +++ b/src/OpaqueVal.h @@ -87,7 +87,9 @@ private: */ class OpaqueVal : public Val { public: + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit OpaqueVal(OpaqueType* t); + explicit OpaqueVal(IntrusivePtr t); ~OpaqueVal() override; /** @@ -183,7 +185,10 @@ protected: static void digest_one(EVP_MD_CTX* h, const IntrusivePtr& v); HashVal() { valid = false; } + + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit HashVal(OpaqueType* t); + explicit HashVal(IntrusivePtr t); virtual bool DoInit(); virtual bool DoFeed(const void* data, size_t size); @@ -314,7 +319,6 @@ public: protected: friend class Val; BloomFilterVal(); - explicit BloomFilterVal(OpaqueType* t); DECLARE_OPAQUE_VALUE(BloomFilterVal) private: diff --git a/src/Type.h b/src/Type.h index 0351c8a6ee..ac537577e3 100644 --- a/src/Type.h +++ b/src/Type.h @@ -769,16 +769,16 @@ protected: IntrusivePtr yield_type; }; -extern OpaqueType* md5_type; -extern OpaqueType* sha1_type; -extern OpaqueType* sha256_type; -extern OpaqueType* entropy_type; -extern OpaqueType* cardinality_type; -extern OpaqueType* topk_type; -extern OpaqueType* bloomfilter_type; -extern OpaqueType* x509_opaque_type; -extern OpaqueType* ocsp_resp_opaque_type; -extern OpaqueType* paraglob_type; +extern IntrusivePtr md5_type; +extern IntrusivePtr sha1_type; +extern IntrusivePtr sha256_type; +extern IntrusivePtr entropy_type; +extern IntrusivePtr cardinality_type; +extern IntrusivePtr topk_type; +extern IntrusivePtr bloomfilter_type; +extern IntrusivePtr x509_opaque_type; +extern IntrusivePtr ocsp_resp_opaque_type; +extern IntrusivePtr paraglob_type; // Returns the basic (non-parameterized) type with the given type. const IntrusivePtr& base_type(TypeTag tag); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 395afc4cc1..f6f958d6a6 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -17,11 +17,11 @@ using namespace std; -OpaqueType* bro_broker::opaque_of_data_type; -OpaqueType* bro_broker::opaque_of_set_iterator; -OpaqueType* bro_broker::opaque_of_table_iterator; -OpaqueType* bro_broker::opaque_of_vector_iterator; -OpaqueType* bro_broker::opaque_of_record_iterator; +IntrusivePtr bro_broker::opaque_of_data_type; +IntrusivePtr bro_broker::opaque_of_set_iterator; +IntrusivePtr bro_broker::opaque_of_table_iterator; +IntrusivePtr bro_broker::opaque_of_vector_iterator; +IntrusivePtr bro_broker::opaque_of_record_iterator; BroType* bro_broker::DataVal::script_data_type = nullptr; diff --git a/src/broker/Data.h b/src/broker/Data.h index cf5f06b90d..d511581ba1 100644 --- a/src/broker/Data.h +++ b/src/broker/Data.h @@ -12,11 +12,11 @@ class ODesc; namespace bro_broker { -extern OpaqueType* opaque_of_data_type; -extern OpaqueType* opaque_of_set_iterator; -extern OpaqueType* opaque_of_table_iterator; -extern OpaqueType* opaque_of_vector_iterator; -extern OpaqueType* opaque_of_record_iterator; +extern IntrusivePtr opaque_of_data_type; +extern IntrusivePtr opaque_of_set_iterator; +extern IntrusivePtr opaque_of_table_iterator; +extern IntrusivePtr opaque_of_vector_iterator; +extern IntrusivePtr opaque_of_record_iterator; /** * Convert a broker port protocol to a bro port protocol. diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index b60ceed282..446ac93fd2 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -151,12 +151,12 @@ void Manager::InitPostScript() log_id_type = zeek::id::find_type("Log::ID")->AsEnumType(); writer_id_type = zeek::id::find_type("Log::Writer")->AsEnumType(); - opaque_of_data_type = new OpaqueType("Broker::Data"); - opaque_of_set_iterator = new OpaqueType("Broker::SetIterator"); - opaque_of_table_iterator = new OpaqueType("Broker::TableIterator"); - opaque_of_vector_iterator = new OpaqueType("Broker::VectorIterator"); - opaque_of_record_iterator = new OpaqueType("Broker::RecordIterator"); - opaque_of_store_handle = new OpaqueType("Broker::Store"); + opaque_of_data_type = make_intrusive("Broker::Data"); + opaque_of_set_iterator = make_intrusive("Broker::SetIterator"); + opaque_of_table_iterator = make_intrusive("Broker::TableIterator"); + opaque_of_vector_iterator = make_intrusive("Broker::VectorIterator"); + opaque_of_record_iterator = make_intrusive("Broker::RecordIterator"); + opaque_of_store_handle = make_intrusive("Broker::Store"); vector_of_data_type = make_intrusive(zeek::id::find_type("Broker::Data")); // Register as a "dont-count" source first, we may change that later. diff --git a/src/broker/Store.cc b/src/broker/Store.cc index c66b993ebd..e763e468ba 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -5,7 +5,7 @@ namespace bro_broker { -OpaqueType* opaque_of_store_handle; +IntrusivePtr opaque_of_store_handle; EnumVal* query_status(bool success) { diff --git a/src/broker/Store.h b/src/broker/Store.h index b439d39e0f..be35c78254 100644 --- a/src/broker/Store.h +++ b/src/broker/Store.h @@ -11,7 +11,7 @@ namespace bro_broker { -extern OpaqueType* opaque_of_store_handle; +extern IntrusivePtr opaque_of_store_handle; /** * Create a Broker::QueryStatus value. diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 14cf82fe25..fdbfbe7ec7 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -113,16 +113,16 @@ vector params; set requested_plugins; const char* proc_status_file = nullptr; -OpaqueType* md5_type = nullptr; -OpaqueType* sha1_type = nullptr; -OpaqueType* sha256_type = nullptr; -OpaqueType* entropy_type = nullptr; -OpaqueType* cardinality_type = nullptr; -OpaqueType* topk_type = nullptr; -OpaqueType* bloomfilter_type = nullptr; -OpaqueType* x509_opaque_type = nullptr; -OpaqueType* ocsp_resp_opaque_type = nullptr; -OpaqueType* paraglob_type = nullptr; +IntrusivePtr md5_type; +IntrusivePtr sha1_type; +IntrusivePtr sha256_type; +IntrusivePtr entropy_type; +IntrusivePtr cardinality_type; +IntrusivePtr topk_type; +IntrusivePtr bloomfilter_type; +IntrusivePtr x509_opaque_type; +IntrusivePtr ocsp_resp_opaque_type; +IntrusivePtr paraglob_type; // Keep copy of command line int bro_argc; @@ -592,16 +592,16 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, init_event_handlers(); - md5_type = new OpaqueType("md5"); - sha1_type = new OpaqueType("sha1"); - sha256_type = new OpaqueType("sha256"); - entropy_type = new OpaqueType("entropy"); - cardinality_type = new OpaqueType("cardinality"); - topk_type = new OpaqueType("topk"); - bloomfilter_type = new OpaqueType("bloomfilter"); - x509_opaque_type = new OpaqueType("x509"); - ocsp_resp_opaque_type = new OpaqueType("ocsp_resp"); - paraglob_type = new OpaqueType("paraglob"); + md5_type = make_intrusive("md5"); + sha1_type = make_intrusive("sha1"); + sha256_type = make_intrusive("sha256"); + entropy_type = make_intrusive("entropy"); + cardinality_type = make_intrusive("cardinality"); + topk_type = make_intrusive("topk"); + bloomfilter_type = make_intrusive("bloomfilter"); + x509_opaque_type = make_intrusive("x509"); + ocsp_resp_opaque_type = make_intrusive("ocsp_resp"); + paraglob_type = make_intrusive("paraglob"); // The leak-checker tends to produce some false // positives (memory which had already been From a031f5b7278394fe2bd1f84fef4423161abdd18e Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 16:24:53 -0700 Subject: [PATCH 066/151] Deprecate Val(Func*) ctor, replace with one using IntrusivePtr --- src/CompHash.cc | 2 +- src/Expr.cc | 7 +++---- src/Func.cc | 7 +++---- src/Func.h | 9 ++++++--- src/Val.cc | 13 +++++++------ src/Val.h | 2 ++ src/Var.cc | 8 ++++---- 7 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index 2e0a6590e7..ed3b7788a0 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -845,7 +845,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, const uint32_t* const kp = AlignType(kp0); kp1 = reinterpret_cast(kp+1); - Func* f = Func::GetFuncPtrByID(*kp); + const auto& f = Func::GetFuncPtrByID(*kp); if ( ! f ) reporter->InternalError("failed to look up unique function id %" PRIu32 " in CompositeHash::RecoverOneVal()", *kp); diff --git a/src/Expr.cc b/src/Expr.cc index 7dfba4020f..739a0e8b8b 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4207,7 +4207,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, // Install a dummy version of the function globally for use only // when broker provides a closure. - BroFunc* dummy_func = new BroFunc( + auto dummy_func = make_intrusive( ingredients->id.get(), ingredients->body, shallow_copy_func_inits(ingredients->body, ingredients->inits).release(), @@ -4245,8 +4245,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, // Update lamb's name dummy_func->SetName(my_name.c_str()); - auto v = make_intrusive(dummy_func); - Unref(dummy_func); + auto v = make_intrusive(std::move(dummy_func)); id->SetVal(std::move(v)); id->SetType(ingredients->id->GetType()); id->SetConst(); @@ -4272,7 +4271,7 @@ IntrusivePtr LambdaExpr::Eval(Frame* f) const // Allows for lookups by the receiver. lamb->SetName(my_name.c_str()); - return make_intrusive(lamb.get()); + return make_intrusive(std::move(lamb)); } void LambdaExpr::ExprDescribe(ODesc* d) const diff --git a/src/Func.cc b/src/Func.cc index a40b384a17..5d4da73ced 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -59,7 +59,6 @@ extern RETSIGTYPE sig_handler(int signo); std::vector call_stack; bool did_builtin_init = false; -std::vector Func::unique_ids; static const std::pair empty_hook_result(false, NULL); std::string render_call_stack() @@ -111,13 +110,13 @@ std::string render_call_stack() Func::Func() { unique_id = unique_ids.size(); - unique_ids.push_back(this); + unique_ids.push_back({NewRef{}, this}); } Func::Func(Kind arg_kind) : kind(arg_kind) { unique_id = unique_ids.size(); - unique_ids.push_back(this); + unique_ids.push_back({NewRef{}, this}); } Func::~Func() = default; @@ -594,7 +593,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, reporter->InternalError("built-in function %s multiply defined", Name()); type = id->GetType(); - id->SetVal(make_intrusive(this)); + id->SetVal(make_intrusive(IntrusivePtr{NewRef{}, this})); } BuiltinFunc::~BuiltinFunc() diff --git a/src/Func.h b/src/Func.h index cc18471b1a..9eaedd5ac8 100644 --- a/src/Func.h +++ b/src/Func.h @@ -93,8 +93,11 @@ public: virtual TraversalCode Traverse(TraversalCallback* cb) const; uint32_t GetUniqueFuncID() const { return unique_id; } - static Func* GetFuncPtrByID(uint32_t id) - { return id >= unique_ids.size() ? nullptr : unique_ids[id]; } + static const IntrusivePtr& GetFuncPtrByID(uint32_t id) + { + static IntrusivePtr nil; + return id >= unique_ids.size() ? nil : unique_ids[id]; + } protected: Func(); @@ -111,7 +114,7 @@ protected: uint32_t unique_id; IntrusivePtr type; std::string name; - static std::vector unique_ids; + static inline std::vector> unique_ids; }; diff --git a/src/Val.cc b/src/Val.cc index 4e39ac676e..d1850c6e1a 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -42,11 +42,12 @@ using namespace std; -Val::Val(Func* f) - : val(f), type({NewRef{}, f->FType()}) - { - ::Ref(val.func_val); - } +Val::Val(Func* f) : Val({NewRef{}, f}) + {} + +Val::Val(IntrusivePtr f) + : val(f.release()), type({NewRef{}, val.func_val->FType()}) + {} static const IntrusivePtr& GetStringFileType() noexcept { @@ -118,7 +119,7 @@ IntrusivePtr Val::DoClone(CloneState* state) // Derived classes are responsible for this. Exception: // Functions and files. There aren't any derived classes. if ( type->Tag() == TYPE_FUNC ) - return make_intrusive(AsFunc()->DoClone().get()); + return make_intrusive(AsFunc()->DoClone()); if ( type->Tag() == TYPE_FILE ) { diff --git a/src/Val.h b/src/Val.h index d94d94624c..81dfd3003f 100644 --- a/src/Val.h +++ b/src/Val.h @@ -129,7 +129,9 @@ public: : val(d), type(base_type(t)) {} + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit Val(Func* f); + explicit Val(IntrusivePtr f); // Note, will unref 'f' when it's done, closing it unless // class has ref'd it. diff --git a/src/Var.cc b/src/Var.cc index f89d1b1473..a5d64a65d5 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -298,8 +298,8 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, // For events, add a function value (without any body) here so that // we can later access the ID even if no implementations have been // defined. - Func* f = new BroFunc(id, nullptr, nullptr, 0, 0); - id->SetVal(make_intrusive(f)); + auto f = make_intrusive(id, nullptr, nullptr, 0, 0); + id->SetVal(make_intrusive(std::move(f))); } } @@ -638,14 +638,14 @@ void end_func(IntrusivePtr body) ingredients->priority); else { - Func* f = new BroFunc( + auto f = make_intrusive( ingredients->id.get(), ingredients->body, ingredients->inits, ingredients->frame_size, ingredients->priority); - ingredients->id->SetVal(make_intrusive(f)); + ingredients->id->SetVal(make_intrusive(std::move(f))); ingredients->id->SetConst(); } From 65aad4922d807070ebddc3d6252693e8a91a7821 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 17:11:05 -0700 Subject: [PATCH 067/151] Deprecate Val(BroFile*) ctor, replace with one using IntrusivePtr --- aux/bifcl | 2 +- src/EventLauncher.cc | 1 + src/File.cc | 4 ++-- src/Stats.cc | 3 +-- src/Val.cc | 9 ++++++--- src/Val.h | 6 ++++-- src/analyzer/protocol/tcp/functions.bif | 11 ++++++----- src/broker/Data.cc | 2 +- src/zeek.bif | 6 +++--- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/aux/bifcl b/aux/bifcl index 2c7ded074f..31f7e04b0d 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 2c7ded074fdea124fcae7845d1f8e77879925270 +Subproject commit 31f7e04b0da5cfa65211208c64ac62874a065fc6 diff --git a/src/EventLauncher.cc b/src/EventLauncher.cc index cc32efe59e..293869c0f7 100644 --- a/src/EventLauncher.cc +++ b/src/EventLauncher.cc @@ -4,5 +4,6 @@ #include "Event.h" #include "NetVar.h" #include "Conn.h" +#include "File.h" #include "event.bif.func_def" diff --git a/src/File.cc b/src/File.cc index 05c16d2efb..26ed28455b 100644 --- a/src/File.cc +++ b/src/File.cc @@ -328,8 +328,8 @@ void BroFile::RaiseOpenEvent() if ( ! ::file_opened ) return; - Ref(this); - Event* event = new ::Event(::file_opened, {make_intrusive(this)}); + IntrusivePtr bf{NewRef{}, this}; + Event* event = new ::Event(::file_opened, {make_intrusive(std::move(bf))}); mgr.Dispatch(event, true); } diff --git a/src/Stats.cc b/src/Stats.cc index 2b2c187c73..09c5df495c 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -311,9 +311,8 @@ void ProfileLogger::Log() // (and for consistency we dispatch it *now*) if ( profiling_update ) { - Ref(file); mgr.Dispatch(new Event(profiling_update, { - make_intrusive(file), + make_intrusive(IntrusivePtr{NewRef{}, file}), val_mgr->Bool(expensive), })); } diff --git a/src/Val.cc b/src/Val.cc index d1850c6e1a..53769963ca 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -57,10 +57,13 @@ static const IntrusivePtr& GetStringFileType() noexcept return string_file_type; } -Val::Val(BroFile* f) - : val(f), type(GetStringFileType()) +Val::Val(BroFile* f) : Val({AdoptRef{}, f}) + {} + +Val::Val(IntrusivePtr f) + : val(f.release()), type(GetStringFileType()) { - assert(f->FType()->Tag() == TYPE_STRING); + assert(val.file_val->FType()->Tag() == TYPE_STRING); } Val::~Val() diff --git a/src/Val.h b/src/Val.h index 81dfd3003f..1948440387 100644 --- a/src/Val.h +++ b/src/Val.h @@ -133,9 +133,11 @@ public: explicit Val(Func* f); explicit Val(IntrusivePtr f); - // Note, will unref 'f' when it's done, closing it unless - // class has ref'd it. + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit Val(BroFile* f); + // Note, the file will be closed after this Val is destructed if there's + // no other remaining references. + explicit Val(IntrusivePtr f); // Extra arg to differentiate from protected version. Val(IntrusivePtr t, bool type_type) diff --git a/src/analyzer/protocol/tcp/functions.bif b/src/analyzer/protocol/tcp/functions.bif index a560301b8a..461f7a510e 100644 --- a/src/analyzer/protocol/tcp/functions.bif +++ b/src/analyzer/protocol/tcp/functions.bif @@ -121,12 +121,13 @@ function set_contents_file%(cid: conn_id, direction: count, f: file%): bool function get_contents_file%(cid: conn_id, direction: count%): file %{ Connection* c = sessions->FindConnection(cid); - BroFile* f = c ? c->GetRootAnalyzer()->GetContentsFile(direction) : nullptr; - if ( f ) + if ( c ) { - Ref(f); - return make_intrusive(f); + auto cf = c->GetRootAnalyzer()->GetContentsFile(direction); + + if ( cf ) + return make_intrusive(IntrusivePtr{NewRef{}, cf}); } // Return some sort of error value. @@ -135,5 +136,5 @@ function get_contents_file%(cid: conn_id, direction: count%): file else builtin_error("no contents file for given direction"); - return make_intrusive(new BroFile(stderr, "-", "w")); + return make_intrusive(make_intrusive(stderr, "-", "w")); %} diff --git a/src/broker/Data.cc b/src/broker/Data.cc index f6f958d6a6..b17dc0dabc 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -127,7 +127,7 @@ struct val_converter { auto file = BroFile::GetFile(a.data()); if ( file ) - return new Val(file); + return new Val({AdoptRef{}, file}); return nullptr; } diff --git a/src/zeek.bif b/src/zeek.bif index f649eb2727..01d933dfcd 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -4398,9 +4398,9 @@ function open%(f: string%): file const char* file = f->CheckString(); if ( streq(file, "-") ) - return make_intrusive(new BroFile(stdout, "-", "w")); + return make_intrusive(make_intrusive(stdout, "-", "w")); else - return make_intrusive(new BroFile(file, "w")); + return make_intrusive(make_intrusive(file, "w")); %} ## Opens a file for writing or appending. If a file with the same name already @@ -4415,7 +4415,7 @@ function open%(f: string%): file ## rmdir unlink rename function open_for_append%(f: string%): file %{ - return make_intrusive(new BroFile(f->CheckString(), "a")); + return make_intrusive(make_intrusive(f->CheckString(), "a")); %} ## Closes an open file and flushes any buffered content. From 599eec297c92f5b6c444ae32681314e54695ef5a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 17:22:16 -0700 Subject: [PATCH 068/151] Deprecate BroFile::GetFile(), replace with BroFile::Get() --- src/File.cc | 11 +++-------- src/File.h | 5 ++++- src/broker/Data.cc | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/File.cc b/src/File.cc index 26ed28455b..d70d92047a 100644 --- a/src/File.cc +++ b/src/File.cc @@ -346,16 +346,11 @@ double BroFile::Size() return s.st_size; } -BroFile* BroFile::GetFile(const char* name) +IntrusivePtr BroFile::Get(const char* name) { for ( const auto &el : open_files ) - { if ( el.first == name ) - { - Ref(el.second); - return el.second; - } - } + return {NewRef{}, el.second}; - return new BroFile(name, "w"); + return make_intrusive(name, "w"); } diff --git a/src/File.h b/src/File.h index 01409ff742..212e301afb 100644 --- a/src/File.h +++ b/src/File.h @@ -63,7 +63,10 @@ public: static void CloseOpenFiles(); // Get the file with the given name, opening it if it doesn't yet exist. - static BroFile* GetFile(const char* name); + static IntrusivePtr Get(const char* name); + [[deprecated("Remove in v4.1. Use BroFile::Get().")]] + static BroFile* GetFile(const char* name) + { return Get(name).release(); } void EnableRawOutput() { raw_output = true; } bool IsRawOutput() const { return raw_output; } diff --git a/src/broker/Data.cc b/src/broker/Data.cc index b17dc0dabc..2b5e94e2b0 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -124,10 +124,10 @@ struct val_converter { return new StringVal(a.size(), a.data()); case TYPE_FILE: { - auto file = BroFile::GetFile(a.data()); + auto file = BroFile::Get(a.data()); if ( file ) - return new Val({AdoptRef{}, file}); + return new Val(std::move(file)); return nullptr; } From 0f5bb4b83dbd921048b39305760dd8dbff70f6c0 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 17:45:39 -0700 Subject: [PATCH 069/151] Change {Get,Set}ContentsFile() to use IntrusivePtr --- src/analyzer/Analyzer.cc | 4 ++-- src/analyzer/Analyzer.h | 4 ++-- src/analyzer/protocol/tcp/TCP.cc | 4 ++-- src/analyzer/protocol/tcp/TCP.h | 4 ++-- src/analyzer/protocol/tcp/TCP_Endpoint.cc | 7 ++----- src/analyzer/protocol/tcp/TCP_Endpoint.h | 8 ++++---- src/analyzer/protocol/tcp/TCP_Reassembler.cc | 21 ++++++++------------ src/analyzer/protocol/tcp/TCP_Reassembler.h | 16 +++++++-------- src/analyzer/protocol/tcp/functions.bif | 4 ++-- 9 files changed, 31 insertions(+), 41 deletions(-) diff --git a/src/analyzer/Analyzer.cc b/src/analyzer/Analyzer.cc index 5b8cf67a08..d974a16188 100644 --- a/src/analyzer/Analyzer.cc +++ b/src/analyzer/Analyzer.cc @@ -912,12 +912,12 @@ void TransportLayerAnalyzer::Done() } void TransportLayerAnalyzer::SetContentsFile(unsigned int /* direction */, - BroFile* /* f */) + IntrusivePtr /* f */) { reporter->Error("analyzer type does not support writing to a contents file"); } -BroFile* TransportLayerAnalyzer::GetContentsFile(unsigned int /* direction */) const +IntrusivePtr TransportLayerAnalyzer::GetContentsFile(unsigned int /* direction */) const { reporter->Error("analyzer type does not support writing to a contents file"); return nullptr; diff --git a/src/analyzer/Analyzer.h b/src/analyzer/Analyzer.h index 859c5400e2..76ef088633 100644 --- a/src/analyzer/Analyzer.h +++ b/src/analyzer/Analyzer.h @@ -911,7 +911,7 @@ public: * @param f The file to record to. * */ - virtual void SetContentsFile(unsigned int direction, BroFile* f); + virtual void SetContentsFile(unsigned int direction, IntrusivePtr f); /** * Returns an associated contents file, if any. This must only be @@ -921,7 +921,7 @@ public: * @param direction One of the CONTENTS_* constants indicating which * direction the query is for. */ - virtual BroFile* GetContentsFile(unsigned int direction) const; + virtual IntrusivePtr GetContentsFile(unsigned int direction) const; /** * Associates a PIA with this analyzer. A PIA takes the diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index 3c30638692..9734ea30cb 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -1584,7 +1584,7 @@ void TCP_Analyzer::ConnDeleteTimer(double t) Conn()->DeleteTimer(t); } -void TCP_Analyzer::SetContentsFile(unsigned int direction, BroFile* f) +void TCP_Analyzer::SetContentsFile(unsigned int direction, IntrusivePtr f) { if ( direction == CONTENTS_NONE ) { @@ -1601,7 +1601,7 @@ void TCP_Analyzer::SetContentsFile(unsigned int direction, BroFile* f) } } -BroFile* TCP_Analyzer::GetContentsFile(unsigned int direction) const +IntrusivePtr TCP_Analyzer::GetContentsFile(unsigned int direction) const { switch ( direction ) { case CONTENTS_NONE: diff --git a/src/analyzer/protocol/tcp/TCP.h b/src/analyzer/protocol/tcp/TCP.h index f8b668b35a..2100eda181 100644 --- a/src/analyzer/protocol/tcp/TCP.h +++ b/src/analyzer/protocol/tcp/TCP.h @@ -60,8 +60,8 @@ public: // the test is whether it has any outstanding, un-acked data. bool DataPending(TCP_Endpoint* closing_endp); - void SetContentsFile(unsigned int direction, BroFile* f) override; - BroFile* GetContentsFile(unsigned int direction) const override; + void SetContentsFile(unsigned int direction, IntrusivePtr f) override; + IntrusivePtr GetContentsFile(unsigned int direction) const override; // From Analyzer.h void UpdateConnVal(RecordVal *conn_val) override; diff --git a/src/analyzer/protocol/tcp/TCP_Endpoint.cc b/src/analyzer/protocol/tcp/TCP_Endpoint.cc index a798c28fb2..272bc0b563 100644 --- a/src/analyzer/protocol/tcp/TCP_Endpoint.cc +++ b/src/analyzer/protocol/tcp/TCP_Endpoint.cc @@ -29,7 +29,6 @@ TCP_Endpoint::TCP_Endpoint(TCP_Analyzer* arg_analyzer, bool arg_is_orig) FIN_seq = 0; SYN_cnt = FIN_cnt = RST_cnt = 0; did_close = false; - contents_file = nullptr; tcp_analyzer = arg_analyzer; is_orig = arg_is_orig; @@ -53,7 +52,6 @@ TCP_Endpoint::TCP_Endpoint(TCP_Analyzer* arg_analyzer, bool arg_is_orig) TCP_Endpoint::~TCP_Endpoint() { delete contents_processor; - Unref(contents_file); } Connection* TCP_Endpoint::Conn() const @@ -254,10 +252,9 @@ void TCP_Endpoint::AckReceived(uint64_t seq) contents_processor->AckReceived(seq); } -void TCP_Endpoint::SetContentsFile(BroFile* f) +void TCP_Endpoint::SetContentsFile(IntrusivePtr f) { - Ref(f); - contents_file = f; + contents_file = std::move(f); contents_start_seq = ToRelativeSeqSpace(last_seq, seq_wraps); if ( contents_start_seq == 0 ) diff --git a/src/analyzer/protocol/tcp/TCP_Endpoint.h b/src/analyzer/protocol/tcp/TCP_Endpoint.h index e72016e4a2..9e90f0919d 100644 --- a/src/analyzer/protocol/tcp/TCP_Endpoint.h +++ b/src/analyzer/protocol/tcp/TCP_Endpoint.h @@ -3,8 +3,8 @@ #pragma once #include "IPAddr.h" +#include "File.h" -class BroFile; class Connection; class IP_Hdr; @@ -187,8 +187,8 @@ public: void AckReceived(uint64_t seq); - void SetContentsFile(BroFile* f); - BroFile* GetContentsFile() const { return contents_file; } + void SetContentsFile(IntrusivePtr f); + const IntrusivePtr& GetContentsFile() const { return contents_file; } // Codes used for tracking history. For responders, we shift these // over by 16 bits in order to fit both originator and responder @@ -211,7 +211,7 @@ public: TCP_Endpoint* peer; TCP_Reassembler* contents_processor; TCP_Analyzer* tcp_analyzer; - BroFile* contents_file; + IntrusivePtr contents_file; uint32_t checksum_base; double start_time, last_time; diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.cc b/src/analyzer/protocol/tcp/TCP_Reassembler.cc index 9ff61bf66a..5f70e02560 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.cc +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.cc @@ -30,7 +30,6 @@ TCP_Reassembler::TCP_Reassembler(analyzer::Analyzer* arg_dst_analyzer, type = arg_type; endp = arg_endp; had_gap = false; - record_contents_file = nullptr; deliver_tcp_contents = false; skip_deliveries = false; did_EOF = false; @@ -58,11 +57,6 @@ TCP_Reassembler::TCP_Reassembler(analyzer::Analyzer* arg_dst_analyzer, } } -TCP_Reassembler::~TCP_Reassembler() - { - Unref(record_contents_file); - } - void TCP_Reassembler::Done() { MatchUndelivered(-1, true); @@ -98,7 +92,7 @@ uint64_t TCP_Reassembler::NumUndeliveredBytes() const return last_block.upper - last_reassem_seq; } -void TCP_Reassembler::SetContentsFile(BroFile* f) +void TCP_Reassembler::SetContentsFile(IntrusivePtr f) { if ( ! f->IsOpen() ) { @@ -107,16 +101,17 @@ void TCP_Reassembler::SetContentsFile(BroFile* f) } if ( record_contents_file ) + { // We were already recording, no need to catch up. - Unref(record_contents_file); + record_contents_file = nullptr; + } else { if ( ! block_list.Empty() ) RecordToSeq(block_list.Begin()->second.seq, last_reassem_seq, f); } - Ref(f); - record_contents_file = f; + record_contents_file = std::move(f); } static inline bool is_clean(const TCP_Endpoint* a) @@ -322,7 +317,7 @@ void TCP_Reassembler::MatchUndelivered(uint64_t up_to_seq, bool use_last_upper) } } -void TCP_Reassembler::RecordToSeq(uint64_t start_seq, uint64_t stop_seq, BroFile* f) +void TCP_Reassembler::RecordToSeq(uint64_t start_seq, uint64_t stop_seq, const IntrusivePtr& f) { auto it = block_list.Begin(); @@ -353,7 +348,7 @@ void TCP_Reassembler::RecordToSeq(uint64_t start_seq, uint64_t stop_seq, BroFile RecordGap(last_seq, stop_seq, f); } -void TCP_Reassembler::RecordBlock(const DataBlock& b, BroFile* f) +void TCP_Reassembler::RecordBlock(const DataBlock& b, const IntrusivePtr& f) { if ( f->Write((const char*) b.block, b.Size()) ) return; @@ -368,7 +363,7 @@ void TCP_Reassembler::RecordBlock(const DataBlock& b, BroFile* f) ); } -void TCP_Reassembler::RecordGap(uint64_t start_seq, uint64_t upper_seq, BroFile* f) +void TCP_Reassembler::RecordGap(uint64_t start_seq, uint64_t upper_seq, const IntrusivePtr& f) { if ( f->Write(fmt("\n<>\n", upper_seq - start_seq)) ) return; diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.h b/src/analyzer/protocol/tcp/TCP_Reassembler.h index dffa55445a..1ff6b835d1 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.h +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.h @@ -3,8 +3,8 @@ #include "Reassem.h" #include "TCP_Endpoint.h" #include "TCP_Flags.h" +#include "File.h" -class BroFile; class Connection; namespace analyzer { @@ -25,8 +25,6 @@ public: TCP_Reassembler(Analyzer* arg_dst_analyzer, TCP_Analyzer* arg_tcp_analyzer, Type arg_type, TCP_Endpoint* arg_endp); - ~TCP_Reassembler() override; - void Done(); void SetDstAnalyzer(Analyzer* analyzer) { dst_analyzer = analyzer; } @@ -51,8 +49,8 @@ public: // from waiting_on_hole above; and is computed in a different fashion). uint64_t NumUndeliveredBytes() const; - void SetContentsFile(BroFile* f); - BroFile* GetContentsFile() const { return record_contents_file; } + void SetContentsFile(IntrusivePtr f); + const IntrusivePtr& GetContentsFile() const { return record_contents_file; } void MatchUndelivered(uint64_t up_to_seq, bool use_last_upper); @@ -91,9 +89,9 @@ private: void Undelivered(uint64_t up_to_seq) override; void Gap(uint64_t seq, uint64_t len); - void RecordToSeq(uint64_t start_seq, uint64_t stop_seq, BroFile* f); - void RecordBlock(const DataBlock& b, BroFile* f); - void RecordGap(uint64_t start_seq, uint64_t upper_seq, BroFile* f); + void RecordToSeq(uint64_t start_seq, uint64_t stop_seq, const IntrusivePtr& f); + void RecordBlock(const DataBlock& b, const IntrusivePtr& f); + void RecordGap(uint64_t start_seq, uint64_t upper_seq, const IntrusivePtr& f); void BlockInserted(DataBlockMap::const_iterator it) override; void Overlap(const u_char* b1, const u_char* b2, uint64_t n) override; @@ -110,7 +108,7 @@ private: bool in_delivery; analyzer::tcp::TCP_Flags flags; - BroFile* record_contents_file; // file on which to reassemble contents + IntrusivePtr record_contents_file; // file on which to reassemble contents Analyzer* dst_analyzer; TCP_Analyzer* tcp_analyzer; diff --git a/src/analyzer/protocol/tcp/functions.bif b/src/analyzer/protocol/tcp/functions.bif index 461f7a510e..043dbbdafa 100644 --- a/src/analyzer/protocol/tcp/functions.bif +++ b/src/analyzer/protocol/tcp/functions.bif @@ -101,7 +101,7 @@ function set_contents_file%(cid: conn_id, direction: count, f: file%): bool if ( ! c ) return val_mgr->False(); - c->GetRootAnalyzer()->SetContentsFile(direction, f); + c->GetRootAnalyzer()->SetContentsFile(direction, {NewRef{}, f}); return val_mgr->True(); %} @@ -127,7 +127,7 @@ function get_contents_file%(cid: conn_id, direction: count%): file auto cf = c->GetRootAnalyzer()->GetContentsFile(direction); if ( cf ) - return make_intrusive(IntrusivePtr{NewRef{}, cf}); + return make_intrusive(std::move(cf)); } // Return some sort of error value. From 688bed97bcc4f6cb4de844687fa447fb4a90efd6 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 18:21:06 -0700 Subject: [PATCH 070/151] Deprecate Func::FType(), replace with Func::GetType() --- src/Func.cc | 14 +++++++------- src/Func.h | 10 +++++++--- src/ID.h | 4 ++++ src/Val.cc | 6 +++--- src/broker/Manager.cc | 4 ++-- src/input/Manager.cc | 6 +++--- src/logging/Manager.cc | 14 +++++++------- src/option.bif | 2 +- src/zeek.bif | 5 +++-- 9 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/Func.cc b/src/Func.cc index 5d4da73ced..2ee53e465e 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -146,7 +146,7 @@ void Func::DescribeDebug(ODesc* d, const zeek::Args* args) const if ( args ) { d->Add("("); - RecordType* func_args = FType()->Args(); + RecordType* func_args = GetType()->Args(); auto num_fields = static_cast(func_args->NumFields()); for ( auto i = 0u; i < args->size(); ++i ) @@ -244,7 +244,7 @@ std::pair Func::HandlePluginResult(std::pair plugin_resu case FUNC_FLAVOR_FUNCTION: { - const auto& yt = FType()->Yield(); + const auto& yt = GetType()->Yield(); if ( (! yt) || yt->Tag() == TYPE_VOID ) { @@ -270,7 +270,7 @@ BroFunc::BroFunc(ID* arg_id, IntrusivePtr arg_body, id_list* aggr_inits, : Func(BRO_FUNC) { name = arg_id->Name(); - type = arg_id->GetType(); + type = arg_id->GetType(); frame_size = arg_frame_size; if ( arg_body ) @@ -345,7 +345,7 @@ IntrusivePtr BroFunc::Call(const zeek::Args& args, Frame* parent) const DescribeDebug(&d, &args); g_trace_state.LogTrace("%s called: %s\n", - FType()->FlavorString().c_str(), d.Description()); + GetType()->FlavorString().c_str(), d.Description()); } stmt_flow_type flow = FLOW_NEXT; @@ -422,7 +422,7 @@ IntrusivePtr BroFunc::Call(const zeek::Args& args, Frame* parent) const // Warn if the function returns something, but we returned from // the function without an explicit return, or without a value. - else if ( FType()->Yield() && FType()->Yield()->Tag() != TYPE_VOID && + else if ( GetType()->Yield() && GetType()->Yield()->Tag() != TYPE_VOID && (flow != FLOW_RETURN /* we fell off the end */ || ! result /* explicit return with no result */) && ! f->HasDelayed() ) @@ -448,7 +448,7 @@ void BroFunc::AddBody(IntrusivePtr new_body, id_list* new_inits, if ( new_frame_size > frame_size ) frame_size = new_frame_size; - auto num_args = FType()->Args()->NumFields(); + auto num_args = GetType()->Args()->NumFields(); if ( num_args > static_cast(frame_size) ) frame_size = num_args; @@ -592,7 +592,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, if ( id->HasVal() ) reporter->InternalError("built-in function %s multiply defined", Name()); - type = id->GetType(); + type = id->GetType(); id->SetVal(make_intrusive(IntrusivePtr{NewRef{}, this})); } diff --git a/src/Func.h b/src/Func.h index 9eaedd5ac8..6bec0d259c 100644 --- a/src/Func.h +++ b/src/Func.h @@ -37,7 +37,7 @@ public: ~Func() override; virtual bool IsPure() const = 0; - function_flavor Flavor() const { return FType()->Flavor(); } + function_flavor Flavor() const { return GetType()->Flavor(); } struct Body { IntrusivePtr stmts; @@ -78,7 +78,11 @@ public: virtual void SetScope(IntrusivePtr newscope); virtual Scope* GetScope() const { return scope.get(); } - virtual FuncType* FType() const { return type->AsFuncType(); } + [[deprecated("Remove in v4.1. Use GetType().")]] + virtual FuncType* FType() const { return type.get(); } + + const IntrusivePtr& GetType() const + { return type; } Kind GetKind() const { return kind; } @@ -112,7 +116,7 @@ protected: IntrusivePtr scope; Kind kind; uint32_t unique_id; - IntrusivePtr type; + IntrusivePtr type; std::string name; static inline std::vector> unique_ids; }; diff --git a/src/ID.h b/src/ID.h index 631bff4179..0cce2e4239 100644 --- a/src/ID.h +++ b/src/ID.h @@ -51,6 +51,10 @@ public: const IntrusivePtr& GetType() const { return type; } + template + IntrusivePtr GetType() const + { return cast_intrusive(type); } + [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] BroType* AsType() { return is_type ? GetType().get() : nullptr; } [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] diff --git a/src/Val.cc b/src/Val.cc index 53769963ca..533f433989 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -46,7 +46,7 @@ Val::Val(Func* f) : Val({NewRef{}, f}) {} Val::Val(IntrusivePtr f) - : val(f.release()), type({NewRef{}, val.func_val->FType()}) + : val(f.release()), type(val.func_val->GetType()) {} static const IntrusivePtr& GetStringFileType() noexcept @@ -269,7 +269,7 @@ IntrusivePtr Val::SizeVal() const case TYPE_INTERNAL_OTHER: if ( type->Tag() == TYPE_FUNC ) - return val_mgr->Count(val.func_val->FType()->ArgTypes()->Types().size()); + return val_mgr->Count(val.func_val->GetType()->ArgTypes()->Types().size()); if ( type->Tag() == TYPE_FILE ) return make_intrusive(val.file_val->Size(), TYPE_DOUBLE); @@ -2482,7 +2482,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) const Func* f = vf->AsFunc(); zeek::Args vl; - const auto& func_args = f->FType()->ArgTypes()->Types(); + const auto& func_args = f->GetType()->ArgTypes()->Types(); // backwards compatibility with idx: any idiom bool any_idiom = func_args.size() == 2 && func_args.back()->Tag() == TYPE_ANY; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 446ac93fd2..ab2851e4af 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -727,7 +727,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) return rval; } - auto num_args = func->FType()->Args()->NumFields(); + auto num_args = func->GetType()->Args()->NumFields(); if ( num_args != args->length() - 1 ) { @@ -741,7 +741,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) } const auto& got_type = (*args)[i]->GetType(); - const auto& expected_type = func->FType()->ArgTypes()->Types()[i - 1]; + const auto& expected_type = func->GetType()->ArgTypes()->Types()[i - 1]; if ( ! same_type(got_type.get(), expected_type.get()) ) { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 4b80d657a1..9fceb2ee67 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -326,7 +326,7 @@ bool Manager::CreateEventStream(RecordVal* fval) Func* event = fval->Lookup("ev", true)->AsFunc(); - FuncType* etype = event->FType()->AsFuncType(); + const auto& etype = event->GetType(); bool allow_file_func = false; @@ -556,7 +556,7 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( event ) { - FuncType* etype = event->FType()->AsFuncType(); + const auto& etype = event->GetType(); if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) { @@ -703,7 +703,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e if ( ev == nullptr ) return true; - FuncType* etype = ev->FType()->AsFuncType(); + const auto& etype = ev->GetType(); if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index cbaf7c53e7..935c76f77d 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -270,7 +270,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) if ( event ) { // Make sure the event is prototyped as expected. - FuncType* etype = event->FType()->AsFuncType(); + const auto& etype = event->GetType(); if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) { @@ -401,7 +401,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, if ( j < num_ext_fields ) { i = j; - rtype = filter->ext_func->FType()->Yield()->AsRecordType(); + rtype = filter->ext_func->GetType()->Yield()->AsRecordType(); } else { @@ -587,18 +587,18 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) filter->num_ext_fields = 0; if ( filter->ext_func ) { - if ( filter->ext_func->FType()->Yield()->Tag() == TYPE_RECORD ) + if ( filter->ext_func->GetType()->Yield()->Tag() == TYPE_RECORD ) { - filter->num_ext_fields = filter->ext_func->FType()->Yield()->AsRecordType()->NumFields(); + filter->num_ext_fields = filter->ext_func->GetType()->Yield()->AsRecordType()->NumFields(); } - else if ( filter->ext_func->FType()->Yield()->Tag() == TYPE_VOID ) + else if ( filter->ext_func->GetType()->Yield()->Tag() == TYPE_VOID ) { // This is a special marker for the default no-implementation // of the ext_func and we'll allow it to slide. } else { - reporter->Error("Return value of log_ext is not a record (got %s)", type_name(filter->ext_func->FType()->Yield()->Tag())); + reporter->Error("Return value of log_ext is not a record (got %s)", type_name(filter->ext_func->GetType()->Yield()->Tag())); delete filter; return false; } @@ -744,7 +744,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) path_arg = val_mgr->EmptyString(); IntrusivePtr rec_arg; - const auto& rt = filter->path_func->FType()->Args()->GetFieldType("rec"); + const auto& rt = filter->path_func->GetType()->Args()->GetFieldType("rec"); if ( rt->Tag() == TYPE_RECORD ) rec_arg = columns->CoerceTo(rt->AsRecordType(), true); diff --git a/src/option.bif b/src/option.bif index 352ffb9631..de9d2894c7 100644 --- a/src/option.bif +++ b/src/option.bif @@ -15,7 +15,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, const IntrusiveP { for ( auto handler_function : i->GetOptionHandlers() ) { - bool add_loc = handler_function->FType()->AsFuncType()->ArgTypes()->Types().size() == 3; + bool add_loc = handler_function->GetType()->ArgTypes()->Types().size() == 3; zeek::Args vl; vl.reserve(2 + add_loc); vl.emplace_back(NewRef{}, name); diff --git a/src/zeek.bif b/src/zeek.bif index 01d933dfcd..0af1ef72f3 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1435,7 +1435,8 @@ function sort%(v: any, ...%) : any if ( comp ) { - FuncType* comp_type = comp->FType()->AsFuncType(); + const auto& comp_type = comp->GetType(); + if ( comp_type->Yield()->Tag() != TYPE_INT || ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) { @@ -1516,7 +1517,7 @@ function order%(v: any, ...%) : index_vec if ( comp ) { - FuncType* comp_type = comp->FType()->AsFuncType(); + const auto& comp_type = comp->GetType()->AsFuncType(); if ( comp_type->Yield()->Tag() != TYPE_INT || ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) { From 6aa1d0468d7c33f68ad75180d00fd0f6e6f20451 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 18:25:45 -0700 Subject: [PATCH 071/151] Deprecate BroFile::FType(), replace with GetType() --- src/File.h | 4 ++++ src/Val.cc | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/File.h b/src/File.h index 212e301afb..edf0b7d0f4 100644 --- a/src/File.h +++ b/src/File.h @@ -37,8 +37,12 @@ public: void SetBuf(bool buffered); // false=line buffered, true=fully buffered + [[deprecated("Remove in v4.1. Use GetType().")]] BroType* FType() const { return t.get(); } + const IntrusivePtr& GetType() const + { return t; } + // Whether the file is open in a general sense; it might // not be open as a Unix file due to our management of // a finite number of FDs. diff --git a/src/Val.cc b/src/Val.cc index 533f433989..5c8265b405 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -63,7 +63,7 @@ Val::Val(BroFile* f) : Val({AdoptRef{}, f}) Val::Val(IntrusivePtr f) : val(f.release()), type(GetStringFileType()) { - assert(val.file_val->FType()->Tag() == TYPE_STRING); + assert(val.file_val->GetType()->Tag() == TYPE_STRING); } Val::~Val() From 938ad35a43f2719bf40e5dd9609049ed8719682a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 18:37:48 -0700 Subject: [PATCH 072/151] Deprecate EventHandler::FType(), replace with GetType() --- src/EventHandler.cc | 13 +++++++------ src/EventHandler.h | 11 ++++++++--- src/Expr.cc | 3 ++- src/broker/Manager.cc | 2 +- src/input/Manager.cc | 2 +- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 580d48be27..1f6172cbd8 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -15,7 +15,6 @@ EventHandler::EventHandler(std::string arg_name) name = std::move(arg_name); used = false; local = nullptr; - type = nullptr; error_handler = false; enabled = true; generate_always = false; @@ -33,8 +32,10 @@ EventHandler::operator bool() const || ! auto_publish.empty()); } -FuncType* EventHandler::FType(bool check_export) +const IntrusivePtr& EventHandler::GetType(bool check_export) { + static IntrusivePtr nil; + if ( type ) return type; @@ -42,12 +43,12 @@ FuncType* EventHandler::FType(bool check_export) check_export); if ( ! id ) - return nullptr; + return nil; if ( id->GetType()->Tag() != TYPE_FUNC ) - return nullptr; + return nil; - type = id->GetType()->AsFuncType(); + type = id->GetType(); return type; } @@ -126,7 +127,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) // new_event() is the one event we don't want to report. return; - RecordType* args = FType()->Args(); + RecordType* args = GetType()->Args(); static auto call_argument_vector = zeek::id::find_type("call_argument_vector"); auto vargs = make_intrusive(call_argument_vector); diff --git a/src/EventHandler.h b/src/EventHandler.h index 6844662b22..86d6defb4f 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -4,12 +4,12 @@ #include "BroList.h" #include "ZeekArgs.h" +#include "Type.h" #include #include class Func; -class FuncType; class EventHandler { public: @@ -18,7 +18,12 @@ public: const char* Name() { return name.data(); } Func* LocalHandler() { return local; } - FuncType* FType(bool check_export = true); + + const IntrusivePtr& GetType(bool check_export = true); + + [[deprecated("Remove in v4.1. Use GetType().")]] + FuncType* FType(bool check_export = true) + { return GetType().get(); } void SetLocalHandler(Func* f); @@ -57,7 +62,7 @@ private: std::string name; Func* local; - FuncType* type; + IntrusivePtr type; bool used; // this handler is indeed used somewhere bool enabled; bool error_handler; // this handler reports error messages. diff --git a/src/Expr.cc b/src/Expr.cc index 739a0e8b8b..afd9b7a695 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4313,7 +4313,8 @@ EventExpr::EventExpr(const char* arg_name, IntrusivePtr arg_args) return; } - FuncType* func_type = h->FType(); + const auto& func_type = h->GetType(); + if ( ! func_type ) { Error("not an event"); diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index ab2851e4af..de279a0b4b 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -977,7 +977,7 @@ void Manager::ProcessEvent(const broker::topic& topic, broker::zeek::Event ev) return; } - const auto& arg_types = handler->FType(false)->ArgTypes()->Types(); + const auto& arg_types = handler->GetType(false)->ArgTypes()->Types(); if ( arg_types.size() != args.size() ) { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 9fceb2ee67..efc9c48a36 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1810,7 +1810,7 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu name.c_str(), num_vals); #endif - RecordType *type = handler->FType()->Args(); + RecordType* type = handler->GetType()->Args(); int num_event_vals = type->NumFields(); if ( num_vals != num_event_vals ) { From 40153cc5cbb5e9f6144856019b394f377ea0f307 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 19:04:31 -0700 Subject: [PATCH 073/151] Deprecate FuncType::Args(), replace with Params() --- NEWS | 2 ++ src/EventHandler.cc | 2 +- src/Func.cc | 4 ++-- src/Type.cc | 3 ++- src/Type.h | 4 ++++ src/Val.cc | 2 +- src/Var.cc | 18 +++++++++--------- src/broker/Manager.cc | 2 +- src/input/Manager.cc | 2 +- src/logging/Manager.cc | 2 +- 10 files changed, 24 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 909d9356b2..cae8a619d7 100644 --- a/NEWS +++ b/NEWS @@ -187,6 +187,8 @@ Deprecated Functionality - Constructors for ``Val`` types that take a ``BroType*`` are all generally deprecated, with alternatives that instead take an ``IntrusivePtr`` argument. +- ``FuncType::Args()`` is deprecated, use ``FuncType::Params()``. + Zeek 3.1.0 ========== diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 1f6172cbd8..45014bc73b 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -127,7 +127,7 @@ void EventHandler::NewEvent(const zeek::Args& vl) // new_event() is the one event we don't want to report. return; - RecordType* args = GetType()->Args(); + const auto& args = GetType()->Params(); static auto call_argument_vector = zeek::id::find_type("call_argument_vector"); auto vargs = make_intrusive(call_argument_vector); diff --git a/src/Func.cc b/src/Func.cc index 2ee53e465e..3b1b5893fe 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -146,7 +146,7 @@ void Func::DescribeDebug(ODesc* d, const zeek::Args* args) const if ( args ) { d->Add("("); - RecordType* func_args = GetType()->Args(); + const auto& func_args = GetType()->Params(); auto num_fields = static_cast(func_args->NumFields()); for ( auto i = 0u; i < args->size(); ++i ) @@ -448,7 +448,7 @@ void BroFunc::AddBody(IntrusivePtr new_body, id_list* new_inits, if ( new_frame_size > frame_size ) frame_size = new_frame_size; - auto num_args = GetType()->Args()->NumFields(); + auto num_args = GetType()->Params()->NumFields(); if ( num_args > static_cast(frame_size) ) frame_size = num_args; diff --git a/src/Type.cc b/src/Type.cc index d5d17f7a3f..1fc09beb76 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1839,7 +1839,8 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) const FuncType* ft1 = (const FuncType*) t1; const FuncType* ft2 = (const FuncType*) t1; - auto args = cast_intrusive(merge_types(ft1->Args(), ft2->Args())); + auto args = cast_intrusive(merge_types(ft1->Params().get(), + ft2->Params().get())); auto yield = t1->Yield() ? merge_types(t1->Yield().get(), t2->Yield().get()) : nullptr; diff --git a/src/Type.h b/src/Type.h index ac537577e3..9ecedc0471 100644 --- a/src/Type.h +++ b/src/Type.h @@ -473,8 +473,12 @@ public: ~FuncType() override; + [[deprecated("Remove in v4.1. Use Params().")]] RecordType* Args() const { return args.get(); } + const IntrusivePtr& Params() const + { return args; } + const IntrusivePtr& Yield() const override { return yield; } diff --git a/src/Val.cc b/src/Val.cc index 5c8265b405..4d4c6b8e51 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1360,7 +1360,7 @@ static void find_nested_record_types(BroType* t, std::set* found) } return; case TYPE_FUNC: - find_nested_record_types(t->AsFuncType()->Args(), found); + find_nested_record_types(t->AsFuncType()->Params().get(), found); find_nested_record_types(t->AsFuncType()->Yield().get(), found); return; case TYPE_VECTOR: diff --git a/src/Var.cc b/src/Var.cc index a5d64a65d5..33895f5def 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -63,8 +63,8 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs, return false; } - auto canon_args = canon_ft->Args(); - auto alt_args = alt_ft->Args(); + const auto& canon_args = canon_ft->Params(); + const auto& alt_args = alt_ft->Params(); if ( auto p = canon_ft->FindPrototype(*alt_args); p ) { @@ -102,7 +102,7 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs, if ( a->Tag() == ATTR_DEPRECATED ) deprecated = true; - FuncType::Prototype p{deprecated, {NewRef{}, alt_args}, std::move(offsets)}; + FuncType::Prototype p{deprecated, alt_args, std::move(offsets)}; canon_ft->AddPrototype(std::move(p)); return true; } @@ -437,13 +437,13 @@ static std::optional func_type_check(const FuncType* decl, return {}; } - return decl->FindPrototype(*impl->Args()); + return decl->FindPrototype(*impl->Params()); } static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl) { - auto canon_args = decl->Args(); - auto impl_args = impl->Args(); + const auto& canon_args = decl->Params(); + const auto& impl_args = impl->Params(); if ( canon_args->NumFields() != impl_args->NumFields() ) return false; @@ -483,14 +483,14 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, // params, automatically transfer any that are missing // (convenience so that implementations don't need to specify // the &default expression again). - transfer_arg_defaults(prototype->args.get(), t->Args()); + transfer_arg_defaults(prototype->args.get(), t->Params().get()); } else { // Warn for trying to use &default parameters in hook/event // handler body when it already has a declaration since only // &default in the declaration has any effect. - auto args = t->Args(); + const auto& args = t->Params(); for ( int i = 0; i < args->NumFields(); ++i ) { @@ -555,7 +555,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, push_scope({NewRef{}, id}, attrs); - RecordType* args = t->Args(); + const auto& args = t->Params(); int num_args = args->NumFields(); for ( int i = 0; i < num_args; ++i ) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index de279a0b4b..c441f69900 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -727,7 +727,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) return rval; } - auto num_args = func->GetType()->Args()->NumFields(); + auto num_args = func->GetType()->Params()->NumFields(); if ( num_args != args->length() - 1 ) { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index efc9c48a36..be2832acc3 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1810,7 +1810,7 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu name.c_str(), num_vals); #endif - RecordType* type = handler->GetType()->Args(); + const auto& type = handler->GetType()->Params(); int num_event_vals = type->NumFields(); if ( num_vals != num_event_vals ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 935c76f77d..7bb597309b 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -744,7 +744,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) path_arg = val_mgr->EmptyString(); IntrusivePtr rec_arg; - const auto& rt = filter->path_func->GetType()->Args()->GetFieldType("rec"); + const auto& rt = filter->path_func->GetType()->Params()->GetFieldType("rec"); if ( rt->Tag() == TYPE_RECORD ) rec_arg = columns->CoerceTo(rt->AsRecordType(), true); From 83f1a911d72676f3419c85753fdcf341a05e0bae Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 15 May 2020 19:15:24 -0700 Subject: [PATCH 074/151] Deprecate FuncType::ArgTypes(), replace with ParamList() --- NEWS | 2 ++ src/Attr.cc | 4 ++-- src/Type.cc | 2 +- src/Type.h | 4 ++++ src/Val.cc | 4 ++-- src/broker/Manager.cc | 4 ++-- src/input/Manager.cc | 6 +++--- src/logging/Manager.cc | 2 +- src/option.bif | 4 ++-- src/zeek.bif | 4 ++-- 10 files changed, 21 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index cae8a619d7..af3d71bdc2 100644 --- a/NEWS +++ b/NEWS @@ -189,6 +189,8 @@ Deprecated Functionality - ``FuncType::Args()`` is deprecated, use ``FuncType::Params()``. +- ``FuncType::ArgTypes()`` is deprecated, use ``FuncType::ParamList()``. + Zeek 3.1.0 ========== diff --git a/src/Attr.cc b/src/Attr.cc index d26fa443b5..251b1c595c 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -464,7 +464,7 @@ void Attributes::CheckAttr(Attr* a) if (the_table->IsUnspecifiedTable()) break; - const auto& func_index_types = e_ft->ArgTypes()->Types(); + const auto& func_index_types = e_ft->ParamList()->Types(); // Keep backwards compatibility with idx: any idiom. if ( func_index_types.size() == 2 ) { @@ -511,7 +511,7 @@ void Attributes::CheckAttr(Attr* a) if ( the_table->IsUnspecifiedTable() ) break; - const auto& args = c_ft->ArgTypes()->Types(); + const auto& args = c_ft->ParamList()->Types(); const auto& t_indexes = the_table->IndexTypes(); if ( args.size() != ( type->IsSet() ? 2 : 3 ) + t_indexes.size() ) { diff --git a/src/Type.cc b/src/Type.cc index 1fc09beb76..671a98d8e6 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1513,7 +1513,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re return false; } - return ft1->CheckArgs(ft2->ArgTypes()->Types(), is_init); + return ft1->CheckArgs(ft2->ParamList()->Types(), is_init); } case TYPE_RECORD: diff --git a/src/Type.h b/src/Type.h index 9ecedc0471..1bb81822d5 100644 --- a/src/Type.h +++ b/src/Type.h @@ -495,8 +495,12 @@ public: bool CheckArgs(const std::vector>& args, bool is_init = false) const; + [[deprecated("Remove in v4.1. Use ParamList().")]] TypeList* ArgTypes() const { return arg_types.get(); } + const IntrusivePtr& ParamList() const + { return arg_types; } + void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool roles_only = false) const override; diff --git a/src/Val.cc b/src/Val.cc index 4d4c6b8e51..a383086269 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -269,7 +269,7 @@ IntrusivePtr Val::SizeVal() const case TYPE_INTERNAL_OTHER: if ( type->Tag() == TYPE_FUNC ) - return val_mgr->Count(val.func_val->GetType()->ArgTypes()->Types().size()); + return val_mgr->Count(val.func_val->GetType()->ParamList()->Types().size()); if ( type->Tag() == TYPE_FILE ) return make_intrusive(val.file_val->Size(), TYPE_DOUBLE); @@ -2482,7 +2482,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) const Func* f = vf->AsFunc(); zeek::Args vl; - const auto& func_args = f->GetType()->ArgTypes()->Types(); + const auto& func_args = f->GetType()->ParamList()->Types(); // backwards compatibility with idx: any idiom bool any_idiom = func_args.size() == 2 && func_args.back()->Tag() == TYPE_ANY; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index c441f69900..fb83682e86 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -741,7 +741,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) } const auto& got_type = (*args)[i]->GetType(); - const auto& expected_type = func->GetType()->ArgTypes()->Types()[i - 1]; + const auto& expected_type = func->GetType()->ParamList()->Types()[i - 1]; if ( ! same_type(got_type.get(), expected_type.get()) ) { @@ -977,7 +977,7 @@ void Manager::ProcessEvent(const broker::topic& topic, broker::zeek::Event ev) return; } - const auto& arg_types = handler->GetType(false)->ArgTypes()->Types(); + const auto& arg_types = handler->GetType(false)->ParamList()->Types(); if ( arg_types.size() != args.size() ) { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index be2832acc3..1e8c9eba06 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -336,7 +336,7 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - const auto& args = etype->ArgTypes()->Types(); + const auto& args = etype->ParamList()->Types(); if ( args.size() < 2 ) { @@ -564,7 +564,7 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - const auto& args = etype->ArgTypes()->Types(); + const auto& args = etype->ParamList()->Types(); if ( args.size() != 4 ) { @@ -711,7 +711,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - const auto& args = etype->ArgTypes()->Types(); + const auto& args = etype->ParamList()->Types(); if ( args.size() != 3 ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 7bb597309b..f1643eea8b 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -278,7 +278,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) return false; } - const auto& args = etype->ArgTypes()->Types(); + const auto& args = etype->ParamList()->Types(); if ( args.size() != 1 ) { diff --git a/src/option.bif b/src/option.bif index de9d2894c7..84e3798744 100644 --- a/src/option.bif +++ b/src/option.bif @@ -15,7 +15,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, const IntrusiveP { for ( auto handler_function : i->GetOptionHandlers() ) { - bool add_loc = handler_function->GetType()->ArgTypes()->Types().size() == 3; + bool add_loc = handler_function->GetType()->ParamList()->Types().size() == 3; zeek::Args vl; vl.reserve(2 + add_loc); vl.emplace_back(NewRef{}, name); @@ -170,7 +170,7 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - const auto& args = on_change->GetType()->AsFuncType()->ArgTypes()->Types(); + const auto& args = on_change->GetType()->AsFuncType()->ParamList()->Types(); if ( args.size() < 2 || args.size() > 3 ) { builtin_error(fmt("Wrong number of arguments for passed function in Option::on_change for ID '%s'; expected 2 or 3, got %zu", diff --git a/src/zeek.bif b/src/zeek.bif index 0af1ef72f3..685e3e4fdf 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1438,7 +1438,7 @@ function sort%(v: any, ...%) : any const auto& comp_type = comp->GetType(); if ( comp_type->Yield()->Tag() != TYPE_INT || - ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) + ! comp_type->ParamList()->AllMatch(elt_type, 0) ) { builtin_error("invalid comparison function in call to sort()"); return rval; @@ -1519,7 +1519,7 @@ function order%(v: any, ...%) : index_vec { const auto& comp_type = comp->GetType()->AsFuncType(); if ( comp_type->Yield()->Tag() != TYPE_INT || - ! comp_type->ArgTypes()->AllMatch(elt_type, 0) ) + ! comp_type->ParamList()->AllMatch(elt_type, 0) ) { builtin_error("invalid comparison function in call to order()"); return IntrusivePtr{NewRef{}, v}; From 43f513ca445143262b87eeb6fdb6df8bafd9d385 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 18 May 2020 15:25:46 -0700 Subject: [PATCH 075/151] Switch OpaqueVal::UnserializeType() to return IntrusivePtr --- src/OpaqueVal.cc | 16 +++++++++------- src/OpaqueVal.h | 2 +- src/probabilistic/Topk.cc | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 703efba33b..e3e6d2a4fc 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -112,7 +112,7 @@ broker::expected OpaqueVal::SerializeType(BroType* t) return {broker::vector{false, static_cast(t->Tag())}}; } -BroType* OpaqueVal::UnserializeType(const broker::data& data) +IntrusivePtr OpaqueVal::UnserializeType(const broker::data& data) { auto v = caf::get_if(&data); if ( ! (v && v->size() == 2) ) @@ -135,14 +135,14 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data) if ( ! id->IsType() ) return nullptr; - return id->GetType()->Ref(); + return id->GetType(); } auto tag = caf::get_if(&(*v)[1]); if ( ! tag ) return nullptr; - return base_type(static_cast(*tag))->Ref(); + return base_type(static_cast(*tag)); } IntrusivePtr OpaqueVal::DoClone(CloneState* state) @@ -854,8 +854,9 @@ bool BloomFilterVal::DoUnserialize(const broker::data& data) auto no_type = caf::get_if(&(*v)[0]); if ( ! no_type ) { - BroType* t = UnserializeType((*v)[0]); - if ( ! (t && Typify(t)) ) + auto t = UnserializeType((*v)[0]); + + if ( ! (t && Typify(t.get())) ) return false; } @@ -957,8 +958,9 @@ bool CardinalityVal::DoUnserialize(const broker::data& data) auto no_type = caf::get_if(&(*v)[0]); if ( ! no_type ) { - BroType* t = UnserializeType((*v)[0]); - if ( ! (t && Typify(t)) ) + auto t = UnserializeType((*v)[0]); + + if ( ! (t && Typify(t.get())) ) return false; } diff --git a/src/OpaqueVal.h b/src/OpaqueVal.h index 6071dbf951..153fc36ee0 100644 --- a/src/OpaqueVal.h +++ b/src/OpaqueVal.h @@ -154,7 +154,7 @@ protected: * Helper function for derived class that need to restore a type * during unserialization. Returns the type at reference count +1. */ - static BroType* UnserializeType(const broker::data& data); + static IntrusivePtr UnserializeType(const broker::data& data); }; namespace probabilistic { diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 841fc771c8..137af7a50a 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -479,12 +479,12 @@ bool TopkVal::DoUnserialize(const broker::data& data) auto no_type = caf::get_if(&(*v)[3]); if ( ! no_type ) { - BroType* t = UnserializeType((*v)[3]); + auto t = UnserializeType((*v)[3]); + if ( ! t ) return false; - Typify(t); - Unref(t); + Typify(t.get()); } uint64_t i = 0; From d35e5520f8675e06a4ccd03bfe5cd57f883a1cd2 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 18 May 2020 15:37:00 -0700 Subject: [PATCH 076/151] Switch TopkVal to store IntrusivePtr --- src/probabilistic/Topk.cc | 27 ++++++++++++--------------- src/probabilistic/Topk.h | 4 ++-- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 137af7a50a..13c5c9adc8 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -23,12 +23,12 @@ Element::~Element() Unref(value); } -void TopkVal::Typify(BroType* t) +void TopkVal::Typify(IntrusivePtr t) { assert(!hash && !type); - type = t->Ref(); - auto tl = make_intrusive(IntrusivePtr{NewRef{}, t}); - tl->Append({NewRef{}, t}); + type = std::move(t); + auto tl = make_intrusive(type); + tl->Append(type); hash = new CompositeHash(std::move(tl)); } @@ -44,7 +44,6 @@ TopkVal::TopkVal(uint64_t arg_size) : OpaqueVal(topk_type) elementDict = new PDict; elementDict->SetDeleteFunc(topk_element_hash_delete_func); size = arg_size; - type = nullptr; numElements = 0; pruned = false; hash = nullptr; @@ -55,7 +54,6 @@ TopkVal::TopkVal() : OpaqueVal(topk_type) elementDict = new PDict; elementDict->SetDeleteFunc(topk_element_hash_delete_func); size = 0; - type = nullptr; numElements = 0; hash = nullptr; } @@ -73,7 +71,6 @@ TopkVal::~TopkVal() bi++; } - Unref(type); delete hash; } @@ -94,7 +91,7 @@ void TopkVal::Merge(const TopkVal* value, bool doPrune) else { - if ( ! same_type(type, value->type) ) + if ( ! same_type(type.get(), value->type.get()) ) { reporter->Error("Cannot merge top-k elements of differing types."); return; @@ -199,8 +196,8 @@ VectorVal* TopkVal::GetTopK(int k) const // returns vector return nullptr; } - auto vector_index = make_intrusive(IntrusivePtr{NewRef{}, type}); - vector_index->Append({NewRef{}, type}); + auto vector_index = make_intrusive(type); + vector_index->Append(type); auto v = make_intrusive(std::move(vector_index)); auto t = make_intrusive(std::move(v)); @@ -284,9 +281,9 @@ void TopkVal::Encountered(Val* encountered) // ok, let's see if we already know this one. if ( numElements == 0 ) - Typify(encountered->GetType().get()); + Typify(encountered->GetType()); else - if ( ! same_type(type, encountered->GetType().get()) ) + if ( ! same_type(type.get(), encountered->GetType().get()) ) { reporter->Error("Trying to add element to topk with differing type from other elements"); return; @@ -416,7 +413,7 @@ broker::expected TopkVal::DoSerialize() const if ( type ) { - auto t = SerializeType(type); + auto t = SerializeType(type.get()); if ( ! t ) return broker::ec::invalid_data; @@ -484,7 +481,7 @@ bool TopkVal::DoUnserialize(const broker::data& data) if ( ! t ) return false; - Typify(t.get()); + Typify(t); } uint64_t i = 0; @@ -505,7 +502,7 @@ bool TopkVal::DoUnserialize(const broker::data& data) for ( uint64_t j = 0; j < *elements_count; j++ ) { auto epsilon = caf::get_if(&(*v)[idx++]); - auto val = bro_broker::data_to_val((*v)[idx++], type); + auto val = bro_broker::data_to_val((*v)[idx++], type.get()); if ( ! (epsilon && val) ) return false; diff --git a/src/probabilistic/Topk.h b/src/probabilistic/Topk.h index 4a2c60e8b7..e6e162f2d6 100644 --- a/src/probabilistic/Topk.h +++ b/src/probabilistic/Topk.h @@ -161,9 +161,9 @@ private: * * @param t type that is tracked */ - void Typify(BroType* t); + void Typify(IntrusivePtr t); - BroType* type; + IntrusivePtr type; CompositeHash* hash; std::list buckets; PDict* elementDict; From aa9d9c904fa1af40a843aeca701326354cb7523a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 18 May 2020 15:55:30 -0700 Subject: [PATCH 077/151] Switch some TopkVal methods to use IntrusivePtr --- src/probabilistic/Topk.cc | 19 +++++++------------ src/probabilistic/Topk.h | 10 +++++----- src/probabilistic/top-k.bif | 4 ++-- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 13c5c9adc8..33857416f4 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -18,11 +18,6 @@ static void topk_element_hash_delete_func(void* val) delete e; } -Element::~Element() - { - Unref(value); - } - void TopkVal::Typify(IntrusivePtr t) { assert(!hash && !type); @@ -116,7 +111,7 @@ void TopkVal::Merge(const TopkVal* value, bool doPrune) { olde = new Element(); olde->epsilon = 0; - olde->value = e->value->Ref(); + olde->value = e->value; // insert at bucket position 0 if ( buckets.size() > 0 ) { @@ -188,7 +183,7 @@ IntrusivePtr TopkVal::DoClone(CloneState* state) return state->NewClone(this, std::move(clone)); } -VectorVal* TopkVal::GetTopK(int k) const // returns vector +IntrusivePtr TopkVal::GetTopK(int k) const // returns vector { if ( numElements == 0 ) { @@ -225,7 +220,7 @@ VectorVal* TopkVal::GetTopK(int k) const // returns vector it--; } - return t.release(); + return t; } uint64_t TopkVal::GetCount(Val* value) const @@ -276,7 +271,7 @@ uint64_t TopkVal::GetSum() const return sum; } -void TopkVal::Encountered(Val* encountered) +void TopkVal::Encountered(IntrusivePtr encountered) { // ok, let's see if we already know this one. @@ -297,7 +292,7 @@ void TopkVal::Encountered(Val* encountered) { e = new Element(); e->epsilon = 0; - e->value = encountered->Ref(); // or no ref? + e->value = std::move(encountered); // well, we do not know this one yet... if ( numElements < size ) @@ -437,7 +432,7 @@ broker::expected TopkVal::DoSerialize() const { Element* element = *eit; d.emplace_back(element->epsilon); - auto v = bro_broker::val_to_data(element->value); + auto v = bro_broker::val_to_data(element->value.get()); if ( ! v ) return broker::ec::invalid_data; @@ -509,7 +504,7 @@ bool TopkVal::DoUnserialize(const broker::data& data) Element* e = new Element(); e->epsilon = *epsilon; - e->value = val.release(); + e->value = std::move(val); e->parent = b; b->elements.insert(b->elements.end(), e); diff --git a/src/probabilistic/Topk.h b/src/probabilistic/Topk.h index e6e162f2d6..c71dbfe769 100644 --- a/src/probabilistic/Topk.h +++ b/src/probabilistic/Topk.h @@ -27,10 +27,8 @@ struct Bucket { struct Element { uint64_t epsilon; - Val* value; + IntrusivePtr value; Bucket* parent; - - ~Element(); }; class TopkVal : public OpaqueVal { @@ -57,7 +55,7 @@ public: * * @param value The encountered element */ - void Encountered(Val* value); + void Encountered(IntrusivePtr value); /** * Get the first *k* elements of the result vector. At the moment, @@ -68,7 +66,7 @@ public: * * @returns The top-k encountered elements */ - VectorVal* GetTopK(int k) const; + IntrusivePtr GetTopK(int k) const; /** * Get the current count tracked in the top-k data structure for a @@ -155,6 +153,8 @@ private: * @returns HashKey for value */ HashKey* GetHash(Val* v) const; // this probably should go somewhere else. + HashKey* GetHash(const IntrusivePtr& v) const + { return GetHash(v.get()); } /** * Set the type that this TopK instance tracks diff --git a/src/probabilistic/top-k.bif b/src/probabilistic/top-k.bif index d771df332f..947b514c08 100644 --- a/src/probabilistic/top-k.bif +++ b/src/probabilistic/top-k.bif @@ -34,7 +34,7 @@ function topk_add%(handle: opaque of topk, value: any%): any %{ assert(handle); probabilistic::TopkVal* h = (probabilistic::TopkVal*) handle; - h->Encountered(value); + h->Encountered({NewRef{}, value}); return nullptr; %} @@ -53,7 +53,7 @@ function topk_get_top%(handle: opaque of topk, k: count%): any_vec %{ assert(handle); probabilistic::TopkVal* h = (probabilistic::TopkVal*) handle; - return IntrusivePtr{AdoptRef{}, h->GetTopK(k)}; + return h->GetTopK(k); %} ## Get an overestimated count of how often a value has been encountered. From 377c8a47620f7d7694876ec05d29030614cfc0af Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 18 May 2020 16:07:26 -0700 Subject: [PATCH 078/151] Switch BlommFilterVal/CardinalityVal to use IntrusivePtr --- src/OpaqueVal.cc | 44 +++++++---------------- src/OpaqueVal.h | 16 +++++---- src/probabilistic/bloom-filter.bif | 8 ++--- src/probabilistic/cardinality-counter.bif | 10 +++--- 4 files changed, 32 insertions(+), 46 deletions(-) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index e3e6d2a4fc..9fb4d6d744 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -700,7 +700,6 @@ bool EntropyVal::DoUnserialize(const broker::data& data) BloomFilterVal::BloomFilterVal() : OpaqueVal(bloomfilter_type) { - type = nullptr; hash = nullptr; bloom_filter = nullptr; } @@ -708,7 +707,6 @@ BloomFilterVal::BloomFilterVal() BloomFilterVal::BloomFilterVal(probabilistic::BloomFilter* bf) : OpaqueVal(bloomfilter_type) { - type = nullptr; hash = nullptr; bloom_filter = bf; } @@ -725,26 +723,20 @@ IntrusivePtr BloomFilterVal::DoClone(CloneState* state) return state->NewClone(this, make_intrusive()); } -bool BloomFilterVal::Typify(BroType* arg_type) +bool BloomFilterVal::Typify(IntrusivePtr arg_type) { if ( type ) return false; - type = arg_type; - type->Ref(); + type = std::move(arg_type); - auto tl = make_intrusive(IntrusivePtr{NewRef{}, type}); - tl->Append({NewRef{}, type}); + auto tl = make_intrusive(type); + tl->Append(type); hash = new CompositeHash(std::move(tl)); return true; } -BroType* BloomFilterVal::Type() const - { - return type; - } - void BloomFilterVal::Add(const Val* val) { HashKey* key = hash->ComputeHash(val, true); @@ -780,7 +772,7 @@ IntrusivePtr BloomFilterVal::Merge(const BloomFilterVal* x, { if ( x->Type() && // any one 0 is ok here y->Type() && - ! same_type(x->Type(), y->Type()) ) + ! same_type(x->Type().get(), y->Type().get()) ) { reporter->Error("cannot merge Bloom filters with different types"); return nullptr; @@ -814,7 +806,6 @@ IntrusivePtr BloomFilterVal::Merge(const BloomFilterVal* x, BloomFilterVal::~BloomFilterVal() { - Unref(type); delete hash; delete bloom_filter; } @@ -827,7 +818,7 @@ broker::expected BloomFilterVal::DoSerialize() const if ( type ) { - auto t = SerializeType(type); + auto t = SerializeType(type.get()); if ( ! t ) return broker::ec::invalid_data; @@ -856,7 +847,7 @@ bool BloomFilterVal::DoUnserialize(const broker::data& data) { auto t = UnserializeType((*v)[0]); - if ( ! (t && Typify(t.get())) ) + if ( ! (t && Typify(std::move(t))) ) return false; } @@ -871,7 +862,6 @@ bool BloomFilterVal::DoUnserialize(const broker::data& data) CardinalityVal::CardinalityVal() : OpaqueVal(cardinality_type) { c = nullptr; - type = nullptr; hash = nullptr; } @@ -879,13 +869,11 @@ CardinalityVal::CardinalityVal(probabilistic::CardinalityCounter* arg_c) : OpaqueVal(cardinality_type) { c = arg_c; - type = nullptr; hash = nullptr; } CardinalityVal::~CardinalityVal() { - Unref(type); delete c; delete hash; } @@ -896,26 +884,20 @@ IntrusivePtr CardinalityVal::DoClone(CloneState* state) make_intrusive(new probabilistic::CardinalityCounter(*c))); } -bool CardinalityVal::Typify(BroType* arg_type) +bool CardinalityVal::Typify(IntrusivePtr arg_type) { if ( type ) return false; - type = arg_type; - type->Ref(); + type = std::move(arg_type); - auto tl = make_intrusive(IntrusivePtr{NewRef{}, type}); - tl->Append({NewRef{}, type}); + auto tl = make_intrusive(type); + tl->Append(type); hash = new CompositeHash(std::move(tl)); return true; } -BroType* CardinalityVal::Type() const - { - return type; - } - void CardinalityVal::Add(const Val* val) { HashKey* key = hash->ComputeHash(val, true); @@ -931,7 +913,7 @@ broker::expected CardinalityVal::DoSerialize() const if ( type ) { - auto t = SerializeType(type); + auto t = SerializeType(type.get()); if ( ! t ) return broker::ec::invalid_data; @@ -960,7 +942,7 @@ bool CardinalityVal::DoUnserialize(const broker::data& data) { auto t = UnserializeType((*v)[0]); - if ( ! (t && Typify(t.get())) ) + if ( ! (t && Typify(std::move(t))) ) return false; } diff --git a/src/OpaqueVal.h b/src/OpaqueVal.h index 153fc36ee0..bcbe5f61c9 100644 --- a/src/OpaqueVal.h +++ b/src/OpaqueVal.h @@ -304,8 +304,10 @@ public: IntrusivePtr DoClone(CloneState* state) override; - BroType* Type() const; - bool Typify(BroType* type); + const IntrusivePtr& Type() const + { return type; } + + bool Typify(IntrusivePtr type); void Add(const Val* val); size_t Count(const Val* val) const; @@ -326,7 +328,7 @@ private: BloomFilterVal(const BloomFilterVal&); BloomFilterVal& operator=(const BloomFilterVal&); - BroType* type; + IntrusivePtr type; CompositeHash* hash; probabilistic::BloomFilter* bloom_filter; }; @@ -341,8 +343,10 @@ public: void Add(const Val* val); - BroType* Type() const; - bool Typify(BroType* type); + const IntrusivePtr& Type() const + { return type; } + + bool Typify(IntrusivePtr type); probabilistic::CardinalityCounter* Get() { return c; }; @@ -351,7 +355,7 @@ protected: DECLARE_OPAQUE_VALUE(CardinalityVal) private: - BroType* type; + IntrusivePtr type; CompositeHash* hash; probabilistic::CardinalityCounter* c; }; diff --git a/src/probabilistic/bloom-filter.bif b/src/probabilistic/bloom-filter.bif index ae88af31c4..21425cd10d 100644 --- a/src/probabilistic/bloom-filter.bif +++ b/src/probabilistic/bloom-filter.bif @@ -146,10 +146,10 @@ function bloomfilter_add%(bf: opaque of bloomfilter, x: any%): any %{ BloomFilterVal* bfv = static_cast(bf); - if ( ! bfv->Type() && ! bfv->Typify(x->GetType().get()) ) + if ( ! bfv->Type() && ! bfv->Typify(x->GetType()) ) reporter->Error("failed to set Bloom filter type"); - else if ( ! same_type(bfv->Type(), x->GetType().get()) ) + else if ( ! same_type(bfv->Type().get(), x->GetType().get()) ) reporter->Error("incompatible Bloom filter types"); else @@ -176,7 +176,7 @@ function bloomfilter_lookup%(bf: opaque of bloomfilter, x: any%): count if ( ! bfv->Type() ) return val_mgr->Count(0); - else if ( ! same_type(bfv->Type(), x->GetType().get()) ) + else if ( ! same_type(bfv->Type().get(), x->GetType().get()) ) reporter->Error("incompatible Bloom filter types"); else @@ -227,7 +227,7 @@ function bloomfilter_merge%(bf1: opaque of bloomfilter, if ( bfv1->Type() && // any one 0 is ok here bfv2->Type() && - ! same_type(bfv1->Type(), bfv2->Type()) ) + ! same_type(bfv1->Type().get(), bfv2->Type().get()) ) { reporter->Error("incompatible Bloom filter types"); return nullptr; diff --git a/src/probabilistic/cardinality-counter.bif b/src/probabilistic/cardinality-counter.bif index a8a6581a7e..45e8ebbe59 100644 --- a/src/probabilistic/cardinality-counter.bif +++ b/src/probabilistic/cardinality-counter.bif @@ -42,13 +42,13 @@ function hll_cardinality_add%(handle: opaque of cardinality, elem: any%): bool %{ CardinalityVal* cv = static_cast(handle); - if ( ! cv->Type() && ! cv->Typify(elem->GetType().get()) ) + if ( ! cv->Type() && ! cv->Typify(elem->GetType()) ) { reporter->Error("failed to set HLL type"); return val_mgr->False(); } - else if ( ! same_type(cv->Type(), elem->GetType().get()) ) + else if ( ! same_type(cv->Type().get(), elem->GetType().get()) ) { reporter->Error("incompatible HLL data type"); return val_mgr->False(); @@ -77,9 +77,9 @@ function hll_cardinality_merge_into%(handle1: opaque of cardinality, handle2: op CardinalityVal* v2 = static_cast(handle2); if ( (v1->Type() != v2->Type()) && // both 0 is ok - (v1->Type() != 0) && // any one 0 also is ok - (v2->Type() != 0) && - ! same_type(v1->Type(), v2->Type()) ) + (v1->Type() != nullptr) && // any one 0 also is ok + (v2->Type() != nullptr) && + ! same_type(v1->Type().get(), v2->Type().get()) ) { reporter->Error("incompatible HLL types"); return val_mgr->False(); From 5742810293141bcf5e3fa7fc3a75ca45b134980c Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 18 May 2020 16:10:10 -0700 Subject: [PATCH 079/151] Switch OpaqueVal::SerializeType() to IntrusivePtr --- src/OpaqueVal.cc | 6 +++--- src/OpaqueVal.h | 2 +- src/probabilistic/Topk.cc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 9fb4d6d744..5c822f7fe5 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -96,7 +96,7 @@ IntrusivePtr OpaqueVal::Unserialize(const broker::data& data) return val; } -broker::expected OpaqueVal::SerializeType(BroType* t) +broker::expected OpaqueVal::SerializeType(const IntrusivePtr& t) { if ( t->InternalType() == TYPE_INTERNAL_ERROR ) return broker::ec::invalid_data; @@ -818,7 +818,7 @@ broker::expected BloomFilterVal::DoSerialize() const if ( type ) { - auto t = SerializeType(type.get()); + auto t = SerializeType(type); if ( ! t ) return broker::ec::invalid_data; @@ -913,7 +913,7 @@ broker::expected CardinalityVal::DoSerialize() const if ( type ) { - auto t = SerializeType(type.get()); + auto t = SerializeType(type); if ( ! t ) return broker::ec::invalid_data; diff --git a/src/OpaqueVal.h b/src/OpaqueVal.h index bcbe5f61c9..50a4e74ce9 100644 --- a/src/OpaqueVal.h +++ b/src/OpaqueVal.h @@ -148,7 +148,7 @@ protected: * Helper function for derived class that need to record a type * during serialization. */ - static broker::expected SerializeType(BroType* t); + static broker::expected SerializeType(const IntrusivePtr& t); /** * Helper function for derived class that need to restore a type diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 33857416f4..f0c55c2e64 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -408,7 +408,7 @@ broker::expected TopkVal::DoSerialize() const if ( type ) { - auto t = SerializeType(type.get()); + auto t = SerializeType(type); if ( ! t ) return broker::ec::invalid_data; From fcaade6e313064efb555f8ca188afda7e2a019dd Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 18 May 2020 17:09:27 -0700 Subject: [PATCH 080/151] Deprecate TableEntryVal::Value(), replace with GetVal() --- src/Stmt.cc | 2 +- src/Val.cc | 52 +++++++++++++++++++++--------------- src/Val.h | 9 ++++--- src/broker/Data.cc | 2 +- src/input/Manager.cc | 2 +- src/logging/Manager.cc | 2 +- src/supervisor/Supervisor.cc | 2 +- 7 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/Stmt.cc b/src/Stmt.cc index d0b9bac64e..9bc48835c3 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1197,7 +1197,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const delete k; if ( value_var ) - f->SetElement(value_var.get(), current_tev->Value()->Ref()); + f->SetElement(value_var.get(), current_tev->GetVal()->Ref()); for ( int i = 0; i < ind_lv->Length(); i++ ) f->SetElement((*loop_vars)[i], ind_lv->Idx(i)->Ref()); diff --git a/src/Val.cc b/src/Val.cc index a383086269..62ffb512ce 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -559,7 +559,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* // Strip quotes. key_str = key_str.substr(1, key_str.length() - 2); - BuildJSON(writer, entry->Value(), only_loggable, re, key_str); + BuildJSON(writer, entry->GetVal().get(), only_loggable, re, key_str); } } @@ -1451,8 +1451,8 @@ int TableVal::RecursiveSize() const TableEntryVal* tv; while ( (tv = v->NextEntry(c)) ) { - if ( tv->Value() ) - n += tv->Value()->AsTableVal()->RecursiveSize(); + if ( tv->GetVal() ) + n += tv->GetVal()->AsTableVal()->RecursiveSize(); } return n; @@ -1561,8 +1561,8 @@ bool TableVal::Assign(Val* index, HashKey* k, IntrusivePtr new_val) { auto change_index = index ? IntrusivePtr{NewRef{}, index} : RecoverIndex(&k_copy); - Val* v = old_entry_val ? old_entry_val->Value() : new_val.get(); - CallChangeFunc(change_index.get(), v, old_entry_val ? ELEMENT_CHANGED : ELEMENT_NEW); + auto v = old_entry_val ? old_entry_val->GetVal() : new_val; + CallChangeFunc(change_index.get(), v.get(), old_entry_val ? ELEMENT_CHANGED : ELEMENT_NEW); } delete old_entry_val; @@ -1618,12 +1618,12 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const if ( type->IsSet() ) { - if ( ! t->Assign(v->Value(), k, nullptr) ) + if ( ! t->Assign(v->GetVal().get(), k, nullptr) ) return false; } else { - if ( ! t->Assign(nullptr, k, {NewRef{}, v->Value()}) ) + if ( ! t->Assign(nullptr, k, v->GetVal()) ) return false; } } @@ -1895,7 +1895,10 @@ IntrusivePtr TableVal::Lookup(Val* index, bool use_default_val) if ( attrs && attrs->FindAttr(ATTR_EXPIRE_READ) ) v->SetExpireAccess(network_time); - return {NewRef{}, v->Value() ? v->Value() : this}; + if ( v->GetVal() ) + return v->GetVal(); + + return {NewRef{}, this}; } if ( ! use_default_val ) @@ -1919,7 +1922,10 @@ IntrusivePtr TableVal::Lookup(Val* index, bool use_default_val) if ( attrs && attrs->FindAttr(ATTR_EXPIRE_READ) ) v->SetExpireAccess(network_time); - return {NewRef{}, v->Value() ? v->Value() : this}; + if ( v->GetVal() ) + return v->GetVal(); + + return {NewRef{}, this}; } } } @@ -1957,8 +1963,8 @@ IntrusivePtr TableVal::LookupSubnetValues(const SubNetVal* search) SubNetVal* s = new SubNetVal(get<0>(element)); TableEntryVal* entry = reinterpret_cast(get<1>(element)); - if ( entry && entry->Value() ) - nt->Assign(s, {NewRef{}, entry->Value()}); + if ( entry && entry->GetVal() ) + nt->Assign(s, entry->GetVal()); else nt->Assign(s, nullptr); // set @@ -2069,7 +2075,10 @@ IntrusivePtr TableVal::Delete(const Val* index) { HashKey* k = ComputeHash(index); TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr; - IntrusivePtr va{NewRef{}, v ? (v->Value() ? v->Value() : this) : nullptr}; + IntrusivePtr va; + + if ( v ) + va = v->GetVal() ? v->GetVal() : IntrusivePtr{NewRef{}, this}; if ( subnets && ! subnets->Remove(index) ) reporter->InternalWarning("index not in prefix table"); @@ -2088,7 +2097,10 @@ IntrusivePtr TableVal::Delete(const Val* index) IntrusivePtr TableVal::Delete(const HashKey* k) { TableEntryVal* v = AsNonConstTable()->RemoveEntry(k); - IntrusivePtr va{NewRef{}, v ? (v->Value() ? v->Value() : this) : nullptr}; + IntrusivePtr va; + + if ( v ) + va = v->GetVal() ? v->GetVal() : IntrusivePtr{NewRef{}, this}; if ( subnets ) { @@ -2232,8 +2244,8 @@ void TableVal::Describe(ODesc* d) const { if ( d->IsReadable() ) d->AddSP("] ="); - if ( v->Value() ) - v->Value()->Describe(d); + if ( v->GetVal() ) + v->GetVal()->Describe(d); } if ( d->IsReadable() && ! d->IsShort() && d->IncludeStats() ) @@ -2408,7 +2420,7 @@ void TableVal::DoExpire(double t) { if ( ! idx ) idx = RecoverIndex(k); - CallChangeFunc(idx.get(), v->Value(), ELEMENT_EXPIRED); + CallChangeFunc(idx.get(), v->GetVal().get(), ELEMENT_EXPIRED); } delete v; @@ -2576,8 +2588,8 @@ unsigned int TableVal::MemoryAllocation() const TableEntryVal* tv; while ( (tv = v->NextEntry(c)) ) { - if ( tv->Value() ) - size += tv->Value()->MemoryAllocation(); + if ( tv->GetVal() ) + size += tv->GetVal()->MemoryAllocation(); size += padded_sizeof(TableEntryVal); } @@ -2628,9 +2640,7 @@ TableVal::ParseTimeTableState TableVal::DumpTableState() while ( (val = tbl->NextEntry(key, cookie)) ) { - rval.emplace_back(RecoverIndex(key), - IntrusivePtr{NewRef{}, val->Value()}); - + rval.emplace_back(RecoverIndex(key), val->GetVal()); delete key; } diff --git a/src/Val.h b/src/Val.h index 1948440387..d272dd4787 100644 --- a/src/Val.h +++ b/src/Val.h @@ -689,9 +689,8 @@ extern double bro_start_network_time; class TableEntryVal { public: - template - explicit TableEntryVal(V&& v) - : val(std::forward(v)) + explicit TableEntryVal(IntrusivePtr v) + : val(std::move(v)) { last_access_time = network_time; expire_access_time = @@ -700,8 +699,12 @@ public: TableEntryVal* Clone(Val::CloneState* state); + [[deprecated("Remove in v4.1. Use GetVal().")]] Val* Value() { return val.get(); } + const IntrusivePtr& GetVal() const + { return val; } + // Returns/sets time of last expiration relevant access to this value. double ExpireAccessTime() const { return bro_start_network_time + expire_access_time; } diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 2b5e94e2b0..a6ae4cc93a 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -928,7 +928,7 @@ broker::expected bro_broker::val_to_data(const Val* v) caf::get(rval).emplace(move(key)); else { - auto val = val_to_data(entry->Value()); + auto val = val_to_data(entry->GetVal().get()); if ( ! val ) return broker::ec::invalid_data; diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 1e8c9eba06..993c8804a9 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -285,7 +285,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) { auto index = info->config->RecoverIndex(k); string key = index->Idx(0)->AsString()->CheckString(); - string value = v->Value()->AsString()->CheckString(); + string value = v->GetVal()->AsString()->CheckString(); rinfo.config.insert(std::make_pair(copy_string(key.c_str()), copy_string(value.c_str()))); delete k; } diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index f1643eea8b..04704fc8bf 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -871,7 +871,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) { auto index = filter->config->RecoverIndex(k); string key = index->Idx(0)->AsString()->CheckString(); - string value = v->Value()->AsString()->CheckString(); + string value = v->GetVal()->AsString()->CheckString(); info->config.insert(std::make_pair(copy_string(key.c_str()), copy_string(value.c_str()))); delete k; } diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 6dd4c65506..3004a798c7 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1027,7 +1027,7 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node) auto key = cluster_table_val->RecoverIndex(k); delete k; auto name = key->Idx(0)->AsStringVal()->ToStdString(); - auto rv = v->Value()->AsRecordVal(); + auto rv = v->GetVal()->AsRecordVal(); Supervisor::ClusterEndpoint ep; ep.role = static_cast(rv->Lookup("role")->AsEnum()); From cda47384076497881768d22da7ee7c8654de412d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 18 May 2020 17:52:54 -0700 Subject: [PATCH 081/151] Switch RecordVal::CoerceTo() to use IntrusivePtr --- src/Expr.cc | 23 ++++++++++------ src/Val.cc | 27 ++++++++++--------- src/Val.h | 7 +++-- .../analyzer/extract/functions.bif | 2 +- src/file_analysis/file_analysis.bif | 4 +-- src/logging/Manager.cc | 4 +-- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index afd9b7a695..0690bf74b6 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3018,7 +3018,10 @@ IntrusivePtr RecordConstructorExpr::InitVal(const BroType* t, IntrusivePtr< if ( v ) { RecordVal* rv = v->AsRecordVal(); - auto ar = rv->CoerceTo(t->AsRecordType(), aggr.release()); + auto bt = const_cast(t); + IntrusivePtr rt{NewRef{}, bt->AsRecordType()}; + auto aggr_rec = cast_intrusive(std::move(aggr)); + auto ar = rv->CoerceTo(std::move(rt), std::move(aggr_rec)); if ( ar ) return ar; @@ -3633,7 +3636,11 @@ IntrusivePtr RecordCoerceExpr::InitVal(const BroType* t, IntrusivePtr if ( auto v = Eval(nullptr) ) { RecordVal* rv = v->AsRecordVal(); - if ( auto ar = rv->CoerceTo(t->AsRecordType(), aggr.release()) ) + auto bt = const_cast(t); + IntrusivePtr rt{NewRef{}, bt->AsRecordType()}; + auto aggr_rec = cast_intrusive(std::move(aggr)); + + if ( auto ar = rv->CoerceTo(std::move(rt), std::move(aggr_rec)) ) return ar; } @@ -3673,19 +3680,19 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const } BroType* rhs_type = rhs->GetType().get(); - BroType* field_type = val_type->GetFieldType(i).get(); + const auto& field_type = val_type->GetFieldType(i); if ( rhs_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && - ! same_type(rhs_type, field_type) ) + ! same_type(rhs_type, field_type.get()) ) { - if ( auto new_val = rhs->AsRecordVal()->CoerceTo(field_type->AsRecordType()) ) + if ( auto new_val = rhs->AsRecordVal()->CoerceTo(cast_intrusive(field_type)) ) rhs = std::move(new_val); } else if ( BothArithmetic(rhs_type->Tag(), field_type->Tag()) && - ! same_type(rhs_type, field_type) ) + ! same_type(rhs_type, field_type.get()) ) { - if ( auto new_val = check_and_promote(rhs, field_type, false, op->GetLocationInfo()) ) + if ( auto new_val = check_and_promote(rhs, field_type.get(), false, op->GetLocationInfo()) ) rhs = std::move(new_val); else RuntimeError("Failed type conversion"); @@ -3706,7 +3713,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const ! same_type(def_type.get(), field_type.get()) ) { auto tmp = def_val->AsRecordVal()->CoerceTo( - field_type->AsRecordType()); + cast_intrusive(field_type)); if ( tmp ) def_val = std::move(tmp); diff --git a/src/Val.cc b/src/Val.cc index 62ffb512ce..2d642fc057 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2694,7 +2694,7 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo def->GetType()->Tag() == TYPE_RECORD && ! same_type(def->GetType().get(), type.get()) ) { - auto tmp = def->AsRecordVal()->CoerceTo(type->AsRecordType()); + auto tmp = def->AsRecordVal()->CoerceTo(cast_intrusive(type)); if ( tmp ) def = std::move(tmp); @@ -2796,17 +2796,17 @@ IntrusivePtr RecordVal::Lookup(const char* field, bool with_default) const return with_default ? LookupWithDefault(idx) : IntrusivePtr{NewRef{}, Lookup(idx)}; } -IntrusivePtr RecordVal::CoerceTo(const RecordType* t, Val* aggr, bool allow_orphaning) const +IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, + IntrusivePtr aggr, + bool allow_orphaning) const { - if ( ! record_promotion_compatible(t->AsRecordType(), GetType()->AsRecordType()) ) + if ( ! record_promotion_compatible(t.get(), GetType()->AsRecordType()) ) return nullptr; if ( ! aggr ) - aggr = new RecordVal({NewRef{}, const_cast(t)}); + aggr = make_intrusive(std::move(t)); - RecordVal* ar = aggr->AsRecordVal(); RecordType* ar_t = aggr->GetType()->AsRecordType(); - const RecordType* rv_t = GetType()->AsRecordType(); int i; @@ -2840,15 +2840,15 @@ IntrusivePtr RecordVal::CoerceTo(const RecordType* t, Val* aggr, bool auto rhs = make_intrusive(IntrusivePtr{NewRef{}, v}); auto e = make_intrusive(std::move(rhs), cast_intrusive(ft)); - ar->Assign(t_i, e->Eval(nullptr)); + aggr->Assign(t_i, e->Eval(nullptr)); continue; } - ar->Assign(t_i, {NewRef{}, v}); + aggr->Assign(t_i, {NewRef{}, v}); } for ( i = 0; i < ar_t->NumFields(); ++i ) - if ( ! ar->Lookup(i) && + if ( ! aggr->Lookup(i) && ! ar_t->FieldDecl(i)->FindAttr(ATTR_OPTIONAL) ) { char buf[512]; @@ -2857,15 +2857,16 @@ IntrusivePtr RecordVal::CoerceTo(const RecordType* t, Val* aggr, bool Error(buf); } - return {AdoptRef{}, ar}; + return aggr; } -IntrusivePtr RecordVal::CoerceTo(RecordType* t, bool allow_orphaning) +IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, + bool allow_orphaning) { - if ( same_type(GetType().get(), t) ) + if ( same_type(GetType().get(), t.get()) ) return {NewRef{}, this}; - return CoerceTo(t, nullptr, allow_orphaning); + return CoerceTo(std::move(t), nullptr, allow_orphaning); } IntrusivePtr RecordVal::GetRecordFieldsVal() const diff --git a/src/Val.h b/src/Val.h index d272dd4787..37323c9a2f 100644 --- a/src/Val.h +++ b/src/Val.h @@ -983,8 +983,11 @@ public: // // The *allow_orphaning* parameter allows for a record to be demoted // down to a record type that contains less fields. - IntrusivePtr CoerceTo(const RecordType* other, Val* aggr, bool allow_orphaning = false) const; - IntrusivePtr CoerceTo(RecordType* other, bool allow_orphaning = false); + IntrusivePtr CoerceTo(IntrusivePtr other, + IntrusivePtr aggr, + bool allow_orphaning = false) const; + IntrusivePtr CoerceTo(IntrusivePtr other, + bool allow_orphaning = false); unsigned int MemoryAllocation() const override; void DescribeReST(ODesc* d) const override; diff --git a/src/file_analysis/analyzer/extract/functions.bif b/src/file_analysis/analyzer/extract/functions.bif index 6d0ac3435d..13cc904c4f 100644 --- a/src/file_analysis/analyzer/extract/functions.bif +++ b/src/file_analysis/analyzer/extract/functions.bif @@ -11,7 +11,7 @@ module FileExtract; function FileExtract::__set_limit%(file_id: string, args: any, n: count%): bool %{ using zeek::BifType::Record::Files::AnalyzerArgs; - auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs.get()); + auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs); bool result = file_mgr->SetExtractionLimit(file_id->CheckString(), rv.get(), n); return val_mgr->Bool(result); %} diff --git a/src/file_analysis/file_analysis.bif b/src/file_analysis/file_analysis.bif index e15163dd83..1f74668dd4 100644 --- a/src/file_analysis/file_analysis.bif +++ b/src/file_analysis/file_analysis.bif @@ -42,7 +42,7 @@ function Files::__set_reassembly_buffer%(file_id: string, max: count%): bool function Files::__add_analyzer%(file_id: string, tag: Files::Tag, args: any%): bool %{ using zeek::BifType::Record::Files::AnalyzerArgs; - auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs.get()); + auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs); bool result = file_mgr->AddAnalyzer(file_id->CheckString(), file_mgr->GetComponentTag(tag), rv.get()); return val_mgr->Bool(result); @@ -52,7 +52,7 @@ function Files::__add_analyzer%(file_id: string, tag: Files::Tag, args: any%): b function Files::__remove_analyzer%(file_id: string, tag: Files::Tag, args: any%): bool %{ using zeek::BifType::Record::Files::AnalyzerArgs; - auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs.get()); + auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs); bool result = file_mgr->RemoveAnalyzer(file_id->CheckString(), file_mgr->GetComponentTag(tag) , rv.get()); return val_mgr->Bool(result); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 04704fc8bf..a2773c7c22 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -701,7 +701,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) if ( ! stream->enabled ) return true; - auto columns = columns_arg->CoerceTo(stream->columns); + auto columns = columns_arg->CoerceTo({NewRef{}, stream->columns}); if ( ! columns ) { @@ -747,7 +747,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) const auto& rt = filter->path_func->GetType()->Params()->GetFieldType("rec"); if ( rt->Tag() == TYPE_RECORD ) - rec_arg = columns->CoerceTo(rt->AsRecordType(), true); + rec_arg = columns->CoerceTo(cast_intrusive(rt), true); else // Can be TYPE_ANY here. rec_arg = columns; From d7ca63c1be61bb83a6e371c5b914214a599132d7 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 18 May 2020 23:17:30 -0700 Subject: [PATCH 082/151] Switch RPC analyzers to use IntrusivePtr --- src/analyzer/protocol/rpc/MOUNT.cc | 42 +++---- src/analyzer/protocol/rpc/MOUNT.h | 10 +- src/analyzer/protocol/rpc/NFS.cc | 173 ++++++++++++--------------- src/analyzer/protocol/rpc/NFS.h | 74 ++++++------ src/analyzer/protocol/rpc/Portmap.cc | 72 +++++------ src/analyzer/protocol/rpc/Portmap.h | 8 +- src/analyzer/protocol/rpc/RPC.cc | 2 - src/analyzer/protocol/rpc/RPC.h | 8 +- 8 files changed, 172 insertions(+), 217 deletions(-) diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index ab5193725d..a3b9ab071a 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -22,7 +22,7 @@ bool MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) uint32_t proc = c->Proc(); // The call arguments, depends on the call type obviously ... - Val *callarg = nullptr; + IntrusivePtr callarg; switch ( proc ) { case BifEnum::MOUNT3::PROC_NULL: @@ -41,7 +41,6 @@ bool MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) break; default: - callarg = nullptr; if ( proc < BifEnum::MOUNT3::PROC_END_OF_PROCS ) { // We know the procedure but haven't implemented it. @@ -58,19 +57,10 @@ bool MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) } if ( ! buf ) - { - // There was a parse error while trying to extract the call - // arguments. However, we don't know where exactly it - // happened and whether Vals where already allocated (e.g., a - // RecordVal was allocated but we failed to fill it). So we - // Unref() the call arguments, and we are fine. - Unref(callarg); - callarg = nullptr; + // There was a parse error while trying to extract the call arguments. return false; - } - - c->AddVal(callarg); // It's save to AddVal(0). + c->AddVal(callarg); return true; } @@ -114,7 +104,7 @@ bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_statu break; case BifEnum::MOUNT3::PROC_MNT: - reply = {AdoptRef{}, mount3_mnt_reply(buf, n, mount_status)}; + reply = mount3_mnt_reply(buf, n, mount_status); event = mount_proc_mnt; break; @@ -159,13 +149,13 @@ bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_statu // optional and all are set to 0 ... if ( event ) { - Val *request = c->TakeRequestVal(); + auto request = c->TakeRequestVal(); auto vl = event_common_vl(c, rpc_status, mount_status, start_time, last_time, reply_len, (bool)request + (bool)reply); if ( request ) - vl.emplace_back(AdoptRef{}, request); + vl.emplace_back(std::move(request)); if ( reply ) vl.emplace_back(reply); @@ -213,14 +203,14 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, return vl; } -EnumVal* MOUNT_Interp::mount3_auth_flavor(const u_char*& buf, int& n) +IntrusivePtr MOUNT_Interp::mount3_auth_flavor(const u_char*& buf, int& n) { BifEnum::MOUNT3::auth_flavor_t t = (BifEnum::MOUNT3::auth_flavor_t)extract_XDR_uint32(buf, n); auto rval = zeek::BifType::Enum::MOUNT3::auth_flavor_t->GetVal(t); - return rval.release(); + return rval; } -StringVal* MOUNT_Interp::mount3_fh(const u_char*& buf, int& n) +IntrusivePtr MOUNT_Interp::mount3_fh(const u_char*& buf, int& n) { int fh_n; const u_char* fh = extract_XDR_opaque(buf, n, fh_n, 64); @@ -228,10 +218,10 @@ StringVal* MOUNT_Interp::mount3_fh(const u_char*& buf, int& n) if ( ! fh ) return nullptr; - return new StringVal(new BroString(fh, fh_n, false)); + return make_intrusive(new BroString(fh, fh_n, false)); } -StringVal* MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) +IntrusivePtr MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) { int name_len; const u_char* name = extract_XDR_opaque(buf, n, name_len); @@ -239,20 +229,20 @@ StringVal* MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) if ( ! name ) return nullptr; - return new StringVal(new BroString(name, name_len, false)); + return make_intrusive(new BroString(name, name_len, false)); } -RecordVal* MOUNT_Interp::mount3_dirmntargs(const u_char*& buf, int& n) +IntrusivePtr MOUNT_Interp::mount3_dirmntargs(const u_char*& buf, int& n) { - RecordVal* dirmntargs = new RecordVal(zeek::BifType::Record::MOUNT3::dirmntargs_t); + auto dirmntargs = make_intrusive(zeek::BifType::Record::MOUNT3::dirmntargs_t); dirmntargs->Assign(0, mount3_filename(buf, n)); return dirmntargs; } -RecordVal* MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n, +IntrusivePtr MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n, BifEnum::MOUNT3::status_t status) { - RecordVal* rep = new RecordVal(zeek::BifType::Record::MOUNT3::mnt_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::MOUNT3::mnt_reply_t); if ( status == BifEnum::MOUNT3::MNT3_OK ) { diff --git a/src/analyzer/protocol/rpc/MOUNT.h b/src/analyzer/protocol/rpc/MOUNT.h index b3b2683f8e..0409db7404 100644 --- a/src/analyzer/protocol/rpc/MOUNT.h +++ b/src/analyzer/protocol/rpc/MOUNT.h @@ -29,12 +29,12 @@ protected: // to 0. However, the methods might still return an allocated Val * ! // So, you might want to Unref() the Val if buf is 0. Method names // are based on the type names of RFC 1813. - EnumVal* mount3_auth_flavor(const u_char*& buf, int& n); - StringVal* mount3_fh(const u_char*& buf, int& n); - RecordVal* mount3_dirmntargs(const u_char*&buf, int &n); - StringVal* mount3_filename(const u_char*& buf, int& n); + IntrusivePtr mount3_auth_flavor(const u_char*& buf, int& n); + IntrusivePtr mount3_fh(const u_char*& buf, int& n); + IntrusivePtr mount3_dirmntargs(const u_char*&buf, int &n); + IntrusivePtr mount3_filename(const u_char*& buf, int& n); - RecordVal* mount3_mnt_reply(const u_char*& buf, int& n, BifEnum::MOUNT3::status_t status); + IntrusivePtr mount3_mnt_reply(const u_char*& buf, int& n, BifEnum::MOUNT3::status_t status); }; class MOUNT_Analyzer : public RPC_Analyzer { diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index c97bcf7b3c..c687c85fac 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -22,7 +22,7 @@ bool NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) uint32_t proc = c->Proc(); // The call arguments, depends on the call type obviously ... - Val *callarg = nullptr; + IntrusivePtr callarg; switch ( proc ) { case BifEnum::NFS3::PROC_NULL: @@ -95,7 +95,6 @@ bool NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) break; default: - callarg = nullptr; if ( proc < BifEnum::NFS3::PROC_END_OF_PROCS ) { // We know the procedure but haven't implemented it. @@ -112,18 +111,10 @@ bool NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) } if ( ! buf ) - { - // There was a parse error while trying to extract the call - // arguments. However, we don't know where exactly it - // happened and whether Vals where already allocated (e.g., a - // RecordVal was allocated but we failed to fill it). So we - // Unref() the call arguments, and we are fine. - Unref(callarg); - callarg = nullptr; + // There was a parse error while trying to extract the call arguments. return false; - } - c->AddVal(callarg); // It's save to AddVal(0). + c->AddVal(std::move(callarg)); return true; } @@ -133,7 +124,7 @@ bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, double last_time, int reply_len) { EventHandlerPtr event = nullptr; - Val *reply = nullptr; + IntrusivePtr reply; BifEnum::NFS3::status_t nfs_status = BifEnum::NFS3::NFS3ERR_OK; bool rpc_success = ( rpc_status == BifEnum::RPC_SUCCESS ); @@ -251,8 +242,7 @@ bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, // Otherwise DeliverRPC would complain about // excess_RPC. n = 0; - auto ev = zeek::BifType::Enum::NFS3::proc_t->GetVal(c->Proc()); - reply = ev.release(); + reply = zeek::BifType::Enum::NFS3::proc_t->GetVal(c->Proc()); event = nfs_proc_not_implemented; } else @@ -260,13 +250,8 @@ bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, } if ( rpc_success && ! buf ) - { - // There was a parse error. We have to unref the reply. (see - // also comments in RPC_BuildCall. - Unref(reply); - reply = nullptr; + // There was a parse error. return false; - } // Note: if reply == 0, it won't be added to the val_list for the // event. While we can check for that on the policy layer it's kinda @@ -276,26 +261,24 @@ bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, // optional and all are set to 0 ... if ( event ) { - Val *request = c->TakeRequestVal(); + auto request = c->TakeRequestVal(); auto vl = event_common_vl(c, rpc_status, nfs_status, start_time, last_time, reply_len, (bool)request + (bool)reply); if ( request ) - vl.emplace_back(AdoptRef{}, request); + vl.emplace_back(std::move(request)); if ( reply ) - vl.emplace_back(AdoptRef{}, reply); + vl.emplace_back(std::move(reply)); analyzer->EnqueueConnEvent(event, std::move(vl)); } - else - Unref(reply); return true; } -StringVal* NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size) +IntrusivePtr NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size) { int data_n; @@ -314,7 +297,7 @@ StringVal* NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offse data_n = std::min(data_n, int(zeek::BifConst::NFS3::return_data_max)); if ( data && data_n > 0 ) - return new StringVal(new BroString(data, data_n, false)); + return make_intrusive(new BroString(data, data_n, false)); return nullptr; } @@ -353,7 +336,7 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_ return vl; } -StringVal* NFS_Interp::nfs3_fh(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_fh(const u_char*& buf, int& n) { int fh_n; const u_char* fh = extract_XDR_opaque(buf, n, fh_n, 64); @@ -361,13 +344,13 @@ StringVal* NFS_Interp::nfs3_fh(const u_char*& buf, int& n) if ( ! fh ) return nullptr; - return new StringVal(new BroString(fh, fh_n, false)); + return make_intrusive(new BroString(fh, fh_n, false)); } -RecordVal* NFS_Interp::nfs3_sattr(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_sattr(const u_char*& buf, int& n) { - RecordVal* attrs = new RecordVal(zeek::BifType::Record::NFS3::sattr_t); + auto attrs = make_intrusive(zeek::BifType::Record::NFS3::sattr_t); attrs->Assign(0, nullptr); // mode int mode_set_it = extract_XDR_uint32(buf, n); @@ -396,9 +379,9 @@ RecordVal* NFS_Interp::nfs3_sattr(const u_char*& buf, int& n) return attrs; } -RecordVal* NFS_Interp::nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +IntrusivePtr NFS_Interp::nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal* rep = new RecordVal(zeek::BifType::Record::NFS3::sattr_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::sattr_reply_t); if ( status == BifEnum::NFS3::NFS3ERR_OK ) { @@ -414,9 +397,9 @@ RecordVal* NFS_Interp::nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS return rep; } -RecordVal* NFS_Interp::nfs3_fattr(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_fattr(const u_char*& buf, int& n) { - RecordVal* attrs = new RecordVal(zeek::BifType::Record::NFS3::fattr_t); + auto attrs = make_intrusive(zeek::BifType::Record::NFS3::fattr_t); attrs->Assign(0, nfs3_ftype(buf, n)); // file type attrs->Assign(1, ExtractUint32(buf, n)); // mode @@ -436,23 +419,23 @@ RecordVal* NFS_Interp::nfs3_fattr(const u_char*& buf, int& n) return attrs; } -EnumVal* NFS_Interp::nfs3_time_how(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_time_how(const u_char*& buf, int& n) { BifEnum::NFS3::time_how_t t = (BifEnum::NFS3::time_how_t)extract_XDR_uint32(buf, n); auto rval = zeek::BifType::Enum::NFS3::time_how_t->GetVal(t); - return rval.release(); + return rval; } -EnumVal* NFS_Interp::nfs3_ftype(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_ftype(const u_char*& buf, int& n) { BifEnum::NFS3::file_type_t t = (BifEnum::NFS3::file_type_t)extract_XDR_uint32(buf, n); auto rval = zeek::BifType::Enum::NFS3::file_type_t->GetVal(t); - return rval.release(); + return rval; } -RecordVal* NFS_Interp::nfs3_wcc_attr(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_wcc_attr(const u_char*& buf, int& n) { - RecordVal* attrs = new RecordVal(zeek::BifType::Record::NFS3::wcc_attr_t); + auto attrs = make_intrusive(zeek::BifType::Record::NFS3::wcc_attr_t); attrs->Assign(0, ExtractUint64(buf, n)); // size attrs->Assign(1, ExtractTime(buf, n)); // mtime @@ -461,7 +444,7 @@ RecordVal* NFS_Interp::nfs3_wcc_attr(const u_char*& buf, int& n) return attrs; } -StringVal *NFS_Interp::nfs3_filename(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_filename(const u_char*& buf, int& n) { int name_len; const u_char* name = extract_XDR_opaque(buf, n, name_len); @@ -469,12 +452,12 @@ StringVal *NFS_Interp::nfs3_filename(const u_char*& buf, int& n) if ( ! name ) return nullptr; - return new StringVal(new BroString(name, name_len, false)); + return make_intrusive(new BroString(name, name_len, false)); } -RecordVal *NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n) { - RecordVal *diropargs = new RecordVal(zeek::BifType::Record::NFS3::diropargs_t); + auto diropargs = make_intrusive(zeek::BifType::Record::NFS3::diropargs_t); diropargs->Assign(0, nfs3_fh(buf, n)); diropargs->Assign(1, nfs3_filename(buf, n)); @@ -482,9 +465,9 @@ RecordVal *NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n) return diropargs; } -RecordVal* NFS_Interp::nfs3_symlinkdata(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_symlinkdata(const u_char*& buf, int& n) { - RecordVal* symlinkdata = new RecordVal(zeek::BifType::Record::NFS3::symlinkdata_t); + auto symlinkdata = make_intrusive(zeek::BifType::Record::NFS3::symlinkdata_t); symlinkdata->Assign(0, nfs3_sattr(buf, n)); symlinkdata->Assign(1, nfs3_nfspath(buf, n)); @@ -492,9 +475,9 @@ RecordVal* NFS_Interp::nfs3_symlinkdata(const u_char*& buf, int& n) return symlinkdata; } -RecordVal *NFS_Interp::nfs3_renameopargs(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_renameopargs(const u_char*& buf, int& n) { - RecordVal *renameopargs = new RecordVal(zeek::BifType::Record::NFS3::renameopargs_t); + auto renameopargs = make_intrusive(zeek::BifType::Record::NFS3::renameopargs_t); renameopargs->Assign(0, nfs3_fh(buf, n)); renameopargs->Assign(1, nfs3_filename(buf, n)); @@ -504,7 +487,7 @@ RecordVal *NFS_Interp::nfs3_renameopargs(const u_char*& buf, int& n) return renameopargs; } -RecordVal* NFS_Interp::nfs3_post_op_attr(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_post_op_attr(const u_char*& buf, int& n) { int have_attrs = extract_XDR_uint32(buf, n); @@ -514,7 +497,7 @@ RecordVal* NFS_Interp::nfs3_post_op_attr(const u_char*& buf, int& n) return nullptr; } -StringVal* NFS_Interp::nfs3_post_op_fh(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_post_op_fh(const u_char*& buf, int& n) { int have_fh = extract_XDR_uint32(buf, n); @@ -524,7 +507,7 @@ StringVal* NFS_Interp::nfs3_post_op_fh(const u_char*& buf, int& n) return nullptr; } -RecordVal* NFS_Interp::nfs3_pre_op_attr(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_pre_op_attr(const u_char*& buf, int& n) { int have_attrs = extract_XDR_uint32(buf, n); @@ -533,16 +516,16 @@ RecordVal* NFS_Interp::nfs3_pre_op_attr(const u_char*& buf, int& n) return nullptr; } -EnumVal *NFS_Interp::nfs3_stable_how(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_stable_how(const u_char*& buf, int& n) { BifEnum::NFS3::stable_how_t stable = (BifEnum::NFS3::stable_how_t)extract_XDR_uint32(buf, n); auto rval = zeek::BifType::Enum::NFS3::stable_how_t->GetVal(stable); - return rval.release(); + return rval; } -RecordVal* NFS_Interp::nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +IntrusivePtr NFS_Interp::nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::lookup_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::lookup_reply_t); if ( status == BifEnum::NFS3::NFS3ERR_OK ) { @@ -559,9 +542,9 @@ RecordVal* NFS_Interp::nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NF return rep; } -RecordVal *NFS_Interp::nfs3_readargs(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_readargs(const u_char*& buf, int& n) { - RecordVal *readargs = new RecordVal(zeek::BifType::Record::NFS3::readargs_t); + auto readargs = make_intrusive(zeek::BifType::Record::NFS3::readargs_t); readargs->Assign(0, nfs3_fh(buf, n)); readargs->Assign(1, ExtractUint64(buf, n)); // offset @@ -570,10 +553,10 @@ RecordVal *NFS_Interp::nfs3_readargs(const u_char*& buf, int& n) return readargs; } -RecordVal* NFS_Interp::nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, +IntrusivePtr NFS_Interp::nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, bro_uint_t offset) { - RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::read_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::read_reply_t); if (status == BifEnum::NFS3::NFS3ERR_OK) { @@ -593,9 +576,9 @@ RecordVal* NFS_Interp::nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3 return rep; } -RecordVal* NFS_Interp::nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +IntrusivePtr NFS_Interp::nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::readlink_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::readlink_reply_t); if (status == BifEnum::NFS3::NFS3ERR_OK) { @@ -610,9 +593,9 @@ RecordVal* NFS_Interp::nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum:: return rep; } -RecordVal* NFS_Interp::nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +IntrusivePtr NFS_Interp::nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal* rep = new RecordVal(zeek::BifType::Record::NFS3::link_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::link_reply_t); if ( status == BifEnum::NFS3::NFS3ERR_OK ) { @@ -626,9 +609,9 @@ RecordVal* NFS_Interp::nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3 return rep; } -RecordVal* NFS_Interp::nfs3_symlinkargs(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_symlinkargs(const u_char*& buf, int& n) { - RecordVal* symlinkargs = new RecordVal(zeek::BifType::Record::NFS3::symlinkargs_t); + auto symlinkargs = make_intrusive(zeek::BifType::Record::NFS3::symlinkargs_t); symlinkargs->Assign(0, nfs3_diropargs(buf, n)); symlinkargs->Assign(1, nfs3_symlinkdata(buf, n)); @@ -636,9 +619,9 @@ RecordVal* NFS_Interp::nfs3_symlinkargs(const u_char*& buf, int& n) return symlinkargs; } -RecordVal* NFS_Interp::nfs3_sattrargs(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_sattrargs(const u_char*& buf, int& n) { - RecordVal* sattrargs = new RecordVal(zeek::BifType::Record::NFS3::sattrargs_t); + auto sattrargs = make_intrusive(zeek::BifType::Record::NFS3::sattrargs_t); sattrargs->Assign(0, nfs3_fh(buf, n)); sattrargs->Assign(1, nfs3_sattr(buf, n)); @@ -646,9 +629,9 @@ RecordVal* NFS_Interp::nfs3_sattrargs(const u_char*& buf, int& n) return sattrargs; } -RecordVal* NFS_Interp::nfs3_linkargs(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_linkargs(const u_char*& buf, int& n) { - RecordVal* linkargs = new RecordVal(zeek::BifType::Record::NFS3::linkargs_t); + auto linkargs = make_intrusive(zeek::BifType::Record::NFS3::linkargs_t); linkargs->Assign(0, nfs3_fh(buf, n)); linkargs->Assign(1, nfs3_diropargs(buf, n)); @@ -656,11 +639,11 @@ RecordVal* NFS_Interp::nfs3_linkargs(const u_char*& buf, int& n) return linkargs; } -RecordVal *NFS_Interp::nfs3_writeargs(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_writeargs(const u_char*& buf, int& n) { uint32_t bytes; uint64_t offset; - RecordVal *writeargs = new RecordVal(zeek::BifType::Record::NFS3::writeargs_t); + auto writeargs = make_intrusive(zeek::BifType::Record::NFS3::writeargs_t); writeargs->Assign(0, nfs3_fh(buf, n)); offset = extract_XDR_uint64(buf, n); @@ -674,9 +657,9 @@ RecordVal *NFS_Interp::nfs3_writeargs(const u_char*& buf, int& n) return writeargs; } -RecordVal *NFS_Interp::nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +IntrusivePtr NFS_Interp::nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::write_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::write_reply_t); if ( status == BifEnum::NFS3::NFS3ERR_OK ) { @@ -699,9 +682,9 @@ RecordVal *NFS_Interp::nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS return rep; } -RecordVal* NFS_Interp::nfs3_newobj_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +IntrusivePtr NFS_Interp::nfs3_newobj_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::newobj_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::newobj_reply_t); if (status == BifEnum::NFS3::NFS3ERR_OK) { @@ -723,9 +706,9 @@ RecordVal* NFS_Interp::nfs3_newobj_reply(const u_char*& buf, int& n, BifEnum::NF return rep; } -RecordVal* NFS_Interp::nfs3_delobj_reply(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_delobj_reply(const u_char*& buf, int& n) { - RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::delobj_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::delobj_reply_t); // wcc_data rep->Assign(0, nfs3_pre_op_attr(buf, n)); @@ -734,9 +717,9 @@ RecordVal* NFS_Interp::nfs3_delobj_reply(const u_char*& buf, int& n) return rep; } -RecordVal* NFS_Interp::nfs3_renameobj_reply(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::nfs3_renameobj_reply(const u_char*& buf, int& n) { - RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::renameobj_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::renameobj_reply_t); // wcc_data rep->Assign(0, nfs3_pre_op_attr(buf, n)); @@ -747,9 +730,9 @@ RecordVal* NFS_Interp::nfs3_renameobj_reply(const u_char*& buf, int& n) return rep; } -RecordVal* NFS_Interp::nfs3_readdirargs(bool isplus, const u_char*& buf, int&n) +IntrusivePtr NFS_Interp::nfs3_readdirargs(bool isplus, const u_char*& buf, int&n) { - RecordVal *args = new RecordVal(zeek::BifType::Record::NFS3::readdirargs_t); + auto args = make_intrusive(zeek::BifType::Record::NFS3::readdirargs_t); args->Assign(0, val_mgr->Bool(isplus)); args->Assign(1, nfs3_fh(buf, n)); @@ -763,10 +746,10 @@ RecordVal* NFS_Interp::nfs3_readdirargs(bool isplus, const u_char*& buf, int&n) return args; } -RecordVal* NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char*& buf, +IntrusivePtr NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char*& buf, int&n, BifEnum::NFS3::status_t status) { - RecordVal *rep = new RecordVal(zeek::BifType::Record::NFS3::readdir_reply_t); + auto rep = make_intrusive(zeek::BifType::Record::NFS3::readdir_reply_t); rep->Assign(0, val_mgr->Bool(isplus)); @@ -808,29 +791,29 @@ RecordVal* NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char*& buf, return rep; } -Val* NFS_Interp::ExtractUint32(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::ExtractUint32(const u_char*& buf, int& n) { - return val_mgr->Count(extract_XDR_uint32(buf, n)).release(); + return val_mgr->Count(extract_XDR_uint32(buf, n)); } -Val* NFS_Interp::ExtractUint64(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::ExtractUint64(const u_char*& buf, int& n) { - return val_mgr->Count(extract_XDR_uint64(buf, n)).release(); + return val_mgr->Count(extract_XDR_uint64(buf, n)); } -Val* NFS_Interp::ExtractTime(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::ExtractTime(const u_char*& buf, int& n) { - return new Val(extract_XDR_time(buf, n), TYPE_TIME); + return make_intrusive(extract_XDR_time(buf, n), TYPE_TIME); } -Val* NFS_Interp::ExtractInterval(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::ExtractInterval(const u_char*& buf, int& n) { - return new IntervalVal(double(extract_XDR_uint32(buf, n)), 1.0); + return make_intrusive(double(extract_XDR_uint32(buf, n)), 1.0); } -Val* NFS_Interp::ExtractBool(const u_char*& buf, int& n) +IntrusivePtr NFS_Interp::ExtractBool(const u_char*& buf, int& n) { - return val_mgr->Bool(extract_XDR_uint32(buf, n))->Ref(); + return val_mgr->Bool(extract_XDR_uint32(buf, n)); } diff --git a/src/analyzer/protocol/rpc/NFS.h b/src/analyzer/protocol/rpc/NFS.h index a215dfc14a..9d5942878e 100644 --- a/src/analyzer/protocol/rpc/NFS.h +++ b/src/analyzer/protocol/rpc/NFS.h @@ -30,53 +30,53 @@ protected: // to 0. However, the methods might still return an allocated Val * ! // So, you might want to Unref() the Val if buf is 0. Method names // are based on the type names of RFC 1813. - StringVal* nfs3_fh(const u_char*& buf, int& n); - RecordVal* nfs3_fattr(const u_char*& buf, int& n); - RecordVal* nfs3_sattr(const u_char*& buf, int& n); - EnumVal* nfs3_ftype(const u_char*& buf, int& n); - EnumVal* nfs3_time_how(const u_char*& buf, int& n); - RecordVal* nfs3_wcc_attr(const u_char*& buf, int& n); - RecordVal* nfs3_diropargs(const u_char*&buf, int &n); - RecordVal* nfs3_symlinkdata(const u_char*& buf, int& n); - RecordVal* nfs3_renameopargs(const u_char*&buf, int &n); - StringVal* nfs3_filename(const u_char*& buf, int& n); - RecordVal* nfs3_linkargs(const u_char*& buf, int& n); - RecordVal* nfs3_symlinkargs(const u_char*& buf, int& n); - RecordVal* nfs3_sattrargs(const u_char*& buf, int& n); - StringVal* nfs3_nfspath(const u_char*& buf, int& n) + IntrusivePtr nfs3_fh(const u_char*& buf, int& n); + IntrusivePtr nfs3_fattr(const u_char*& buf, int& n); + IntrusivePtr nfs3_sattr(const u_char*& buf, int& n); + IntrusivePtr nfs3_ftype(const u_char*& buf, int& n); + IntrusivePtr nfs3_time_how(const u_char*& buf, int& n); + IntrusivePtr nfs3_wcc_attr(const u_char*& buf, int& n); + IntrusivePtr nfs3_diropargs(const u_char*&buf, int &n); + IntrusivePtr nfs3_symlinkdata(const u_char*& buf, int& n); + IntrusivePtr nfs3_renameopargs(const u_char*&buf, int &n); + IntrusivePtr nfs3_filename(const u_char*& buf, int& n); + IntrusivePtr nfs3_linkargs(const u_char*& buf, int& n); + IntrusivePtr nfs3_symlinkargs(const u_char*& buf, int& n); + IntrusivePtr nfs3_sattrargs(const u_char*& buf, int& n); + IntrusivePtr nfs3_nfspath(const u_char*& buf, int& n) { return nfs3_filename(buf,n); } - RecordVal* nfs3_post_op_attr(const u_char*&buf, int &n); // Return 0 or an fattr - RecordVal* nfs3_pre_op_attr(const u_char*&buf, int &n); // Return 0 or an wcc_attr - RecordVal* nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - RecordVal* nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - RecordVal* nfs3_readargs(const u_char*& buf, int& n); - RecordVal* nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, bro_uint_t offset); - RecordVal* nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - RecordVal* nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - RecordVal* nfs3_writeargs(const u_char*& buf, int& n); - EnumVal* nfs3_stable_how(const u_char*& buf, int& n); - RecordVal* nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - RecordVal* nfs3_newobj_reply(const u_char*& buf, int&n, BifEnum::NFS3::status_t status); - RecordVal* nfs3_delobj_reply(const u_char*& buf, int& n); - RecordVal* nfs3_renameobj_reply(const u_char*& buf, int& n); - StringVal* nfs3_post_op_fh(const u_char*& buf, int& n); - RecordVal* nfs3_readdirargs(bool isplus, const u_char*& buf, int&n); - RecordVal* nfs3_readdir_reply(bool isplus, const u_char*& buf, int&n, BifEnum::NFS3::status_t status); + IntrusivePtr nfs3_post_op_attr(const u_char*&buf, int &n); // Return 0 or an fattr + IntrusivePtr nfs3_pre_op_attr(const u_char*&buf, int &n); // Return 0 or an wcc_attr + IntrusivePtr nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + IntrusivePtr nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + IntrusivePtr nfs3_readargs(const u_char*& buf, int& n); + IntrusivePtr nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, bro_uint_t offset); + IntrusivePtr nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + IntrusivePtr nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + IntrusivePtr nfs3_writeargs(const u_char*& buf, int& n); + IntrusivePtr nfs3_stable_how(const u_char*& buf, int& n); + IntrusivePtr nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + IntrusivePtr nfs3_newobj_reply(const u_char*& buf, int&n, BifEnum::NFS3::status_t status); + IntrusivePtr nfs3_delobj_reply(const u_char*& buf, int& n); + IntrusivePtr nfs3_renameobj_reply(const u_char*& buf, int& n); + IntrusivePtr nfs3_post_op_fh(const u_char*& buf, int& n); + IntrusivePtr nfs3_readdirargs(bool isplus, const u_char*& buf, int&n); + IntrusivePtr nfs3_readdir_reply(bool isplus, const u_char*& buf, int&n, BifEnum::NFS3::status_t status); // Consumes the file data in the RPC message. Depending on NFS::return_data* consts // in bro.init returns NULL or the data as string val: // * offset is the offset of the read/write call // * size is the amount of bytes read (or requested to be written), - StringVal* nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size); + IntrusivePtr nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size); - Val* ExtractUint32(const u_char*& buf, int& n); - Val* ExtractUint64(const u_char*& buf, int& n); - Val* ExtractTime(const u_char*& buf, int& n); - Val* ExtractInterval(const u_char*& buf, int& n); - Val* ExtractBool(const u_char*& buf, int& n); + IntrusivePtr ExtractUint32(const u_char*& buf, int& n); + IntrusivePtr ExtractUint64(const u_char*& buf, int& n); + IntrusivePtr ExtractTime(const u_char*& buf, int& n); + IntrusivePtr ExtractInterval(const u_char*& buf, int& n); + IntrusivePtr ExtractBool(const u_char*& buf, int& n); }; class NFS_Analyzer : public RPC_Analyzer { diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 4c1c0ffb6c..1d1480fa42 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -29,28 +29,28 @@ bool PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n case PMAPPROC_SET: { - Val* m = ExtractMapping(buf, n); + auto m = ExtractMapping(buf, n); if ( ! m ) return false; - c->AddVal(m); + c->AddVal(std::move(m)); } break; case PMAPPROC_UNSET: { - Val* m = ExtractMapping(buf, n); + auto m = ExtractMapping(buf, n); if ( ! m ) return false; - c->AddVal(m); + c->AddVal(std::move(m)); } break; case PMAPPROC_GETPORT: { - Val* pr = ExtractPortRequest(buf, n); + auto pr = ExtractPortRequest(buf, n); if ( ! pr ) return false; - c->AddVal(pr); + c->AddVal(std::move(pr)); } break; @@ -59,10 +59,10 @@ bool PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n case PMAPPROC_CALLIT: { - Val* call_it = ExtractCallItRequest(buf, n); + auto call_it = ExtractCallItRequest(buf, n); if ( ! call_it ) return false; - c->AddVal(call_it); + c->AddVal(std::move(call_it)); } break; @@ -79,7 +79,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu int reply_len) { EventHandlerPtr event; - Val *reply = nullptr; + IntrusivePtr reply; int success = (status == BifEnum::RPC_SUCCESS); switch ( c->Proc() ) { @@ -94,7 +94,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu if ( ! buf ) return false; - reply = val_mgr->Bool(status)->Ref(); + reply = val_mgr->Bool(status); event = pm_request_set; } else @@ -109,7 +109,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu if ( ! buf ) return false; - reply = val_mgr->Bool(status)->Ref(); + reply = val_mgr->Bool(status); event = pm_request_unset; } else @@ -127,7 +127,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu RecordVal* rv = c->RequestVal()->AsRecordVal(); Val* is_tcp = rv->Lookup(2); reply = val_mgr->Port(CheckPort(port), is_tcp->IsOne() ? - TRANSPORT_TCP : TRANSPORT_UDP)->Ref(); + TRANSPORT_TCP : TRANSPORT_UDP); event = pm_request_getport; } else @@ -139,28 +139,25 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu if ( success ) { static auto pm_mappings = zeek::id::find_type("pm_mappings"); - TableVal* mappings = new TableVal(pm_mappings); + auto mappings = make_intrusive(pm_mappings); uint32_t nmap = 0; // Each call in the loop test pulls the next "opted" // element to see if there are more mappings. while ( extract_XDR_uint32(buf, n) && buf ) { - Val* m = ExtractMapping(buf, n); + auto m = ExtractMapping(buf, n); if ( ! m ) break; auto index = val_mgr->Count(++nmap); - mappings->Assign(index.get(), m); + mappings->Assign(index.get(), std::move(m)); } if ( ! buf ) - { - Unref(mappings); return false; - } - reply = mappings; + reply = std::move(mappings); event = pm_request_dump; } else @@ -177,7 +174,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu if ( ! opaque_reply ) return false; - reply = val_mgr->Port(CheckPort(port), TRANSPORT_UDP)->Ref(); + reply = val_mgr->Port(CheckPort(port), TRANSPORT_UDP); event = pm_request_callit; } else @@ -188,14 +185,14 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu return false; } - Event(event, c->TakeRequestVal(), status, reply); + Event(event, c->TakeRequestVal(), status, std::move(reply)); return true; } -Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) +IntrusivePtr PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) { static auto pm_mapping = zeek::id::find_type("pm_mapping"); - RecordVal* mapping = new RecordVal(pm_mapping); + auto mapping = make_intrusive(pm_mapping); mapping->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); mapping->Assign(1, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -205,18 +202,15 @@ Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) mapping->Assign(2, val_mgr->Port(CheckPort(port), is_tcp ? TRANSPORT_TCP : TRANSPORT_UDP)); if ( ! buf ) - { - Unref(mapping); return nullptr; - } return mapping; } -Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) +IntrusivePtr PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) { static auto pm_port_request = zeek::id::find_type("pm_port_request"); - RecordVal* pr = new RecordVal(pm_port_request); + auto pr = make_intrusive(pm_port_request); pr->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); pr->Assign(1, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -226,18 +220,15 @@ Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) (void) extract_XDR_uint32(buf, len); // consume the bogus port if ( ! buf ) - { - Unref(pr); return nullptr; - } return pr; } -Val* PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) +IntrusivePtr PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) { static auto pm_callit_request = zeek::id::find_type("pm_callit_request"); - RecordVal* c = new RecordVal(pm_callit_request); + auto c = make_intrusive(pm_callit_request); c->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); c->Assign(1, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -248,10 +239,7 @@ Val* PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) c->Assign(3, val_mgr->Count(arg_n)); if ( ! buf ) - { - Unref(c); return nullptr; - } return c; } @@ -274,14 +262,10 @@ uint32_t PortmapperInterp::CheckPort(uint32_t port) return port; } -void PortmapperInterp::Event(EventHandlerPtr f, Val* request, BifEnum::rpc_status status, Val* reply) +void PortmapperInterp::Event(EventHandlerPtr f, IntrusivePtr request, BifEnum::rpc_status status, IntrusivePtr reply) { if ( ! f ) - { - Unref(request); - Unref(reply); return; - } zeek::Args vl; @@ -290,16 +274,16 @@ void PortmapperInterp::Event(EventHandlerPtr f, Val* request, BifEnum::rpc_statu if ( status == BifEnum::RPC_SUCCESS ) { if ( request ) - vl.emplace_back(AdoptRef{}, request); + vl.emplace_back(std::move(request)); if ( reply ) - vl.emplace_back(AdoptRef{}, reply); + vl.emplace_back(std::move(reply)); } else { vl.emplace_back(zeek::BifType::Enum::rpc_status->GetVal(status)); if ( request ) - vl.emplace_back(AdoptRef{}, request); + vl.emplace_back(std::move(request)); } analyzer->EnqueueConnEvent(f, std::move(vl)); diff --git a/src/analyzer/protocol/rpc/Portmap.h b/src/analyzer/protocol/rpc/Portmap.h index cf8f9be7e2..9879976c28 100644 --- a/src/analyzer/protocol/rpc/Portmap.h +++ b/src/analyzer/protocol/rpc/Portmap.h @@ -17,11 +17,11 @@ protected: double last_time, int reply_len) override; uint32_t CheckPort(uint32_t port); - void Event(EventHandlerPtr f, Val* request, BifEnum::rpc_status status, Val* reply); + void Event(EventHandlerPtr f, IntrusivePtr request, BifEnum::rpc_status status, IntrusivePtr reply); - Val* ExtractMapping(const u_char*& buf, int& len); - Val* ExtractPortRequest(const u_char*& buf, int& len); - Val* ExtractCallItRequest(const u_char*& buf, int& len); + IntrusivePtr ExtractMapping(const u_char*& buf, int& len); + IntrusivePtr ExtractPortRequest(const u_char*& buf, int& len); + IntrusivePtr ExtractCallItRequest(const u_char*& buf, int& len); }; class Portmapper_Analyzer : public RPC_Analyzer { diff --git a/src/analyzer/protocol/rpc/RPC.cc b/src/analyzer/protocol/rpc/RPC.cc index 176bc33d5a..ed3dda86e4 100644 --- a/src/analyzer/protocol/rpc/RPC.cc +++ b/src/analyzer/protocol/rpc/RPC.cc @@ -28,7 +28,6 @@ namespace { // local namespace RPC_CallInfo::RPC_CallInfo(uint32_t arg_xid, const u_char*& buf, int& n, double arg_start_time, double arg_last_time, int arg_rpc_len) { - v = nullptr; xid = arg_xid; stamp = 0; uid = 0; @@ -98,7 +97,6 @@ RPC_CallInfo::RPC_CallInfo(uint32_t arg_xid, const u_char*& buf, int& n, double RPC_CallInfo::~RPC_CallInfo() { delete [] call_buf; - Unref(v); } bool RPC_CallInfo::CompareRexmit(const u_char* buf, int n) const diff --git a/src/analyzer/protocol/rpc/RPC.h b/src/analyzer/protocol/rpc/RPC.h index a3615bebc5..7d4a75bd8e 100644 --- a/src/analyzer/protocol/rpc/RPC.h +++ b/src/analyzer/protocol/rpc/RPC.h @@ -52,9 +52,9 @@ public: double last_time, int rpc_len); ~RPC_CallInfo(); - void AddVal(Val* arg_v) { Unref(v); v = arg_v; } - Val* RequestVal() const { return v; } - Val* TakeRequestVal() { Val* rv = v; v = nullptr; return rv; } + void AddVal(IntrusivePtr arg_v) { v = std::move(arg_v); } + const IntrusivePtr& RequestVal() const { return v; } + IntrusivePtr TakeRequestVal() { auto rv = std::move(v); return rv; } bool CompareRexmit(const u_char* buf, int n) const; @@ -95,7 +95,7 @@ protected: int header_len; // size of data before the arguments bool valid_call; // whether call was well-formed - Val* v; // single (perhaps compound) value corresponding to call + IntrusivePtr v; // single (perhaps compound) value corresponding to call }; class RPC_Interpreter { From f3d160d03465fc67f891b55251d94344fe76f4c4 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Mon, 18 May 2020 23:57:57 -0700 Subject: [PATCH 083/151] Deprecate RecordVal::Assign(int, Val*) And adapt all usages to the existing overload taking IntrusivePtr. --- NEWS | 3 + src/CompHash.cc | 6 +- src/DNS_Mgr.cc | 2 +- src/Type.cc | 5 +- src/Val.h | 22 +++++ src/analyzer/protocol/dhcp/dhcp-options.pac | 8 +- .../protocol/gtpv1/gtpv1-analyzer.pac | 48 +++++----- src/analyzer/protocol/krb/krb-analyzer.pac | 42 ++++---- src/analyzer/protocol/krb/krb-padata.pac | 8 +- src/analyzer/protocol/krb/krb-types.pac | 30 +++--- .../protocol/mqtt/commands/publish.pac | 8 +- .../protocol/mqtt/commands/subscribe.pac | 6 +- .../protocol/mqtt/commands/unsubscribe.pac | 4 +- src/analyzer/protocol/ntlm/ntlm-analyzer.pac | 89 +++++++++-------- src/analyzer/protocol/ntp/ntp-analyzer.pac | 57 +++++------ .../protocol/radius/radius-analyzer.pac | 6 +- src/analyzer/protocol/snmp/snmp-analyzer.pac | 96 +++++++++---------- src/analyzer/protocol/ssh/ssh-analyzer.pac | 22 ++--- src/analyzer/protocol/ssh/ssh-protocol.pac | 10 +- src/analyzer/protocol/teredo/Teredo.cc | 8 +- src/broker/Store.cc | 4 +- src/broker/Store.h | 2 +- src/broker/comm.bif | 8 +- src/broker/data.bif | 4 +- src/file_analysis/File.cc | 17 ++-- src/file_analysis/analyzer/pe/pe-analyzer.pac | 38 ++++---- .../analyzer/unified2/unified2-analyzer.pac | 63 ++++++------ src/file_analysis/analyzer/x509/X509.cc | 24 ++--- src/file_analysis/analyzer/x509/X509.h | 2 +- src/file_analysis/analyzer/x509/functions.bif | 10 +- src/input/Manager.cc | 4 +- src/iosource/Packet.cc | 8 +- src/iosource/Packet.h | 2 +- src/logging/Manager.cc | 2 +- src/supervisor/Supervisor.cc | 6 +- src/supervisor/supervisor.bif | 2 +- src/util.cc | 8 +- src/zeek.bif | 14 +-- 38 files changed, 366 insertions(+), 332 deletions(-) diff --git a/NEWS b/NEWS index af3d71bdc2..5adb4009db 100644 --- a/NEWS +++ b/NEWS @@ -191,6 +191,9 @@ Deprecated Functionality - ``FuncType::ArgTypes()`` is deprecated, use ``FuncType::ParamList()``. +- ``RecordVal::Assign(int, Val*)`` is deprecated, use the overload taking + ``IntrusivePtr``. + Zeek 3.1.0 ========== diff --git a/src/CompHash.cc b/src/CompHash.cc index ed3b7788a0..2d3e674348 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -900,7 +900,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, RecordType* rt = t->AsRecordType(); int num_fields = rt->NumFields(); - std::vector values; + std::vector> values; int i; for ( i = 0; i < num_fields; ++i ) { @@ -922,7 +922,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, break; } - values.push_back(v.release()); + values.emplace_back(std::move(v)); } ASSERT(int(values.size()) == num_fields); @@ -930,7 +930,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, auto rv = make_intrusive(IntrusivePtr{NewRef{}, rt}); for ( int i = 0; i < num_fields; ++i ) - rv->Assign(i, values[i]); + rv->Assign(i, std::move(values[i])); *pval = std::move(rv); kp1 = kp; diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 021df5d191..44dd2cb5c5 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -724,7 +724,7 @@ IntrusivePtr DNS_Mgr::BuildMappingVal(DNS_Mapping* dm) r->Assign(3, val_mgr->Bool(dm->Valid())); auto h = dm->Host(); - r->Assign(4, h ? h.release() : new StringVal("")); + r->Assign(4, h ? std::move(h) : make_intrusive("")); r->Assign(5, dm->AddrsSet()); return r; diff --git a/src/Type.cc b/src/Type.cc index 671a98d8e6..bfa2fb6af9 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -809,9 +809,6 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const if ( rv ) fv = rv->Lookup(i); - if ( fv ) - ::Ref(fv); - bool logged = (fd->attrs && fd->FindAttr(ATTR_LOG) != nullptr); auto nr = make_intrusive(record_field); @@ -819,7 +816,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const string s = container_type_name(ft.get()); nr->Assign(0, make_intrusive(s)); nr->Assign(1, val_mgr->Bool(logged)); - nr->Assign(2, fv); + nr->Assign(2, {NewRef{}, fv}); nr->Assign(3, FieldDefault(i)); Val* field_name = new StringVal(FieldName(i)); rval->Assign(field_name, std::move(nr)); diff --git a/src/Val.h b/src/Val.h index 37323c9a2f..61d8eab0f3 100644 --- a/src/Val.h +++ b/src/Val.h @@ -945,8 +945,30 @@ public: IntrusivePtr SizeVal() const override; + /** + * Assign a value to a record field. + * @param field The field index to assign. + * @param new_val The value to assign. + */ void Assign(int field, IntrusivePtr new_val); + + /** + * Assign a value of type @c T to a record field, as constructed from + * the provided arguments. + * @param field The field index to assign. + * @param args A variable number of arguments to pass to constructor of + * type @c T. + */ + template + void Assign(int field, Ts&&... args) + { Assign(field, make_intrusive(std::forward(args)...)); } + + [[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]] void Assign(int field, Val* new_val); + // Note: the following nullptr method can also go upon removing the above. + void Assign(int field, std::nullptr_t) + { Assign(field, IntrusivePtr{}); } + Val* Lookup(int field) const; // Does not Ref() value. IntrusivePtr LookupWithDefault(int field) const; diff --git a/src/analyzer/protocol/dhcp/dhcp-options.pac b/src/analyzer/protocol/dhcp/dhcp-options.pac index 2ebb439575..a53398eabc 100644 --- a/src/analyzer/protocol/dhcp/dhcp-options.pac +++ b/src/analyzer/protocol/dhcp/dhcp-options.pac @@ -625,11 +625,11 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_client_id_option(v: OptionValue): bool %{ - RecordVal* client_id = new RecordVal(zeek::BifType::Record::DHCP::ClientID); + auto client_id = make_intrusive(zeek::BifType::Record::DHCP::ClientID); client_id->Assign(0, val_mgr->Count(${v.client_id.hwtype})); client_id->Assign(1, make_intrusive(fmt_mac(${v.client_id.hwaddr}.begin(), ${v.client_id.hwaddr}.length()))); - ${context.flow}->options->Assign(19, client_id); + ${context.flow}->options->Assign(19, std::move(client_id)); return true; %} @@ -685,14 +685,14 @@ refine casetype OptionValue += { refine flow DHCP_Flow += { function process_client_fqdn_option(v: OptionValue): bool %{ - RecordVal* client_fqdn = new RecordVal(zeek::BifType::Record::DHCP::ClientFQDN); + auto client_fqdn = make_intrusive(zeek::BifType::Record::DHCP::ClientFQDN); client_fqdn->Assign(0, val_mgr->Count(${v.client_fqdn.flags})); client_fqdn->Assign(1, val_mgr->Count(${v.client_fqdn.rcode1})); client_fqdn->Assign(2, val_mgr->Count(${v.client_fqdn.rcode2})); const char* domain_name = reinterpret_cast(${v.client_fqdn.domain_name}.begin()); client_fqdn->Assign(3, make_intrusive(${v.client_fqdn.domain_name}.length(), domain_name)); - ${context.flow}->options->Assign(21, client_fqdn); + ${context.flow}->options->Assign(21, std::move(client_fqdn)); return true; %} diff --git a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac index f4daeb8c0c..00eae1b5f1 100644 --- a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac +++ b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac @@ -83,9 +83,9 @@ static IntrusivePtr BuildTraceType(const InformationElement* ie) return val_mgr->Count(ie->trace_type()->value()); } -Val* BuildEndUserAddr(const InformationElement* ie) +IntrusivePtr BuildEndUserAddr(const InformationElement* ie) { - RecordVal* ev = new RecordVal(zeek::BifType::Record::gtp_end_user_addr); + auto ev = make_intrusive(zeek::BifType::Record::gtp_end_user_addr); ev->Assign(0, val_mgr->Count(ie->end_user_addr()->pdp_type_org())); ev->Assign(1, val_mgr->Count(ie->end_user_addr()->pdp_type_num())); @@ -114,23 +114,23 @@ Val* BuildEndUserAddr(const InformationElement* ie) return ev; } -Val* BuildAccessPointName(const InformationElement* ie) +IntrusivePtr BuildAccessPointName(const InformationElement* ie) { BroString* bs = new BroString((const u_char*) ie->ap_name()->value().data(), ie->ap_name()->value().length(), false); - return new StringVal(bs); + return make_intrusive(bs); } -Val* BuildProtoConfigOptions(const InformationElement* ie) +IntrusivePtr BuildProtoConfigOptions(const InformationElement* ie) { const u_char* d = (const u_char*) ie->proto_config_opts()->value().data(); int len = ie->proto_config_opts()->value().length(); - return new StringVal(new BroString(d, len, false)); + return make_intrusive(new BroString(d, len, false)); } -Val* BuildGSN_Addr(const InformationElement* ie) +IntrusivePtr BuildGSN_Addr(const InformationElement* ie) { - RecordVal* ev = new RecordVal(zeek::BifType::Record::gtp_gsn_addr); + auto ev = make_intrusive(zeek::BifType::Record::gtp_gsn_addr); int len = ie->gsn_addr()->value().length(); const uint8* d = ie->gsn_addr()->value().data(); @@ -147,16 +147,16 @@ Val* BuildGSN_Addr(const InformationElement* ie) return ev; } -Val* BuildMSISDN(const InformationElement* ie) +IntrusivePtr BuildMSISDN(const InformationElement* ie) { const u_char* d = (const u_char*) ie->msisdn()->value().data(); int len = ie->msisdn()->value().length(); - return new StringVal(new BroString(d, len, false)); + return make_intrusive(new BroString(d, len, false)); } -Val* BuildQoS_Profile(const InformationElement* ie) +IntrusivePtr BuildQoS_Profile(const InformationElement* ie) { - RecordVal* ev = new RecordVal(zeek::BifType::Record::gtp_qos_profile); + auto ev = make_intrusive(zeek::BifType::Record::gtp_qos_profile); const u_char* d = (const u_char*) ie->qos_profile()->data().data(); int len = ie->qos_profile()->data().length(); @@ -167,30 +167,30 @@ Val* BuildQoS_Profile(const InformationElement* ie) return ev; } -Val* BuildTrafficFlowTemplate(const InformationElement* ie) +IntrusivePtr BuildTrafficFlowTemplate(const InformationElement* ie) { const uint8* d = ie->traffic_flow_template()->value().data(); int len = ie->traffic_flow_template()->value().length(); - return new StringVal(new BroString((const u_char*) d, len, false)); + return make_intrusive(new BroString((const u_char*) d, len, false)); } -Val* BuildTriggerID(const InformationElement* ie) +IntrusivePtr BuildTriggerID(const InformationElement* ie) { const uint8* d = ie->trigger_id()->value().data(); int len = ie->trigger_id()->value().length(); - return new StringVal(new BroString((const u_char*) d, len, false)); + return make_intrusive(new BroString((const u_char*) d, len, false)); } -Val* BuildOMC_ID(const InformationElement* ie) +IntrusivePtr BuildOMC_ID(const InformationElement* ie) { const uint8* d = ie->omc_id()->value().data(); int len = ie->omc_id()->value().length(); - return new StringVal(new BroString((const u_char*) d, len, false)); + return make_intrusive(new BroString((const u_char*) d, len, false)); } -Val* BuildPrivateExt(const InformationElement* ie) +IntrusivePtr BuildPrivateExt(const InformationElement* ie) { - RecordVal* ev = new RecordVal(zeek::BifType::Record::gtp_private_extension); + auto ev = make_intrusive(zeek::BifType::Record::gtp_private_extension); const uint8* d = ie->private_ext()->value().data(); int len = ie->private_ext()->value().length(); @@ -216,16 +216,16 @@ static IntrusivePtr BuildChargingID(const InformationElement* ie) return val_mgr->Count(ie->charging_id()->value());; } -Val* BuildChargingGatewayAddr(const InformationElement* ie) +IntrusivePtr BuildChargingGatewayAddr(const InformationElement* ie) { const uint8* d = ie->charging_gateway_addr()->value().data(); int len = ie->charging_gateway_addr()->value().length(); if ( len == 4 ) - return new AddrVal(IPAddr(IPv4, (const uint32*) d, IPAddr::Network)); + return make_intrusive(IPAddr(IPv4, (const uint32*) d, IPAddr::Network)); else if ( len == 16 ) - return new AddrVal(IPAddr(IPv6, (const uint32*) d, IPAddr::Network)); + return make_intrusive(IPAddr(IPv6, (const uint32*) d, IPAddr::Network)); else - return 0; + return nullptr; } static IntrusivePtr BuildTeardownInd(const InformationElement* ie) diff --git a/src/analyzer/protocol/krb/krb-analyzer.pac b/src/analyzer/protocol/krb/krb-analyzer.pac index ebc07a0f3a..f3c6782361 100644 --- a/src/analyzer/protocol/krb/krb-analyzer.pac +++ b/src/analyzer/protocol/krb/krb-analyzer.pac @@ -1,14 +1,14 @@ %header{ -RecordVal* proc_krb_kdc_options(const KRB_KDC_Options* opts); -RecordVal* proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer); +IntrusivePtr proc_krb_kdc_options(const KRB_KDC_Options* opts); +IntrusivePtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer); bool proc_error_arguments(RecordVal* rv, const std::vector* args, int64 error_code); %} %code{ -RecordVal* proc_krb_kdc_options(const KRB_KDC_Options* opts) +IntrusivePtr proc_krb_kdc_options(const KRB_KDC_Options* opts) { - RecordVal* rv = new RecordVal(zeek::BifType::Record::KRB::KDC_Options); + auto rv = make_intrusive(zeek::BifType::Record::KRB::KDC_Options); rv->Assign(0, val_mgr->Bool(opts->forwardable())); rv->Assign(1, val_mgr->Bool(opts->forwarded())); @@ -27,12 +27,12 @@ RecordVal* proc_krb_kdc_options(const KRB_KDC_Options* opts) return rv; } -RecordVal* proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer) +IntrusivePtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer) { - RecordVal* rv = new RecordVal(zeek::BifType::Record::KRB::KDC_Request); + auto rv = make_intrusive(zeek::BifType::Record::KRB::KDC_Request); - rv->Assign(0, asn1_integer_to_val(msg->pvno()->data(), TYPE_COUNT)); - rv->Assign(1, asn1_integer_to_val(msg->msg_type()->data(), TYPE_COUNT)); + rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(msg->pvno()->data(), TYPE_COUNT)}); + rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(msg->msg_type()->data(), TYPE_COUNT)}); if ( msg->padata()->has_padata() ) rv->Assign(2, proc_padata(msg->padata()->padata()->padata(), bro_analyzer, false)); @@ -64,7 +64,7 @@ RecordVal* proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_an rv->Assign(9, GetTimeFromAsn1(element->data()->rtime(), 0)); break; case 7: - rv->Assign(10, asn1_integer_to_val(element->data()->nonce(), TYPE_COUNT)); + rv->Assign(10, {AdoptRef{}, asn1_integer_to_val(element->data()->nonce(), TYPE_COUNT)}); break; case 8: if ( element->data()->etype()->data()->size() ) @@ -132,10 +132,10 @@ bool proc_error_arguments(RecordVal* rv, const std::vector* args switch ( (*args)[i]->seq_meta()->index() ) { case 0: - rv->Assign(0, asn1_integer_to_val((*args)[i]->args()->pvno(), TYPE_COUNT)); + rv->Assign(0, {AdoptRef{}, asn1_integer_to_val((*args)[i]->args()->pvno(), TYPE_COUNT)}); break; case 1: - rv->Assign(1, asn1_integer_to_val((*args)[i]->args()->msg_type(), TYPE_COUNT)); + rv->Assign(1, {AdoptRef{}, asn1_integer_to_val((*args)[i]->args()->msg_type(), TYPE_COUNT)}); break; // ctime/stime handled above case 7: @@ -179,8 +179,8 @@ refine connection KRB_Conn += { if ( ! krb_as_request ) return false; - RecordVal* rv = proc_krb_kdc_req_arguments(${msg}, bro_analyzer()); - zeek::BifEvent::enqueue_krb_as_request(bro_analyzer(), bro_analyzer()->Conn(), {AdoptRef{}, rv}); + auto rv = proc_krb_kdc_req_arguments(${msg}, bro_analyzer()); + zeek::BifEvent::enqueue_krb_as_request(bro_analyzer(), bro_analyzer()->Conn(), std::move(rv)); return true; } @@ -189,8 +189,8 @@ refine connection KRB_Conn += { if ( ! krb_tgs_request ) return false; - RecordVal* rv = proc_krb_kdc_req_arguments(${msg}, bro_analyzer()); - zeek::BifEvent::enqueue_krb_tgs_request(bro_analyzer(), bro_analyzer()->Conn(), {AdoptRef{}, rv}); + auto rv = proc_krb_kdc_req_arguments(${msg}, bro_analyzer()); + zeek::BifEvent::enqueue_krb_tgs_request(bro_analyzer(), bro_analyzer()->Conn(), std::move(rv)); return true; } @@ -205,8 +205,8 @@ refine connection KRB_Conn += { { auto rv = make_intrusive(zeek::BifType::Record::KRB::KDC_Response); - rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)); - rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)); + rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)}); + rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)}); if ( ${msg.padata.has_padata} ) rv->Assign(2, proc_padata(${msg.padata.padata.padata}, bro_analyzer(), false)); @@ -246,7 +246,7 @@ refine connection KRB_Conn += { { auto rv = make_intrusive(zeek::BifType::Record::KRB::Error_Msg); proc_error_arguments(rv.get(), ${msg.args1}, 0); - rv->Assign(4, asn1_integer_to_val(${msg.error_code}, TYPE_COUNT)); + rv->Assign(4, {AdoptRef{}, asn1_integer_to_val(${msg.error_code}, TYPE_COUNT)}); proc_error_arguments(rv.get(), ${msg.args2}, binary_to_int64(${msg.error_code.encoding.content})); zeek::BifEvent::enqueue_krb_error(bro_analyzer(), bro_analyzer()->Conn(), std::move(rv)); } @@ -291,8 +291,8 @@ refine connection KRB_Conn += { { auto rv = make_intrusive(zeek::BifType::Record::KRB::SAFE_Msg); - rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)); - rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)); + rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)}); + rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)}); uint timestamp_i = 0; int64 timestamp_usecs = 0; @@ -325,7 +325,7 @@ refine connection KRB_Conn += { rv->Assign(3, to_stringval(${msg.safe_body.args[i].args.user_data.encoding.content})); break; case 3: - rv->Assign(5, asn1_integer_to_val(${msg.safe_body.args[i].args.seq_number}, TYPE_COUNT)); + rv->Assign(5, {AdoptRef{}, asn1_integer_to_val(${msg.safe_body.args[i].args.seq_number}, TYPE_COUNT)}); break; case 4: rv->Assign(6, proc_host_address(bro_analyzer(), ${msg.safe_body.args[i].args.sender_addr})); diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index a3c5d55741..5617e48fb6 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -7,16 +7,16 @@ %} %header{ -VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error); +IntrusivePtr proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error); %} %code{ -VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) +IntrusivePtr proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) { auto vv = make_intrusive(zeek::id::find_type("KRB::Type_Value_Vector")); if ( ! data->data()->has_padata() ) - return vv.release(); + return vv; for ( uint i = 0; i < data->data()->padata_elems()->size(); ++i) { @@ -119,7 +119,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a } } } - return vv.release(); + return vv; } %} diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index 4a53fca79e..4f1942854d 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -3,10 +3,10 @@ %header{ IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pname); -VectorVal* proc_cipher_list(const Array* list); +IntrusivePtr proc_cipher_list(const Array* list); -VectorVal* proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list); -RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr); +IntrusivePtr proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list); +IntrusivePtr proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr); IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list); IntrusivePtr proc_ticket(const KRB_Ticket* ticket); @@ -25,15 +25,15 @@ IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pname) return make_intrusive("unknown"); } -VectorVal* proc_cipher_list(const Array* list) +IntrusivePtr proc_cipher_list(const Array* list) { auto ciphers = make_intrusive(zeek::id::index_vec); for ( uint i = 0; i < list->data()->size(); ++i ) - ciphers->Assign(ciphers->Size(), asn1_integer_to_val((*list->data())[i], TYPE_COUNT)); - return ciphers.release(); + ciphers->Assign(ciphers->Size(), {AdoptRef{}, asn1_integer_to_val((*list->data())[i], TYPE_COUNT)}); + return ciphers; } -VectorVal* proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) +IntrusivePtr proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) { auto addrs = make_intrusive(zeek::id::find_type("KRB::Host_Address_Vector")); @@ -42,12 +42,12 @@ VectorVal* proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* addrs->Assign(addrs->Size(), proc_host_address(a, (*list->addresses())[i])); } - return addrs.release(); + return addrs; } -RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) +IntrusivePtr proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) { - RecordVal* rv = new RecordVal(zeek::BifType::Record::KRB::Host_Address); + auto rv = make_intrusive(zeek::BifType::Record::KRB::Host_Address); const auto& addr_bytes = addr->address()->data()->content(); switch ( binary_to_int64(addr->addr_type()->encoding()->content()) ) @@ -85,10 +85,10 @@ RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) break; } - RecordVal* unk = new RecordVal(zeek::BifType::Record::KRB::Type_Value); - unk->Assign(0, asn1_integer_to_val(addr->addr_type(), TYPE_COUNT)); + auto unk = make_intrusive(zeek::BifType::Record::KRB::Type_Value); + unk->Assign(0, {AdoptRef{}, asn1_integer_to_val(addr->addr_type(), TYPE_COUNT)}); unk->Assign(1, to_stringval(addr_bytes)); - rv->Assign(2, unk); + rv->Assign(2, std::move(unk)); return rv; } @@ -109,10 +109,10 @@ IntrusivePtr proc_ticket(const KRB_Ticket* ticket) { auto rv = make_intrusive(zeek::BifType::Record::KRB::Ticket); - rv->Assign(0, asn1_integer_to_val(ticket->tkt_vno()->data(), TYPE_COUNT)); + rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(ticket->tkt_vno()->data(), TYPE_COUNT)}); rv->Assign(1, to_stringval(ticket->realm()->data()->content())); rv->Assign(2, GetStringFromPrincipalName(ticket->sname())); - rv->Assign(3, asn1_integer_to_val(ticket->enc_part()->data()->etype()->data(), TYPE_COUNT)); + rv->Assign(3, {AdoptRef{}, asn1_integer_to_val(ticket->enc_part()->data()->etype()->data(), TYPE_COUNT)}); rv->Assign(4, to_stringval(ticket->enc_part()->data()->ciphertext()->encoding()->content())); return rv; diff --git a/src/analyzer/protocol/mqtt/commands/publish.pac b/src/analyzer/protocol/mqtt/commands/publish.pac index d8211be638..cd7ceef2b3 100644 --- a/src/analyzer/protocol/mqtt/commands/publish.pac +++ b/src/analyzer/protocol/mqtt/commands/publish.pac @@ -27,8 +27,8 @@ refine flow MQTT_Flow += { m->Assign(0, val_mgr->Bool(${msg.dup})); m->Assign(1, val_mgr->Count(${msg.qos})); m->Assign(2, val_mgr->Bool(${msg.retain})); - m->Assign(3, new StringVal(${msg.topic.str}.length(), - reinterpret_cast(${msg.topic.str}.begin()))); + m->Assign(3, ${msg.topic.str}.length(), + reinterpret_cast(${msg.topic.str}.begin())); auto len = ${msg.payload}.length(); static auto max_payload_size = zeek::id::find("MQTT::max_payload_size"); @@ -37,8 +37,8 @@ refine flow MQTT_Flow += { if ( len > static_cast(max) ) len = max; - m->Assign(4, new StringVal(len, - reinterpret_cast(${msg.payload}.begin()))); + m->Assign(4, len, + reinterpret_cast(${msg.payload}.begin())); m->Assign(5, val_mgr->Count(${msg.payload}.length())); diff --git a/src/analyzer/protocol/mqtt/commands/subscribe.pac b/src/analyzer/protocol/mqtt/commands/subscribe.pac index 75015bffc7..755101b41f 100644 --- a/src/analyzer/protocol/mqtt/commands/subscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/subscribe.pac @@ -24,11 +24,11 @@ refine flow MQTT_Flow += { for ( auto topic: *${msg.topics} ) { - auto subscribe_topic = new StringVal(${topic.name.str}.length(), + auto subscribe_topic = make_intrusive(${topic.name.str}.length(), reinterpret_cast(${topic.name.str}.begin())); auto qos = val_mgr->Count(${topic.requested_QoS}); - topics->Assign(topics->Size(), subscribe_topic); - qos_levels->Assign(qos_levels->Size(), qos); + topics->Assign(topics->Size(), std::move(subscribe_topic)); + qos_levels->Assign(qos_levels->Size(), std::move(qos)); } zeek::BifEvent::enqueue_mqtt_subscribe(connection()->bro_analyzer(), diff --git a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac index 45f68f8d8b..944e005c7b 100644 --- a/src/analyzer/protocol/mqtt/commands/unsubscribe.pac +++ b/src/analyzer/protocol/mqtt/commands/unsubscribe.pac @@ -18,9 +18,9 @@ refine flow MQTT_Flow += { for ( auto topic: *${msg.topics} ) { - auto unsubscribe_topic = new StringVal(${topic.str}.length(), + auto unsubscribe_topic = make_intrusive(${topic.str}.length(), reinterpret_cast(${topic.str}.begin())); - topics->Assign(topics->Size(), unsubscribe_topic); + topics->Assign(topics->Size(), std::move(unsubscribe_topic)); } zeek::BifEvent::enqueue_mqtt_unsubscribe(connection()->bro_analyzer(), diff --git a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac index c95e90982d..46a7396e45 100644 --- a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac +++ b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac @@ -1,28 +1,64 @@ +%header{ + IntrusivePtr filetime2brotime(uint64_t ts); + IntrusivePtr build_version_record(NTLM_Version* val); + IntrusivePtr build_negotiate_flag_record(NTLM_Negotiate_Flags* val); +%} -refine connection NTLM_Conn += { - - # This is replicated from the SMB analyzer. :( - function filetime2brotime(ts: uint64): Val - %{ +%code{ + // This is replicated from the SMB analyzer. :( + IntrusivePtr filetime2brotime(uint64_t ts) + { double secs = (ts / 10000000.0); // Bro can't support times back to the 1600's // so we subtract a lot of seconds. - Val* bro_ts = new Val(secs - 11644473600.0, TYPE_TIME); + auto bro_ts = make_intrusive(secs - 11644473600.0, TYPE_TIME); return bro_ts; - %} + } - function build_version_record(val: NTLM_Version): BroVal - %{ - RecordVal* result = new RecordVal(zeek::BifType::Record::NTLM::Version); + IntrusivePtr build_version_record(NTLM_Version* val) + { + auto result = make_intrusive(zeek::BifType::Record::NTLM::Version); result->Assign(0, val_mgr->Count(${val.major_version})); result->Assign(1, val_mgr->Count(${val.minor_version})); result->Assign(2, val_mgr->Count(${val.build_number})); result->Assign(3, val_mgr->Count(${val.ntlm_revision})); return result; - %} + } + + IntrusivePtr build_negotiate_flag_record(NTLM_Negotiate_Flags* val) + { + auto flags = make_intrusive(zeek::BifType::Record::NTLM::NegotiateFlags); + flags->Assign(0, val_mgr->Bool(${val.negotiate_56})); + flags->Assign(1, val_mgr->Bool(${val.negotiate_key_exch})); + flags->Assign(2, val_mgr->Bool(${val.negotiate_128})); + flags->Assign(3, val_mgr->Bool(${val.negotiate_version})); + flags->Assign(4, val_mgr->Bool(${val.negotiate_target_info})); + flags->Assign(5, val_mgr->Bool(${val.request_non_nt_session_key})); + flags->Assign(6, val_mgr->Bool(${val.negotiate_identify})); + flags->Assign(7, val_mgr->Bool(${val.negotiate_extended_sessionsecurity})); + flags->Assign(8, val_mgr->Bool(${val.target_type_server})); + flags->Assign(9, val_mgr->Bool(${val.target_type_domain})); + flags->Assign(10, val_mgr->Bool(${val.negotiate_always_sign})); + flags->Assign(11, val_mgr->Bool(${val.negotiate_oem_workstation_supplied})); + flags->Assign(12, val_mgr->Bool(${val.negotiate_oem_domain_supplied})); + flags->Assign(13, val_mgr->Bool(${val.negotiate_anonymous_connection})); + flags->Assign(14, val_mgr->Bool(${val.negotiate_ntlm})); + flags->Assign(15, val_mgr->Bool(${val.negotiate_lm_key})); + flags->Assign(16, val_mgr->Bool(${val.negotiate_datagram})); + flags->Assign(17, val_mgr->Bool(${val.negotiate_seal})); + flags->Assign(18, val_mgr->Bool(${val.negotiate_sign})); + flags->Assign(19, val_mgr->Bool(${val.request_target})); + flags->Assign(20, val_mgr->Bool(${val.negotiate_oem})); + flags->Assign(21, val_mgr->Bool(${val.negotiate_unicode})); + + return flags; + } +%} + +refine connection NTLM_Conn += { function build_av_record(val: NTLM_AV_Pair_Sequence, len: uint16): BroVal %{ @@ -76,35 +112,6 @@ refine connection NTLM_Conn += { return result; %} - function build_negotiate_flag_record(val: NTLM_Negotiate_Flags): BroVal - %{ - RecordVal* flags = new RecordVal(zeek::BifType::Record::NTLM::NegotiateFlags); - flags->Assign(0, val_mgr->Bool(${val.negotiate_56})); - flags->Assign(1, val_mgr->Bool(${val.negotiate_key_exch})); - flags->Assign(2, val_mgr->Bool(${val.negotiate_128})); - flags->Assign(3, val_mgr->Bool(${val.negotiate_version})); - flags->Assign(4, val_mgr->Bool(${val.negotiate_target_info})); - flags->Assign(5, val_mgr->Bool(${val.request_non_nt_session_key})); - flags->Assign(6, val_mgr->Bool(${val.negotiate_identify})); - flags->Assign(7, val_mgr->Bool(${val.negotiate_extended_sessionsecurity})); - flags->Assign(8, val_mgr->Bool(${val.target_type_server})); - flags->Assign(9, val_mgr->Bool(${val.target_type_domain})); - flags->Assign(10, val_mgr->Bool(${val.negotiate_always_sign})); - flags->Assign(11, val_mgr->Bool(${val.negotiate_oem_workstation_supplied})); - flags->Assign(12, val_mgr->Bool(${val.negotiate_oem_domain_supplied})); - flags->Assign(13, val_mgr->Bool(${val.negotiate_anonymous_connection})); - flags->Assign(14, val_mgr->Bool(${val.negotiate_ntlm})); - flags->Assign(15, val_mgr->Bool(${val.negotiate_lm_key})); - flags->Assign(16, val_mgr->Bool(${val.negotiate_datagram})); - flags->Assign(17, val_mgr->Bool(${val.negotiate_seal})); - flags->Assign(18, val_mgr->Bool(${val.negotiate_sign})); - flags->Assign(19, val_mgr->Bool(${val.request_target})); - flags->Assign(20, val_mgr->Bool(${val.negotiate_oem})); - flags->Assign(21, val_mgr->Bool(${val.negotiate_unicode})); - - return flags; - %} - function proc_ntlm_negotiate(val: NTLM_Negotiate): bool %{ if ( ! ntlm_negotiate ) @@ -144,7 +151,7 @@ refine connection NTLM_Conn += { result->Assign(2, build_version_record(${val.version})); if ( ${val}->has_target_info() ) - result->Assign(3, build_av_record(${val.target_info}, ${val.target_info_fields.length})); + result->Assign(3, {AdoptRef{}, build_av_record(${val.target_info}, ${val.target_info_fields.length})}); zeek::BifEvent::enqueue_ntlm_challenge(bro_analyzer(), bro_analyzer()->Conn(), diff --git a/src/analyzer/protocol/ntp/ntp-analyzer.pac b/src/analyzer/protocol/ntp/ntp-analyzer.pac index 35e776c3a9..bd9af501d1 100644 --- a/src/analyzer/protocol/ntp/ntp-analyzer.pac +++ b/src/analyzer/protocol/ntp/ntp-analyzer.pac @@ -8,34 +8,33 @@ %} %header{ - Val* proc_ntp_short(const NTP_Short_Time* t); - Val* proc_ntp_timestamp(const NTP_Time* t); + IntrusivePtr proc_ntp_short(const NTP_Short_Time* t); + IntrusivePtr proc_ntp_timestamp(const NTP_Time* t); + IntrusivePtr BuildNTPStdMsg(NTP_std_msg* nsm); + IntrusivePtr BuildNTPControlMsg(NTP_control_msg* ncm); + IntrusivePtr BuildNTPMode7Msg(NTP_mode7_msg* m7); %} %code{ - Val* proc_ntp_short(const NTP_Short_Time* t) + IntrusivePtr proc_ntp_short(const NTP_Short_Time* t) { if ( t->seconds() == 0 && t->fractions() == 0 ) - return new Val(0.0, TYPE_INTERVAL); - return new Val(t->seconds() + t->fractions()*FRAC_16, TYPE_INTERVAL); + return make_intrusive(0.0, TYPE_INTERVAL); + return make_intrusive(t->seconds() + t->fractions()*FRAC_16, TYPE_INTERVAL); } - Val* proc_ntp_timestamp(const NTP_Time* t) + IntrusivePtr proc_ntp_timestamp(const NTP_Time* t) { if ( t->seconds() == 0 && t->fractions() == 0) - return new Val(0.0, TYPE_TIME); - return new Val(EPOCH_OFFSET + t->seconds() + t->fractions()*FRAC_32, TYPE_TIME); + return make_intrusive(0.0, TYPE_TIME); + return make_intrusive(EPOCH_OFFSET + t->seconds() + t->fractions()*FRAC_32, TYPE_TIME); } -%} - -refine flow NTP_Flow += { - - # This builds the standard msg record - function BuildNTPStdMsg(nsm: NTP_std_msg): BroVal - %{ - RecordVal* rv = new RecordVal(zeek::BifType::Record::NTP::StandardMessage); + // This builds the standard msg record + IntrusivePtr BuildNTPStdMsg(NTP_std_msg* nsm) + { + auto rv = make_intrusive(zeek::BifType::Record::NTP::StandardMessage); rv->Assign(0, val_mgr->Count(${nsm.stratum})); rv->Assign(1, make_intrusive(pow(2, ${nsm.poll}), TYPE_INTERVAL)); @@ -83,12 +82,12 @@ refine flow NTP_Flow += { } return rv; - %} + } - # This builds the control msg record - function BuildNTPControlMsg(ncm: NTP_control_msg): BroVal - %{ - RecordVal* rv = new RecordVal(zeek::BifType::Record::NTP::ControlMessage); + // This builds the control msg record + IntrusivePtr BuildNTPControlMsg(NTP_control_msg* ncm) + { + auto rv = make_intrusive(zeek::BifType::Record::NTP::ControlMessage); rv->Assign(0, val_mgr->Count(${ncm.OpCode})); rv->Assign(1, val_mgr->Bool(${ncm.R})); @@ -108,12 +107,12 @@ refine flow NTP_Flow += { } return rv; - %} + } - # This builds the mode7 msg record - function BuildNTPMode7Msg(m7: NTP_mode7_msg): BroVal - %{ - RecordVal* rv = new RecordVal(zeek::BifType::Record::NTP::Mode7Message); + // This builds the mode7 msg record + IntrusivePtr BuildNTPMode7Msg(NTP_mode7_msg* m7) + { + auto rv = make_intrusive(zeek::BifType::Record::NTP::Mode7Message); rv->Assign(0, val_mgr->Count(${m7.request_code})); rv->Assign(1, val_mgr->Bool(${m7.auth_bit})); @@ -125,7 +124,11 @@ refine flow NTP_Flow += { rv->Assign(5, to_stringval(${m7.data})); return rv; - %} + } +%} + + +refine flow NTP_Flow += { function proc_ntp_message(msg: NTP_PDU): bool diff --git a/src/analyzer/protocol/radius/radius-analyzer.pac b/src/analyzer/protocol/radius/radius-analyzer.pac index 4bb6d006b4..cf1548bd2f 100644 --- a/src/analyzer/protocol/radius/radius-analyzer.pac +++ b/src/analyzer/protocol/radius/radius-analyzer.pac @@ -14,7 +14,7 @@ refine flow RADIUS_Flow += { if ( ${msg.attributes}->size() ) { - TableVal* attributes = new TableVal(zeek::BifType::Table::RADIUS::Attributes); + auto attributes = make_intrusive(zeek::BifType::Table::RADIUS::Attributes); for ( uint i = 0; i < ${msg.attributes}->size(); ++i ) { @@ -38,8 +38,8 @@ refine flow RADIUS_Flow += { } } - result->Assign(3, attributes); - } + result->Assign(3, std::move(attributes)); + } zeek::BifEvent::enqueue_radius_message(connection()->bro_analyzer(), connection()->bro_analyzer()->Conn(), std::move(result)); return true; diff --git a/src/analyzer/protocol/snmp/snmp-analyzer.pac b/src/analyzer/protocol/snmp/snmp-analyzer.pac index 504a525440..ad31e0ef8a 100644 --- a/src/analyzer/protocol/snmp/snmp-analyzer.pac +++ b/src/analyzer/protocol/snmp/snmp-analyzer.pac @@ -8,13 +8,13 @@ %} %header{ -AddrVal* network_address_to_val(const ASN1Encoding* na); -AddrVal* network_address_to_val(const NetworkAddress* na); -Val* asn1_obj_to_val(const ASN1Encoding* obj); +IntrusivePtr network_address_to_val(const ASN1Encoding* na); +IntrusivePtr network_address_to_val(const NetworkAddress* na); +IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj); IntrusivePtr build_hdr(const Header* header); -RecordVal* build_hdrV3(const Header* header); -VectorVal* build_bindings(const VarBindList* vbl); +IntrusivePtr build_hdrV3(const Header* header); +IntrusivePtr build_bindings(const VarBindList* vbl); IntrusivePtr build_pdu(const CommonPDU* pdu); IntrusivePtr build_trap_pdu(const TrapPDU* pdu); IntrusivePtr build_bulk_pdu(const GetBulkRequestPDU* pdu); @@ -22,12 +22,12 @@ IntrusivePtr build_bulk_pdu(const GetBulkRequestPDU* pdu); %code{ -AddrVal* network_address_to_val(const NetworkAddress* na) +IntrusivePtr network_address_to_val(const NetworkAddress* na) { return network_address_to_val(na->encoding()); } -AddrVal* network_address_to_val(const ASN1Encoding* na) +IntrusivePtr network_address_to_val(const ASN1Encoding* na) { bytestring const& bs = na->content(); @@ -35,16 +35,16 @@ AddrVal* network_address_to_val(const ASN1Encoding* na) // but standards don't seem to currently make any provisions for IPv6, // so ignore anything that can't be IPv4. if ( bs.length() != 4 ) - return new AddrVal(IPAddr()); + return make_intrusive(IPAddr()); const u_char* data = reinterpret_cast(bs.data()); uint32 network_order = extract_uint32(data); - return new AddrVal(ntohl(network_order)); + return make_intrusive(ntohl(network_order)); } -Val* asn1_obj_to_val(const ASN1Encoding* obj) +IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj) { - RecordVal* rval = new RecordVal(zeek::BifType::Record::SNMP::ObjectValue); + IntrusivePtr rval = make_intrusive(zeek::BifType::Record::SNMP::ObjectValue); uint8 tag = obj->meta()->tag(); rval->Assign(0, val_mgr->Count(tag)); @@ -57,18 +57,18 @@ Val* asn1_obj_to_val(const ASN1Encoding* obj) break; case ASN1_OBJECT_IDENTIFIER_TAG: - rval->Assign(1, asn1_oid_to_val(obj)); + rval->Assign(1, {AdoptRef{}, asn1_oid_to_val(obj)}); break; case ASN1_INTEGER_TAG: - rval->Assign(2, asn1_integer_to_val(obj, TYPE_INT)); + rval->Assign(2, {AdoptRef{}, asn1_integer_to_val(obj, TYPE_INT)}); break; case APP_COUNTER32_TAG: case APP_UNSIGNED32_TAG: case APP_TIMETICKS_TAG: case APP_COUNTER64_TAG: - rval->Assign(3, asn1_integer_to_val(obj, TYPE_COUNT)); + rval->Assign(3, {AdoptRef{}, asn1_integer_to_val(obj, TYPE_COUNT)}); break; case APP_IPADDRESS_TAG: @@ -78,16 +78,16 @@ Val* asn1_obj_to_val(const ASN1Encoding* obj) case ASN1_OCTET_STRING_TAG: case APP_OPAQUE_TAG: default: - rval->Assign(5, asn1_octet_string_to_val(obj)); + rval->Assign(5, {AdoptRef{}, asn1_octet_string_to_val(obj)}); break; } return rval; } -Val* time_ticks_to_val(const TimeTicks* tt) +IntrusivePtr time_ticks_to_val(const TimeTicks* tt) { - return asn1_integer_to_val(tt->asn1_integer(), TYPE_COUNT); + return {AdoptRef{}, asn1_integer_to_val(tt->asn1_integer(), TYPE_COUNT)}; } IntrusivePtr build_hdr(const Header* header) @@ -98,17 +98,17 @@ IntrusivePtr build_hdr(const Header* header) switch ( header->version() ) { case SNMPV1_TAG: { - RecordVal* v1 = new RecordVal(zeek::BifType::Record::SNMP::HeaderV1); - v1->Assign(0, asn1_octet_string_to_val(header->v1()->community())); - rv->Assign(1, v1); + auto v1 = make_intrusive(zeek::BifType::Record::SNMP::HeaderV1); + v1->Assign(0, {AdoptRef{}, asn1_octet_string_to_val(header->v1()->community())}); + rv->Assign(1, std::move(v1)); } break; case SNMPV2_TAG: { - RecordVal* v2 = new RecordVal(zeek::BifType::Record::SNMP::HeaderV2); - v2->Assign(0, asn1_octet_string_to_val(header->v2()->community())); - rv->Assign(2, v2); + auto v2 = make_intrusive(zeek::BifType::Record::SNMP::HeaderV2); + v2->Assign(0, {AdoptRef{}, asn1_octet_string_to_val(header->v2()->community())}); + rv->Assign(2, std::move(v2)); } break; @@ -122,59 +122,57 @@ IntrusivePtr build_hdr(const Header* header) return rv; } -RecordVal* build_hdrV3(const Header* header) +IntrusivePtr build_hdrV3(const Header* header) { - RecordVal* v3 = new RecordVal(zeek::BifType::Record::SNMP::HeaderV3); + auto v3 = make_intrusive(zeek::BifType::Record::SNMP::HeaderV3); const v3Header* v3hdr = header->v3(); const v3HeaderData* global_data = v3hdr->global_data(); bytestring const& flags = global_data->flags()->encoding()->content(); uint8 flags_byte = flags.length() > 0 ? flags[0] : 0; - v3->Assign(0, asn1_integer_to_val(global_data->id(), TYPE_COUNT)); - v3->Assign(1, asn1_integer_to_val(global_data->max_size(), - TYPE_COUNT)); + v3->Assign(0, {AdoptRef{}, asn1_integer_to_val(global_data->id(), TYPE_COUNT)}); + v3->Assign(1, {AdoptRef{}, asn1_integer_to_val(global_data->max_size(), TYPE_COUNT)}); v3->Assign(2, val_mgr->Count(flags_byte)); v3->Assign(3, val_mgr->Bool(flags_byte & 0x01)); v3->Assign(4, val_mgr->Bool(flags_byte & 0x02)); v3->Assign(5, val_mgr->Bool(flags_byte & 0x04)); - v3->Assign(6, asn1_integer_to_val(global_data->security_model(), - TYPE_COUNT)); - v3->Assign(7, asn1_octet_string_to_val(v3hdr->security_parameters())); + v3->Assign(6, {AdoptRef{}, asn1_integer_to_val(global_data->security_model(), TYPE_COUNT)}); + v3->Assign(7, {AdoptRef{}, asn1_octet_string_to_val(v3hdr->security_parameters())}); if ( v3hdr->next()->tag() == ASN1_SEQUENCE_TAG ) { const v3ScopedPDU* spdu = v3hdr->plaintext_pdu(); - RecordVal* rv = new RecordVal(zeek::BifType::Record::SNMP::ScopedPDU_Context); - rv->Assign(0, asn1_octet_string_to_val(spdu->context_engine_id())); - rv->Assign(1, asn1_octet_string_to_val(spdu->context_name())); - v3->Assign(8, rv); + auto rv = make_intrusive(zeek::BifType::Record::SNMP::ScopedPDU_Context); + rv->Assign(0, {AdoptRef{}, asn1_octet_string_to_val(spdu->context_engine_id())}); + rv->Assign(1, {AdoptRef{}, asn1_octet_string_to_val(spdu->context_name())}); + v3->Assign(8, std::move(rv)); } return v3; } -VectorVal* build_bindings(const VarBindList* vbl) +IntrusivePtr build_bindings(const VarBindList* vbl) { auto vv = make_intrusive(zeek::BifType::Vector::SNMP::Bindings); for ( size_t i = 0; i < vbl->bindings()->size(); ++i ) { VarBind* vb = (*vbl->bindings())[i]; - RecordVal* binding = new RecordVal(zeek::BifType::Record::SNMP::Binding); - binding->Assign(0, asn1_oid_to_val(vb->name()->oid())); + auto binding = make_intrusive(zeek::BifType::Record::SNMP::Binding); + binding->Assign(0, {AdoptRef{}, asn1_oid_to_val(vb->name()->oid())}); binding->Assign(1, asn1_obj_to_val(vb->value()->encoding())); - vv->Assign(i, binding); + vv->Assign(i, std::move(binding)); } - return vv.release(); + return vv; } IntrusivePtr build_pdu(const CommonPDU* pdu) { auto rv = make_intrusive(zeek::BifType::Record::SNMP::PDU); - rv->Assign(0, asn1_integer_to_val(pdu->request_id(), TYPE_INT)); - rv->Assign(1, asn1_integer_to_val(pdu->error_status(), TYPE_INT)); - rv->Assign(2, asn1_integer_to_val(pdu->error_index(), TYPE_INT)); + rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(pdu->request_id(), TYPE_INT)}); + rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(pdu->error_status(), TYPE_INT)}); + rv->Assign(2, {AdoptRef{}, asn1_integer_to_val(pdu->error_index(), TYPE_INT)}); rv->Assign(3, build_bindings(pdu->var_bindings())); return rv; } @@ -182,10 +180,10 @@ IntrusivePtr build_pdu(const CommonPDU* pdu) IntrusivePtr build_trap_pdu(const TrapPDU* pdu) { auto rv = make_intrusive(zeek::BifType::Record::SNMP::TrapPDU); - rv->Assign(0, asn1_oid_to_val(pdu->enterprise())); + rv->Assign(0, {AdoptRef{}, asn1_oid_to_val(pdu->enterprise())}); rv->Assign(1, network_address_to_val(pdu->agent_addr())); - rv->Assign(2, asn1_integer_to_val(pdu->generic_trap(), TYPE_INT)); - rv->Assign(3, asn1_integer_to_val(pdu->specific_trap(), TYPE_INT)); + rv->Assign(2, {AdoptRef{}, asn1_integer_to_val(pdu->generic_trap(), TYPE_INT)}); + rv->Assign(3, {AdoptRef{}, asn1_integer_to_val(pdu->specific_trap(), TYPE_INT)}); rv->Assign(4, time_ticks_to_val(pdu->time_stamp())); rv->Assign(5, build_bindings(pdu->var_bindings())); return rv; @@ -194,9 +192,9 @@ IntrusivePtr build_trap_pdu(const TrapPDU* pdu) IntrusivePtr build_bulk_pdu(const GetBulkRequestPDU* pdu) { auto rv = make_intrusive(zeek::BifType::Record::SNMP::BulkPDU); - rv->Assign(0, asn1_integer_to_val(pdu->request_id(), TYPE_INT)); - rv->Assign(1, asn1_integer_to_val(pdu->non_repeaters(), TYPE_COUNT)); - rv->Assign(2, asn1_integer_to_val(pdu->max_repititions(), TYPE_COUNT)); + rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(pdu->request_id(), TYPE_INT)}); + rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(pdu->non_repeaters(), TYPE_COUNT)}); + rv->Assign(2, {AdoptRef{}, asn1_integer_to_val(pdu->max_repititions(), TYPE_COUNT)}); rv->Assign(3, build_bindings(pdu->var_bindings())); return rv; } diff --git a/src/analyzer/protocol/ssh/ssh-analyzer.pac b/src/analyzer/protocol/ssh/ssh-analyzer.pac index 12fa79634c..e3064e08a0 100644 --- a/src/analyzer/protocol/ssh/ssh-analyzer.pac +++ b/src/analyzer/protocol/ssh/ssh-analyzer.pac @@ -5,14 +5,14 @@ %} %header{ -VectorVal* name_list_to_vector(const bytestring& nl); +IntrusivePtr name_list_to_vector(const bytestring& nl); %} %code{ // Copied from IRC_Analyzer::SplitWords -VectorVal* name_list_to_vector(const bytestring& nl) +IntrusivePtr name_list_to_vector(const bytestring& nl) { - VectorVal* vv = new VectorVal(zeek::id::string_vec); + auto vv = make_intrusive(zeek::id::string_vec); string name_list = std_str(nl); if ( name_list.size() < 1 ) @@ -74,30 +74,30 @@ refine flow SSH_Flow += { result->Assign(0, name_list_to_vector(${msg.kex_algorithms.val})); result->Assign(1, name_list_to_vector(${msg.server_host_key_algorithms.val})); - RecordVal* encryption_algs = new RecordVal(zeek::BifType::Record::SSH::Algorithm_Prefs); + auto encryption_algs = make_intrusive(zeek::BifType::Record::SSH::Algorithm_Prefs); encryption_algs->Assign(0, name_list_to_vector(${msg.encryption_algorithms_client_to_server.val})); encryption_algs->Assign(1, name_list_to_vector(${msg.encryption_algorithms_server_to_client.val})); - result->Assign(2, encryption_algs); + result->Assign(2, std::move(encryption_algs)); - RecordVal* mac_algs = new RecordVal(zeek::BifType::Record::SSH::Algorithm_Prefs); + auto mac_algs = make_intrusive(zeek::BifType::Record::SSH::Algorithm_Prefs); mac_algs->Assign(0, name_list_to_vector(${msg.mac_algorithms_client_to_server.val})); mac_algs->Assign(1, name_list_to_vector(${msg.mac_algorithms_server_to_client.val})); - result->Assign(3, mac_algs); + result->Assign(3, std::move(mac_algs)); - RecordVal* compression_algs = new RecordVal(zeek::BifType::Record::SSH::Algorithm_Prefs); + auto compression_algs = make_intrusive(zeek::BifType::Record::SSH::Algorithm_Prefs); compression_algs->Assign(0, name_list_to_vector(${msg.compression_algorithms_client_to_server.val})); compression_algs->Assign(1, name_list_to_vector(${msg.compression_algorithms_server_to_client.val})); - result->Assign(4, compression_algs); + result->Assign(4, std::move(compression_algs)); if ( ${msg.languages_client_to_server.len} || ${msg.languages_server_to_client.len} ) { - RecordVal* languages = new RecordVal(zeek::BifType::Record::SSH::Algorithm_Prefs); + auto languages = make_intrusive(zeek::BifType::Record::SSH::Algorithm_Prefs); if ( ${msg.languages_client_to_server.len} ) languages->Assign(0, name_list_to_vector(${msg.languages_client_to_server.val})); if ( ${msg.languages_server_to_client.len} ) languages->Assign(1, name_list_to_vector(${msg.languages_server_to_client.val})); - result->Assign(5, languages); + result->Assign(5, std::move(languages)); } diff --git a/src/analyzer/protocol/ssh/ssh-protocol.pac b/src/analyzer/protocol/ssh/ssh-protocol.pac index 1b42a841b7..427507a8f6 100644 --- a/src/analyzer/protocol/ssh/ssh-protocol.pac +++ b/src/analyzer/protocol/ssh/ssh-protocol.pac @@ -393,8 +393,8 @@ refine connection SSH_Conn += { else if ( kex_orig_ == orig ) return false; - VectorVal* client_list = name_list_to_vector(orig ? algs : kex_algs_cache_); - VectorVal* server_list = name_list_to_vector(orig ? kex_algs_cache_ : algs); + auto client_list = name_list_to_vector(orig ? algs : kex_algs_cache_); + auto server_list = name_list_to_vector(orig ? kex_algs_cache_ : algs); for ( unsigned int i = 0; i < client_list->Size(); ++i ) { @@ -406,9 +406,6 @@ refine connection SSH_Conn += { kex_algorithm_.init((const uint8 *) client_list->Lookup(i)->AsStringVal()->Bytes(), client_list->Lookup(i)->AsStringVal()->Len()); - Unref(client_list); - Unref(server_list); - // UNTESTED if ( update_kex_state_if_equal("rsa1024-sha1", KEX_RSA) ) return true; @@ -452,9 +449,6 @@ refine connection SSH_Conn += { } } - Unref(client_list); - Unref(server_list); - return true; %} diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index 33df0e10e1..e37ef7d18f 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -106,7 +106,7 @@ IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const if ( auth ) { - RecordVal* teredo_auth = new RecordVal(teredo_auth_type); + auto teredo_auth = make_intrusive(teredo_auth_type); uint8_t id_len = *((uint8_t*)(auth + 2)); uint8_t au_len = *((uint8_t*)(auth + 3)); uint64_t nonce = ntohll(*((uint64_t*)(auth + 4 + id_len + au_len))); @@ -117,17 +117,17 @@ IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const new BroString(auth + 4 + id_len, au_len, true))); teredo_auth->Assign(2, val_mgr->Count(nonce)); teredo_auth->Assign(3, val_mgr->Count(conf)); - teredo_hdr->Assign(0, teredo_auth); + teredo_hdr->Assign(0, std::move(teredo_auth)); } if ( origin_indication ) { - RecordVal* teredo_origin = new RecordVal(teredo_origin_type); + auto teredo_origin = make_intrusive(teredo_origin_type); uint16_t port = ntohs(*((uint16_t*)(origin_indication + 2))) ^ 0xFFFF; uint32_t addr = ntohl(*((uint32_t*)(origin_indication + 4))) ^ 0xFFFFFFFF; teredo_origin->Assign(0, val_mgr->Port(port, TRANSPORT_UDP)); teredo_origin->Assign(1, make_intrusive(htonl(addr))); - teredo_hdr->Assign(1, teredo_origin); + teredo_hdr->Assign(1, std::move(teredo_origin)); } teredo_hdr->Assign(2, inner->ToPktHdrVal()); diff --git a/src/broker/Store.cc b/src/broker/Store.cc index e763e468ba..fa76c14616 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -7,7 +7,7 @@ namespace bro_broker { IntrusivePtr opaque_of_store_handle; -EnumVal* query_status(bool success) +IntrusivePtr query_status(bool success) { static EnumType* store_query_status = nullptr; static int success_val; @@ -21,7 +21,7 @@ EnumVal* query_status(bool success) } auto rval = store_query_status->GetVal(success ? success_val : failure_val); - return rval.release(); + return rval; } void StoreHandleVal::ValDescribe(ODesc* d) const diff --git a/src/broker/Store.h b/src/broker/Store.h index be35c78254..7f329126bb 100644 --- a/src/broker/Store.h +++ b/src/broker/Store.h @@ -18,7 +18,7 @@ extern IntrusivePtr opaque_of_store_handle; * @param success whether the query status should be set to success or failure. * @return a Broker::QueryStatus value. */ -EnumVal* query_status(bool success); +IntrusivePtr query_status(bool success); /** * @return a Broker::QueryResult value that has a Broker::QueryStatus indicating diff --git a/src/broker/comm.bif b/src/broker/comm.bif index a8d3ca5389..c49e90801e 100644 --- a/src/broker/comm.bif +++ b/src/broker/comm.bif @@ -103,8 +103,8 @@ function Broker::__peers%(%): PeerInfos const auto& ei = zeek::id::find_type("Broker::EndpointInfo"); const auto& ni = zeek::id::find_type("Broker::NetworkInfo"); auto peer_info = new RecordVal(pi); - auto endpoint_info = new RecordVal(ei); - auto network_info = new RecordVal(ni); + auto endpoint_info = make_intrusive(ei); + auto network_info = make_intrusive(ni); auto n = p.peer.network; if ( n ) @@ -119,10 +119,10 @@ function Broker::__peers%(%): PeerInfos } endpoint_info->Assign(0, make_intrusive(to_string(p.peer.node))); - endpoint_info->Assign(1, network_info); + endpoint_info->Assign(1, std::move(network_info)); auto ps = (BifEnum::Broker::PeerStatus)p.status; - peer_info->Assign(0, endpoint_info); + peer_info->Assign(0, std::move(endpoint_info)); peer_info->Assign(1, zeek::BifType::Enum::Broker::PeerStatus->GetVal(ps)); rval->Assign(i, peer_info); diff --git a/src/broker/data.bif b/src/broker/data.bif index 167cc9ab48..0cdceff2e9 100644 --- a/src/broker/data.bif +++ b/src/broker/data.bif @@ -301,8 +301,8 @@ function Broker::__table_iterator_value%(it: opaque of Broker::TableIterator%): %{ auto ti = static_cast(it); auto rval = make_intrusive(zeek::BifType::Record::Broker::TableItem); - auto key_val = new RecordVal(zeek::BifType::Record::Broker::Data); - auto val_val = new RecordVal(zeek::BifType::Record::Broker::Data); + auto key_val = make_intrusive(zeek::BifType::Record::Broker::Data); + auto val_val = make_intrusive(zeek::BifType::Record::Broker::Data); rval->Assign(0, key_val); rval->Assign(1, val_val); diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 6f931e5d2e..81605e3936 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -21,13 +21,13 @@ using namespace file_analysis; -static Val* empty_connection_table() +static IntrusivePtr empty_connection_table() { auto tbl_index = make_intrusive(zeek::id::conn_id); tbl_index->Append(zeek::id::conn_id); auto tbl_type = make_intrusive(std::move(tbl_index), zeek::id::connection); - return new TableVal(std::move(tbl_type)); + return make_intrusive(std::move(tbl_type)); } static IntrusivePtr get_conn_id_val(const Connection* conn) @@ -133,8 +133,9 @@ bool File::UpdateConnectionFields(Connection* conn, bool is_orig) if ( ! conns ) { - conns = empty_connection_table(); - val->Assign(conns_idx, conns); + auto ect = empty_connection_table(); + conns = ect.get(); + val->Assign(conns_idx, std::move(ect)); } auto idx = get_conn_id_val(conn); @@ -315,8 +316,8 @@ void File::InferMetadata() return; BroString* bs = concatenate(bof_buffer.chunks); - bof_buffer_val = new StringVal(bs); - val->Assign(bof_buffer_idx, bof_buffer_val); + val->Assign(bof_buffer_idx, bs); + bof_buffer_val = val->Lookup(bof_buffer_idx); } if ( ! FileEventAvailable(file_sniff) ) @@ -332,8 +333,8 @@ void File::InferMetadata() if ( ! matches.empty() ) { - meta->Assign(meta_mime_type_idx, - new StringVal(*(matches.begin()->second.begin()))); + meta->Assign(meta_mime_type_idx, + *(matches.begin()->second.begin())); meta->Assign(meta_mime_types_idx, file_analysis::GenMIMEMatchesVal(matches)); } diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index f0967dc5ba..cfab9f4c94 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -5,38 +5,42 @@ %} %header{ -VectorVal* process_rvas(const RVAS* rvas); +IntrusivePtr process_rvas(const RVAS* rvas); +IntrusivePtr characteristics_to_bro(uint32_t c, uint8_t len); %} %code{ -VectorVal* process_rvas(const RVAS* rva_table) +IntrusivePtr process_rvas(const RVAS* rva_table) { auto rvas = make_intrusive(zeek::id::index_vec); for ( uint16 i=0; i < rva_table->rvas()->size(); ++i ) rvas->Assign(i, val_mgr->Count((*rva_table->rvas())[i]->size())); - return rvas.release(); + return rvas; + } + +IntrusivePtr characteristics_to_bro(uint32_t c, uint8_t len) + { + uint64 mask = (len==16) ? 0xFFFF : 0xFFFFFFFF; + auto char_set = make_intrusive(zeek::id::count_set); + + for ( uint16 i=0; i < len; ++i ) + { + if ( ((c >> i) & 0x1) == 1 ) + { + auto ch = val_mgr->Count((1<Assign(ch.get(), 0); + } + } + + return char_set; } %} refine flow File += { - function characteristics_to_bro(c: uint32, len: uint8): TableVal - %{ - uint64 mask = (len==16) ? 0xFFFF : 0xFFFFFFFF; - TableVal* char_set = new TableVal(zeek::id::count_set); - for ( uint16 i=0; i < len; ++i ) - { - if ( ((c >> i) & 0x1) == 1 ) - { - auto ch = val_mgr->Count((1<Assign(ch.get(), 0); - } - } - return char_set; - %} function proc_dos_header(h: DOS_Header): bool %{ diff --git a/src/file_analysis/analyzer/unified2/unified2-analyzer.pac b/src/file_analysis/analyzer/unified2/unified2-analyzer.pac index 58077f1635..f395e919d9 100644 --- a/src/file_analysis/analyzer/unified2/unified2-analyzer.pac +++ b/src/file_analysis/analyzer/unified2/unified2-analyzer.pac @@ -7,9 +7,43 @@ #include "IPAddr.h" %} +%code{ +IntrusivePtr binpac::Unified2::Flow::unified2_addr_to_bro_addr(std::vector* a) + { + if ( a->size() == 1 ) + { + return make_intrusive(IPAddr(IPv4, &(a->at(0)), IPAddr::Host)); + } + else if ( a->size() == 4 ) + { + uint32 tmp[4] = { a->at(0), a->at(1), a->at(2), a->at(3) }; + return make_intrusive(IPAddr(IPv6, tmp, IPAddr::Host)); + } + else + { + // Should never reach here. + return make_intrusive(1); + } + } + +IntrusivePtr binpac::Unified2::Flow::to_port(uint16_t n, uint8_t p) + { + TransportProto proto = TRANSPORT_UNKNOWN; + switch ( p ) { + case 1: proto = TRANSPORT_ICMP; break; + case 6: proto = TRANSPORT_TCP; break; + case 17: proto = TRANSPORT_UDP; break; + } + + return val_mgr->Port(n, proto); + } +%} + refine flow Flow += { %member{ + IntrusivePtr unified2_addr_to_bro_addr(std::vector* a); + IntrusivePtr to_port(uint16_t n, uint8_t p); %} %init{ @@ -27,35 +61,6 @@ refine flow Flow += { return t; %} - function unified2_addr_to_bro_addr(a: uint32[]): AddrVal - %{ - if ( a->size() == 1 ) - { - return new AddrVal(IPAddr(IPv4, &(a->at(0)), IPAddr::Host)); - } - else if ( a->size() == 4 ) - { - uint32 tmp[4] = { a->at(0), a->at(1), a->at(2), a->at(3) }; - return new AddrVal(IPAddr(IPv6, tmp, IPAddr::Host)); - } - else - { - // Should never reach here. - return new AddrVal(1); - } - %} - - function to_port(n: uint16, p: uint8): Val - %{ - TransportProto proto = TRANSPORT_UNKNOWN; - switch ( p ) { - case 1: proto = TRANSPORT_ICMP; break; - case 6: proto = TRANSPORT_TCP; break; - case 17: proto = TRANSPORT_UDP; break; - } - - return val_mgr->Port(n, proto)->Ref(); - %} #function proc_record(rec: Record) : bool # %{ diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 9c5fe8a6d9..5c5cfaaab5 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -336,10 +336,10 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) return; } - VectorVal* names = nullptr; - VectorVal* emails = nullptr; - VectorVal* uris = nullptr; - VectorVal* ips = nullptr; + IntrusivePtr names; + IntrusivePtr emails; + IntrusivePtr uris; + IntrusivePtr ips; bool otherfields = false; @@ -367,21 +367,21 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) { case GEN_DNS: if ( names == nullptr ) - names = new VectorVal(zeek::id::string_vec); + names = make_intrusive(zeek::id::string_vec); names->Assign(names->Size(), bs); break; case GEN_URI: if ( uris == nullptr ) - uris = new VectorVal(zeek::id::string_vec); + uris = make_intrusive(zeek::id::string_vec); uris->Assign(uris->Size(), bs); break; case GEN_EMAIL: if ( emails == nullptr ) - emails = new VectorVal(zeek::id::string_vec); + emails = make_intrusive(zeek::id::string_vec); emails->Assign(emails->Size(), bs); break; @@ -391,7 +391,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) else if ( gen->type == GEN_IPADD ) { if ( ips == nullptr ) - ips = new VectorVal(zeek::id::find_type("addr_vec")); + ips = make_intrusive(zeek::id::find_type("addr_vec")); uint32_t* addr = (uint32_t*) gen->d.ip->data; @@ -439,13 +439,13 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) GENERAL_NAMES_free(altname); } -StringVal* file_analysis::X509::KeyCurve(EVP_PKEY *key) +IntrusivePtr file_analysis::X509::KeyCurve(EVP_PKEY* key) { - assert(key != NULL); + assert(key != nullptr); #ifdef OPENSSL_NO_EC // well, we do not have EC-Support... - return NULL; + return nullptr; #else if ( EVP_PKEY_base_id(key) != EVP_PKEY_EC ) { @@ -468,7 +468,7 @@ StringVal* file_analysis::X509::KeyCurve(EVP_PKEY *key) if ( curve_name == nullptr ) return nullptr; - return new StringVal(curve_name); + return make_intrusive(curve_name); #endif } diff --git a/src/file_analysis/analyzer/x509/X509.h b/src/file_analysis/analyzer/x509/X509.h index c299d55270..98370977c4 100644 --- a/src/file_analysis/analyzer/x509/X509.h +++ b/src/file_analysis/analyzer/x509/X509.h @@ -136,7 +136,7 @@ private: std::string cert_data; // Helpers for ParseCertificate. - static StringVal* KeyCurve(EVP_PKEY *key); + static IntrusivePtr KeyCurve(EVP_PKEY* key); static unsigned int KeyLength(EVP_PKEY *key); /** X509 stores associated with global script-layer values */ inline static std::map x509_stores = std::map(); diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index aba1042da7..8b90370358 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -11,14 +11,14 @@ #include // construct an error record -IntrusivePtr x509_result_record(uint64_t num, const char* reason, Val* chainVector = nullptr) +static IntrusivePtr x509_result_record(uint64_t num, const char* reason, IntrusivePtr chainVector = nullptr) { auto rrecord = make_intrusive(zeek::BifType::Record::X509::Result); rrecord->Assign(0, val_mgr->Int(num)); rrecord->Assign(1, make_intrusive(reason)); if ( chainVector ) - rrecord->Assign(2, chainVector); + rrecord->Assign(2, std::move(chainVector)); return rrecord; } @@ -542,7 +542,7 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str int result = X509_verify_cert(csc); - VectorVal* chainVector = nullptr; + IntrusivePtr chainVector; if ( result == 1 ) // we have a valid chain. try to get it... { @@ -556,7 +556,7 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str } int num_certs = sk_X509_num(chain); - chainVector = new VectorVal(zeek::id::find_type("x509_opaque_vector")); + chainVector = make_intrusive(zeek::id::find_type("x509_opaque_vector")); for ( int i = 0; i < num_certs; i++ ) { @@ -578,7 +578,7 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str x509_verify_chainerror: - auto rrecord = x509_result_record(X509_STORE_CTX_get_error(csc), X509_verify_cert_error_string(X509_STORE_CTX_get_error(csc)), chainVector); + auto rrecord = x509_result_record(X509_STORE_CTX_get_error(csc), X509_verify_cert_error_string(X509_STORE_CTX_get_error(csc)), std::move(chainVector)); X509_STORE_CTX_cleanup(csc); X509_STORE_CTX_free(csc); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 993c8804a9..af80e6cbdb 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1908,7 +1908,7 @@ RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType *request_type, (*position)++; } - rec->Assign(i, fieldVal->Ref()); + rec->Assign(i, {NewRef{}, fieldVal}); } return rec; @@ -1945,7 +1945,7 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v } if ( fieldVal ) - rec->Assign(i, fieldVal); + rec->Assign(i, {AdoptRef{}, fieldVal}); } return rec; diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index 45aaf02072..75554662cf 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -597,7 +597,7 @@ IntrusivePtr Packet::ToRawPktHdrVal() const static auto raw_pkt_hdr_type = zeek::id::find_type("raw_pkt_hdr"); static auto l2_hdr_type = zeek::id::find_type("l2_hdr"); auto pkt_hdr = make_intrusive(raw_pkt_hdr_type); - RecordVal* l2_hdr = new RecordVal(l2_hdr_type); + auto l2_hdr = make_intrusive(l2_hdr_type); bool is_ethernet = link_type == DLT_EN10MB; @@ -651,7 +651,7 @@ IntrusivePtr Packet::ToRawPktHdrVal() const l2_hdr->Assign(8, zeek::BifType::Enum::layer3_proto->GetVal(l3)); - pkt_hdr->Assign(0, l2_hdr); + pkt_hdr->Assign(0, std::move(l2_hdr)); if ( l3_proto == L3_IPV4 ) { @@ -674,12 +674,12 @@ RecordVal* Packet::BuildPktHdrVal() const return ToRawPktHdrVal().release(); } -Val *Packet::FmtEUI48(const u_char *mac) const +IntrusivePtr Packet::FmtEUI48(const u_char* mac) const { char buf[20]; snprintf(buf, sizeof buf, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - return new StringVal(buf); + return make_intrusive(buf); } void Packet::Describe(ODesc* d) const diff --git a/src/iosource/Packet.h b/src/iosource/Packet.h index ce2e3b928a..83b0fddb59 100644 --- a/src/iosource/Packet.h +++ b/src/iosource/Packet.h @@ -225,7 +225,7 @@ private: void Weird(const char* name); // Renders an MAC address into its ASCII representation. - Val* FmtEUI48(const u_char *mac) const; + IntrusivePtr FmtEUI48(const u_char* mac) const; // True if we need to delete associated packet memory upon // destruction. diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index a2773c7c22..811346b766 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1515,7 +1515,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con // Create the RotationInfo record. auto info = make_intrusive(zeek::BifType::Record::Log::RotationInfo); - info->Assign(0, winfo->type->Ref()); + info->Assign(0, {NewRef{}, winfo->type}); info->Assign(1, make_intrusive(new_name)); info->Assign(2, make_intrusive(winfo->writer->Info().path)); info->Assign(3, make_intrusive(open, TYPE_TIME)); diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 3004a798c7..ea76fd0a94 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1131,8 +1131,8 @@ IntrusivePtr Supervisor::NodeConfig::ToRecord() const rval->Assign(rt->FieldOffset("scripts"), std::move(scripts_val)); - const auto& tt = rt->GetFieldType("cluster"); - auto cluster_val = new TableVal({NewRef{}, tt->AsTableType()}); + auto tt = rt->GetFieldType("cluster"); + auto cluster_val = make_intrusive(std::move(tt)); rval->Assign(rt->FieldOffset("cluster"), cluster_val); for ( const auto& e : cluster ) @@ -1316,7 +1316,7 @@ IntrusivePtr Supervisor::Status(std::string_view node_name) { auto rval = make_intrusive(zeek::BifType::Record::Supervisor::Status); const auto& tt = zeek::BifType::Record::Supervisor::Status->GetFieldType("nodes"); - auto node_table_val = new TableVal(cast_intrusive(tt)); + auto node_table_val = make_intrusive(cast_intrusive(tt)); rval->Assign(0, node_table_val); if ( node_name.empty() ) diff --git a/src/supervisor/supervisor.bif b/src/supervisor/supervisor.bif index a6ee28ae1b..e0dd3dce3b 100644 --- a/src/supervisor/supervisor.bif +++ b/src/supervisor/supervisor.bif @@ -86,7 +86,7 @@ function Supervisor::__node%(%): Supervisor::NodeConfig builtin_error("not a supervised process"); const auto& rt = zeek::BifType::Record::Supervisor::NodeConfig; auto rval = make_intrusive(rt); - rval->Assign(rt->FieldOffset("name"), new StringVal("")); + rval->Assign(rt->FieldOffset("name"), ""); return rval; } diff --git a/src/util.cc b/src/util.cc index 7b3394e8d7..8fdeee9e12 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1857,10 +1857,10 @@ FILE* rotate_file(const char* name, RecordVal* rotate_info) // Init rotate_info. if ( rotate_info ) { - rotate_info->Assign(0, new StringVal(name)); - rotate_info->Assign(1, new StringVal(newname)); - rotate_info->Assign(2, new Val(network_time, TYPE_TIME)); - rotate_info->Assign(3, new Val(network_time, TYPE_TIME)); + rotate_info->Assign(0, name); + rotate_info->Assign(1, newname); + rotate_info->Assign(2, network_time, TYPE_TIME); + rotate_info->Assign(3, network_time, TYPE_TIME); } return newf; diff --git a/src/zeek.bif b/src/zeek.bif index 685e3e4fdf..6fd13e5139 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -3864,7 +3864,7 @@ static bool mmdb_lookup_asn(const IPAddr& addr, MMDB_lookup_result_s& result) return mmdb_lookup(addr, result, true); } -static Val* mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, +static IntrusivePtr mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, int data_type ) { switch (status) @@ -3875,16 +3875,16 @@ static Val* mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, switch (data_type) { case MMDB_DATA_TYPE_UTF8_STRING: - return new StringVal(entry_data->data_size, - entry_data->utf8_string); + return make_intrusive(entry_data->data_size, + entry_data->utf8_string); break; case MMDB_DATA_TYPE_DOUBLE: - return new Val(entry_data->double_value, TYPE_DOUBLE); + return make_intrusive(entry_data->double_value, TYPE_DOUBLE); break; case MMDB_DATA_TYPE_UINT32: - return val_mgr->Count(entry_data->uint32).release(); + return val_mgr->Count(entry_data->uint32); default: break; @@ -4111,8 +4111,8 @@ function lookup_asn%(a: addr%) : count // Get Autonomous System Number status = MMDB_get_value(&result.entry, &entry_data, "autonomous_system_number", nullptr); - Val* asn = mmdb_getvalue(&entry_data, status, MMDB_DATA_TYPE_UINT32); - return asn == nullptr ? val_mgr->Count(0) : IntrusivePtr{AdoptRef{}, asn}; + auto asn = mmdb_getvalue(&entry_data, status, MMDB_DATA_TYPE_UINT32); + return asn == nullptr ? val_mgr->Count(0) : asn; } #else // not USE_GEOIP From 958387393698cfcd261a345473fa445da736be4a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 19 May 2020 15:52:41 -0700 Subject: [PATCH 084/151] Switch ASN1 Val conversion functions to return IntrusivePtr --- src/analyzer/protocol/asn1/asn1.pac | 38 ++++++++-------- src/analyzer/protocol/krb/krb-analyzer.pac | 22 +++++----- src/analyzer/protocol/krb/krb-types.pac | 8 ++-- src/analyzer/protocol/snmp/snmp-analyzer.pac | 46 ++++++++++---------- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/analyzer/protocol/asn1/asn1.pac b/src/analyzer/protocol/asn1/asn1.pac index a1fc14e1a3..61ef62630d 100644 --- a/src/analyzer/protocol/asn1/asn1.pac +++ b/src/analyzer/protocol/asn1/asn1.pac @@ -3,12 +3,12 @@ %} %header{ - Val* asn1_integer_to_val(const ASN1Encoding* i, TypeTag t); - Val* asn1_integer_to_val(const ASN1Integer* i, TypeTag t); - StringVal* asn1_oid_to_val(const ASN1Encoding* oid); - StringVal* asn1_oid_to_val(const ASN1ObjectIdentifier* oid); - StringVal* asn1_octet_string_to_val(const ASN1Encoding* s); - StringVal* asn1_octet_string_to_val(const ASN1OctetString* s); + IntrusivePtr asn1_integer_to_val(const ASN1Encoding* i, TypeTag t); + IntrusivePtr asn1_integer_to_val(const ASN1Integer* i, TypeTag t); + IntrusivePtr asn1_oid_to_val(const ASN1Encoding* oid); + IntrusivePtr asn1_oid_to_val(const ASN1ObjectIdentifier* oid); + IntrusivePtr asn1_octet_string_to_val(const ASN1Encoding* s); + IntrusivePtr asn1_octet_string_to_val(const ASN1OctetString* s); %} ############################## ASN.1 Encodings @@ -102,35 +102,35 @@ function binary_to_int64(bs: bytestring): int64 %code{ -Val* asn1_integer_to_val(const ASN1Integer* i, TypeTag t) +IntrusivePtr asn1_integer_to_val(const ASN1Integer* i, TypeTag t) { return asn1_integer_to_val(i->encoding(), t); } -Val* asn1_integer_to_val(const ASN1Encoding* i, TypeTag t) +IntrusivePtr asn1_integer_to_val(const ASN1Encoding* i, TypeTag t) { auto v = binary_to_int64(i->content()); switch ( t ) { case TYPE_BOOL: - return val_mgr->Bool(v)->Ref(); + return val_mgr->Bool(v); case TYPE_INT: - return val_mgr->Int(v).release(); + return val_mgr->Int(v); case TYPE_COUNT: case TYPE_COUNTER: - return val_mgr->Count(v).release(); + return val_mgr->Count(v); default: reporter->Error("bad asn1_integer_to_val tag: %s", type_name(t)); - return val_mgr->Count(v).release(); + return val_mgr->Count(v); } } -StringVal* asn1_oid_to_val(const ASN1ObjectIdentifier* oid) +IntrusivePtr asn1_oid_to_val(const ASN1ObjectIdentifier* oid) { return asn1_oid_to_val(oid->encoding()); } -StringVal* asn1_oid_to_val(const ASN1Encoding* oid) +IntrusivePtr asn1_oid_to_val(const ASN1Encoding* oid) { vector oid_components; vector > subidentifiers; @@ -152,7 +152,7 @@ StringVal* asn1_oid_to_val(const ASN1Encoding* oid) if ( ! subidentifier.empty() || subidentifiers.size() < 1 ) // Underflow. - return val_mgr->EmptyString()->Ref()->AsStringVal(); + return val_mgr->EmptyString(); for ( size_t i = 0; i < subidentifiers.size(); ++i ) { @@ -191,17 +191,17 @@ StringVal* asn1_oid_to_val(const ASN1Encoding* oid) } } - return new StringVal(rval); + return make_intrusive(rval); } -StringVal* asn1_octet_string_to_val(const ASN1OctetString* s) +IntrusivePtr asn1_octet_string_to_val(const ASN1OctetString* s) { return asn1_octet_string_to_val(s->encoding()); } -StringVal* asn1_octet_string_to_val(const ASN1Encoding* s) +IntrusivePtr asn1_octet_string_to_val(const ASN1Encoding* s) { bytestring const& bs = s->content(); - return new StringVal(bs.length(), reinterpret_cast(bs.data())); + return make_intrusive(bs.length(), reinterpret_cast(bs.data())); } %} diff --git a/src/analyzer/protocol/krb/krb-analyzer.pac b/src/analyzer/protocol/krb/krb-analyzer.pac index f3c6782361..86aa921895 100644 --- a/src/analyzer/protocol/krb/krb-analyzer.pac +++ b/src/analyzer/protocol/krb/krb-analyzer.pac @@ -31,8 +31,8 @@ IntrusivePtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAn { auto rv = make_intrusive(zeek::BifType::Record::KRB::KDC_Request); - rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(msg->pvno()->data(), TYPE_COUNT)}); - rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(msg->msg_type()->data(), TYPE_COUNT)}); + rv->Assign(0, asn1_integer_to_val(msg->pvno()->data(), TYPE_COUNT)); + rv->Assign(1, asn1_integer_to_val(msg->msg_type()->data(), TYPE_COUNT)); if ( msg->padata()->has_padata() ) rv->Assign(2, proc_padata(msg->padata()->padata()->padata(), bro_analyzer, false)); @@ -64,7 +64,7 @@ IntrusivePtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAn rv->Assign(9, GetTimeFromAsn1(element->data()->rtime(), 0)); break; case 7: - rv->Assign(10, {AdoptRef{}, asn1_integer_to_val(element->data()->nonce(), TYPE_COUNT)}); + rv->Assign(10, asn1_integer_to_val(element->data()->nonce(), TYPE_COUNT)); break; case 8: if ( element->data()->etype()->data()->size() ) @@ -132,10 +132,10 @@ bool proc_error_arguments(RecordVal* rv, const std::vector* args switch ( (*args)[i]->seq_meta()->index() ) { case 0: - rv->Assign(0, {AdoptRef{}, asn1_integer_to_val((*args)[i]->args()->pvno(), TYPE_COUNT)}); + rv->Assign(0, asn1_integer_to_val((*args)[i]->args()->pvno(), TYPE_COUNT)); break; case 1: - rv->Assign(1, {AdoptRef{}, asn1_integer_to_val((*args)[i]->args()->msg_type(), TYPE_COUNT)}); + rv->Assign(1, asn1_integer_to_val((*args)[i]->args()->msg_type(), TYPE_COUNT)); break; // ctime/stime handled above case 7: @@ -205,8 +205,8 @@ refine connection KRB_Conn += { { auto rv = make_intrusive(zeek::BifType::Record::KRB::KDC_Response); - rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)}); - rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)}); + rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)); + rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)); if ( ${msg.padata.has_padata} ) rv->Assign(2, proc_padata(${msg.padata.padata.padata}, bro_analyzer(), false)); @@ -246,7 +246,7 @@ refine connection KRB_Conn += { { auto rv = make_intrusive(zeek::BifType::Record::KRB::Error_Msg); proc_error_arguments(rv.get(), ${msg.args1}, 0); - rv->Assign(4, {AdoptRef{}, asn1_integer_to_val(${msg.error_code}, TYPE_COUNT)}); + rv->Assign(4, asn1_integer_to_val(${msg.error_code}, TYPE_COUNT)); proc_error_arguments(rv.get(), ${msg.args2}, binary_to_int64(${msg.error_code.encoding.content})); zeek::BifEvent::enqueue_krb_error(bro_analyzer(), bro_analyzer()->Conn(), std::move(rv)); } @@ -291,8 +291,8 @@ refine connection KRB_Conn += { { auto rv = make_intrusive(zeek::BifType::Record::KRB::SAFE_Msg); - rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)}); - rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)}); + rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)); + rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)); uint timestamp_i = 0; int64 timestamp_usecs = 0; @@ -325,7 +325,7 @@ refine connection KRB_Conn += { rv->Assign(3, to_stringval(${msg.safe_body.args[i].args.user_data.encoding.content})); break; case 3: - rv->Assign(5, {AdoptRef{}, asn1_integer_to_val(${msg.safe_body.args[i].args.seq_number}, TYPE_COUNT)}); + rv->Assign(5, asn1_integer_to_val(${msg.safe_body.args[i].args.seq_number}, TYPE_COUNT)); break; case 4: rv->Assign(6, proc_host_address(bro_analyzer(), ${msg.safe_body.args[i].args.sender_addr})); diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index 4f1942854d..20ef1ea3bb 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -29,7 +29,7 @@ IntrusivePtr proc_cipher_list(const Array* list) { auto ciphers = make_intrusive(zeek::id::index_vec); for ( uint i = 0; i < list->data()->size(); ++i ) - ciphers->Assign(ciphers->Size(), {AdoptRef{}, asn1_integer_to_val((*list->data())[i], TYPE_COUNT)}); + ciphers->Assign(ciphers->Size(), asn1_integer_to_val((*list->data())[i], TYPE_COUNT)); return ciphers; } @@ -86,7 +86,7 @@ IntrusivePtr proc_host_address(const BroAnalyzer a, const KRB_Host_Ad } auto unk = make_intrusive(zeek::BifType::Record::KRB::Type_Value); - unk->Assign(0, {AdoptRef{}, asn1_integer_to_val(addr->addr_type(), TYPE_COUNT)}); + unk->Assign(0, asn1_integer_to_val(addr->addr_type(), TYPE_COUNT)); unk->Assign(1, to_stringval(addr_bytes)); rv->Assign(2, std::move(unk)); return rv; @@ -109,10 +109,10 @@ IntrusivePtr proc_ticket(const KRB_Ticket* ticket) { auto rv = make_intrusive(zeek::BifType::Record::KRB::Ticket); - rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(ticket->tkt_vno()->data(), TYPE_COUNT)}); + rv->Assign(0, asn1_integer_to_val(ticket->tkt_vno()->data(), TYPE_COUNT)); rv->Assign(1, to_stringval(ticket->realm()->data()->content())); rv->Assign(2, GetStringFromPrincipalName(ticket->sname())); - rv->Assign(3, {AdoptRef{}, asn1_integer_to_val(ticket->enc_part()->data()->etype()->data(), TYPE_COUNT)}); + rv->Assign(3, asn1_integer_to_val(ticket->enc_part()->data()->etype()->data(), TYPE_COUNT)); rv->Assign(4, to_stringval(ticket->enc_part()->data()->ciphertext()->encoding()->content())); return rv; diff --git a/src/analyzer/protocol/snmp/snmp-analyzer.pac b/src/analyzer/protocol/snmp/snmp-analyzer.pac index ad31e0ef8a..4793405697 100644 --- a/src/analyzer/protocol/snmp/snmp-analyzer.pac +++ b/src/analyzer/protocol/snmp/snmp-analyzer.pac @@ -57,18 +57,18 @@ IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj) break; case ASN1_OBJECT_IDENTIFIER_TAG: - rval->Assign(1, {AdoptRef{}, asn1_oid_to_val(obj)}); + rval->Assign(1, asn1_oid_to_val(obj)); break; case ASN1_INTEGER_TAG: - rval->Assign(2, {AdoptRef{}, asn1_integer_to_val(obj, TYPE_INT)}); + rval->Assign(2, asn1_integer_to_val(obj, TYPE_INT)); break; case APP_COUNTER32_TAG: case APP_UNSIGNED32_TAG: case APP_TIMETICKS_TAG: case APP_COUNTER64_TAG: - rval->Assign(3, {AdoptRef{}, asn1_integer_to_val(obj, TYPE_COUNT)}); + rval->Assign(3, asn1_integer_to_val(obj, TYPE_COUNT)); break; case APP_IPADDRESS_TAG: @@ -78,7 +78,7 @@ IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj) case ASN1_OCTET_STRING_TAG: case APP_OPAQUE_TAG: default: - rval->Assign(5, {AdoptRef{}, asn1_octet_string_to_val(obj)}); + rval->Assign(5, asn1_octet_string_to_val(obj)); break; } @@ -87,7 +87,7 @@ IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj) IntrusivePtr time_ticks_to_val(const TimeTicks* tt) { - return {AdoptRef{}, asn1_integer_to_val(tt->asn1_integer(), TYPE_COUNT)}; + return asn1_integer_to_val(tt->asn1_integer(), TYPE_COUNT); } IntrusivePtr build_hdr(const Header* header) @@ -99,7 +99,7 @@ IntrusivePtr build_hdr(const Header* header) case SNMPV1_TAG: { auto v1 = make_intrusive(zeek::BifType::Record::SNMP::HeaderV1); - v1->Assign(0, {AdoptRef{}, asn1_octet_string_to_val(header->v1()->community())}); + v1->Assign(0, asn1_octet_string_to_val(header->v1()->community())); rv->Assign(1, std::move(v1)); } break; @@ -107,7 +107,7 @@ IntrusivePtr build_hdr(const Header* header) case SNMPV2_TAG: { auto v2 = make_intrusive(zeek::BifType::Record::SNMP::HeaderV2); - v2->Assign(0, {AdoptRef{}, asn1_octet_string_to_val(header->v2()->community())}); + v2->Assign(0, asn1_octet_string_to_val(header->v2()->community())); rv->Assign(2, std::move(v2)); } break; @@ -130,21 +130,21 @@ IntrusivePtr build_hdrV3(const Header* header) bytestring const& flags = global_data->flags()->encoding()->content(); uint8 flags_byte = flags.length() > 0 ? flags[0] : 0; - v3->Assign(0, {AdoptRef{}, asn1_integer_to_val(global_data->id(), TYPE_COUNT)}); - v3->Assign(1, {AdoptRef{}, asn1_integer_to_val(global_data->max_size(), TYPE_COUNT)}); + v3->Assign(0, asn1_integer_to_val(global_data->id(), TYPE_COUNT)); + v3->Assign(1, asn1_integer_to_val(global_data->max_size(), TYPE_COUNT)); v3->Assign(2, val_mgr->Count(flags_byte)); v3->Assign(3, val_mgr->Bool(flags_byte & 0x01)); v3->Assign(4, val_mgr->Bool(flags_byte & 0x02)); v3->Assign(5, val_mgr->Bool(flags_byte & 0x04)); - v3->Assign(6, {AdoptRef{}, asn1_integer_to_val(global_data->security_model(), TYPE_COUNT)}); - v3->Assign(7, {AdoptRef{}, asn1_octet_string_to_val(v3hdr->security_parameters())}); + v3->Assign(6, asn1_integer_to_val(global_data->security_model(), TYPE_COUNT)); + v3->Assign(7, asn1_octet_string_to_val(v3hdr->security_parameters())); if ( v3hdr->next()->tag() == ASN1_SEQUENCE_TAG ) { const v3ScopedPDU* spdu = v3hdr->plaintext_pdu(); auto rv = make_intrusive(zeek::BifType::Record::SNMP::ScopedPDU_Context); - rv->Assign(0, {AdoptRef{}, asn1_octet_string_to_val(spdu->context_engine_id())}); - rv->Assign(1, {AdoptRef{}, asn1_octet_string_to_val(spdu->context_name())}); + rv->Assign(0, asn1_octet_string_to_val(spdu->context_engine_id())); + rv->Assign(1, asn1_octet_string_to_val(spdu->context_name())); v3->Assign(8, std::move(rv)); } @@ -159,7 +159,7 @@ IntrusivePtr build_bindings(const VarBindList* vbl) { VarBind* vb = (*vbl->bindings())[i]; auto binding = make_intrusive(zeek::BifType::Record::SNMP::Binding); - binding->Assign(0, {AdoptRef{}, asn1_oid_to_val(vb->name()->oid())}); + binding->Assign(0, asn1_oid_to_val(vb->name()->oid())); binding->Assign(1, asn1_obj_to_val(vb->value()->encoding())); vv->Assign(i, std::move(binding)); } @@ -170,9 +170,9 @@ IntrusivePtr build_bindings(const VarBindList* vbl) IntrusivePtr build_pdu(const CommonPDU* pdu) { auto rv = make_intrusive(zeek::BifType::Record::SNMP::PDU); - rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(pdu->request_id(), TYPE_INT)}); - rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(pdu->error_status(), TYPE_INT)}); - rv->Assign(2, {AdoptRef{}, asn1_integer_to_val(pdu->error_index(), TYPE_INT)}); + rv->Assign(0, asn1_integer_to_val(pdu->request_id(), TYPE_INT)); + rv->Assign(1, asn1_integer_to_val(pdu->error_status(), TYPE_INT)); + rv->Assign(2, asn1_integer_to_val(pdu->error_index(), TYPE_INT)); rv->Assign(3, build_bindings(pdu->var_bindings())); return rv; } @@ -180,10 +180,10 @@ IntrusivePtr build_pdu(const CommonPDU* pdu) IntrusivePtr build_trap_pdu(const TrapPDU* pdu) { auto rv = make_intrusive(zeek::BifType::Record::SNMP::TrapPDU); - rv->Assign(0, {AdoptRef{}, asn1_oid_to_val(pdu->enterprise())}); + rv->Assign(0, asn1_oid_to_val(pdu->enterprise())); rv->Assign(1, network_address_to_val(pdu->agent_addr())); - rv->Assign(2, {AdoptRef{}, asn1_integer_to_val(pdu->generic_trap(), TYPE_INT)}); - rv->Assign(3, {AdoptRef{}, asn1_integer_to_val(pdu->specific_trap(), TYPE_INT)}); + rv->Assign(2, asn1_integer_to_val(pdu->generic_trap(), TYPE_INT)); + rv->Assign(3, asn1_integer_to_val(pdu->specific_trap(), TYPE_INT)); rv->Assign(4, time_ticks_to_val(pdu->time_stamp())); rv->Assign(5, build_bindings(pdu->var_bindings())); return rv; @@ -192,9 +192,9 @@ IntrusivePtr build_trap_pdu(const TrapPDU* pdu) IntrusivePtr build_bulk_pdu(const GetBulkRequestPDU* pdu) { auto rv = make_intrusive(zeek::BifType::Record::SNMP::BulkPDU); - rv->Assign(0, {AdoptRef{}, asn1_integer_to_val(pdu->request_id(), TYPE_INT)}); - rv->Assign(1, {AdoptRef{}, asn1_integer_to_val(pdu->non_repeaters(), TYPE_COUNT)}); - rv->Assign(2, {AdoptRef{}, asn1_integer_to_val(pdu->max_repititions(), TYPE_COUNT)}); + rv->Assign(0, asn1_integer_to_val(pdu->request_id(), TYPE_INT)); + rv->Assign(1, asn1_integer_to_val(pdu->non_repeaters(), TYPE_COUNT)); + rv->Assign(2, asn1_integer_to_val(pdu->max_repititions(), TYPE_COUNT)); rv->Assign(3, build_bindings(pdu->var_bindings())); return rv; } From 377779bb2aa48352a7c5eeb48be30ca016dd00c1 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 19 May 2020 17:15:13 -0700 Subject: [PATCH 085/151] Change BroValUnion to use IntrusivePtr for record field storage This also changes the AsRecord() and AsNonConstRecord() accessors to return std::vector>* instead of val_list* --- NEWS | 3 +++ src/Sessions.cc | 2 +- src/Val.cc | 53 ++++++++++++++++++++++++++----------------------- src/Val.h | 10 +++------- src/zeek.bif | 6 +++--- 5 files changed, 38 insertions(+), 36 deletions(-) diff --git a/NEWS b/NEWS index 5adb4009db..e0997318d4 100644 --- a/NEWS +++ b/NEWS @@ -89,6 +89,9 @@ Changed Functionality - ``TypeList::Types()`` and ``IndexType::IndexTypes()`` now return an ``std::vector`` instead of ``type_list*`` +- ``AsRecord()`` and ``AsNonConstRecord()`` have changed to return + ``std::vector>*``. + Removed Functionality --------------------- diff --git a/src/Sessions.cc b/src/Sessions.cc index f28f335968..101fc2100e 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -910,7 +910,7 @@ Connection* NetSessions::FindConnection(Val* v) return nullptr; RecordType* vr = vt->AsRecordType(); - const val_list* vl = v->AsRecord(); + auto vl = v->AsRecord(); int orig_h, orig_p; // indices into record's value list int resp_h, resp_p; diff --git a/src/Val.cc b/src/Val.cc index 2d642fc057..7d5f59c60e 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2673,7 +2673,8 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo origin = nullptr; auto rt = GetType()->AsRecordType(); int n = rt->NumFields(); - val_list* vl = val.val_list_val = new val_list(n); + auto vl = val.record_val = new std::vector>; + vl->reserve(n); if ( is_parsing ) parse_time_records[rt].emplace_back(NewRef{}, this); @@ -2715,13 +2716,13 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo def = make_intrusive(cast_intrusive(type)); } - vl->push_back(def.release()); + vl->emplace_back(std::move(def)); } } RecordVal::~RecordVal() { - delete_vals(AsNonConstRecord()); + delete AsNonConstRecord(); } IntrusivePtr RecordVal::SizeVal() const @@ -2731,8 +2732,7 @@ IntrusivePtr RecordVal::SizeVal() const void RecordVal::Assign(int field, IntrusivePtr new_val) { - Val* old_val = AsNonConstRecord()->replace(field, new_val.release()); - Unref(old_val); + (*AsNonConstRecord())[field] = std::move(new_val); Modified(); } @@ -2743,15 +2743,15 @@ void RecordVal::Assign(int field, Val* new_val) Val* RecordVal::Lookup(int field) const { - return (*AsRecord())[field]; + return (*AsRecord())[field].get(); } IntrusivePtr RecordVal::LookupWithDefault(int field) const { - Val* val = (*AsRecord())[field]; + const auto& val = (*AsRecord())[field]; if ( val ) - return {NewRef{}, val}; + return val; return GetType()->AsRecordType()->FieldDefault(field); } @@ -2767,16 +2767,16 @@ void RecordVal::ResizeParseTimeRecords(RecordType* rt) for ( auto& rv : rvs ) { - auto vs = rv->val.val_list_val; - auto current_length = vs->length(); + auto vs = rv->val.record_val; + int current_length = vs->size(); auto required_length = rt->NumFields(); if ( required_length > current_length ) { - vs->resize(required_length); + vs->reserve(required_length); for ( auto i = current_length; i < required_length; ++i ) - vs->replace(i, rt->FieldDefault(i).release()); + vs->emplace_back(rt->FieldDefault(i)); } } } @@ -2876,8 +2876,8 @@ IntrusivePtr RecordVal::GetRecordFieldsVal() const void RecordVal::Describe(ODesc* d) const { - const val_list* vl = AsRecord(); - int n = vl->length(); + auto vl = AsRecord(); + auto n = vl->size(); auto record_type = GetType()->AsRecordType(); if ( d->IsBinary() || d->IsPortable() ) @@ -2890,7 +2890,7 @@ void RecordVal::Describe(ODesc* d) const else d->Add("["); - loop_over_list(*vl, i) + for ( size_t i = 0; i < n; ++i ) { if ( ! d->IsBinary() && i > 0 ) d->Add(", "); @@ -2900,7 +2900,8 @@ void RecordVal::Describe(ODesc* d) const if ( ! d->IsBinary() ) d->Add("="); - Val* v = (*vl)[i]; + const auto& v = (*vl)[i]; + if ( v ) v->Describe(d); else @@ -2913,14 +2914,14 @@ void RecordVal::Describe(ODesc* d) const void RecordVal::DescribeReST(ODesc* d) const { - const val_list* vl = AsRecord(); - int n = vl->length(); + auto vl = AsRecord(); + auto n = vl->size(); auto record_type = GetType()->AsRecordType(); d->Add("{"); d->PushIndent(); - loop_over_list(*vl, i) + for ( size_t i = 0; i < n; ++i ) { if ( i > 0 ) d->NL(); @@ -2928,7 +2929,7 @@ void RecordVal::DescribeReST(ODesc* d) const d->Add(record_type->FieldName(i)); d->Add("="); - Val* v = (*vl)[i]; + const auto& v = (*vl)[i]; if ( v ) v->Describe(d); @@ -2951,10 +2952,10 @@ IntrusivePtr RecordVal::DoClone(CloneState* state) rv->origin = nullptr; state->NewClone(this, rv); - for ( const auto& vlv : *val.val_list_val ) + for ( const auto& vlv : *val.record_val) { auto v = vlv ? vlv->Clone(state) : nullptr; - rv->val.val_list_val->push_back(v.release()); + rv->val.record_val->emplace_back(std::move(v)); } return rv; @@ -2963,15 +2964,17 @@ IntrusivePtr RecordVal::DoClone(CloneState* state) unsigned int RecordVal::MemoryAllocation() const { unsigned int size = 0; - const val_list* vl = AsRecord(); + const auto& vl = *AsRecord(); - for ( const auto& v : *vl ) + for ( const auto& v : vl ) { if ( v ) size += v->MemoryAllocation(); } - return size + padded_sizeof(*this) + val.val_list_val->MemoryAllocation(); + size += pad_size(vl.capacity() * sizeof(IntrusivePtr)); + size += padded_sizeof(vl); + return size + padded_sizeof(*this); } IntrusivePtr EnumVal::SizeVal() const diff --git a/src/Val.h b/src/Val.h index 61d8eab0f3..b635732f01 100644 --- a/src/Val.h +++ b/src/Val.h @@ -80,8 +80,7 @@ union BroValUnion { BroFile* file_val; RE_Matcher* re_val; PDict* table_val; - val_list* val_list_val; - + std::vector>* record_val; std::vector* vector_val; BroValUnion() = default; @@ -116,9 +115,6 @@ union BroValUnion { constexpr BroValUnion(PDict* value) noexcept : table_val(value) {} - constexpr BroValUnion(val_list* value) noexcept - : val_list_val(value) {} - constexpr BroValUnion(std::vector *value) noexcept : vector_val(value) {} }; @@ -222,7 +218,7 @@ public: CONST_ACCESSOR(TYPE_STRING, BroString*, string_val, AsString) CONST_ACCESSOR(TYPE_FUNC, Func*, func_val, AsFunc) CONST_ACCESSOR(TYPE_TABLE, PDict*, table_val, AsTable) - CONST_ACCESSOR(TYPE_RECORD, val_list*, val_list_val, AsRecord) + CONST_ACCESSOR(TYPE_RECORD, std::vector>*, record_val, AsRecord) CONST_ACCESSOR(TYPE_FILE, BroFile*, file_val, AsFile) CONST_ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) CONST_ACCESSOR(TYPE_VECTOR, std::vector*, vector_val, AsVector) @@ -368,7 +364,7 @@ protected: {} ACCESSOR(TYPE_TABLE, PDict*, table_val, AsNonConstTable) - ACCESSOR(TYPE_RECORD, val_list*, val_list_val, AsNonConstRecord) + ACCESSOR(TYPE_RECORD, std::vector>*, record_val, AsNonConstRecord) // For internal use by the Val::Clone() methods. struct CloneState { diff --git a/src/zeek.bif b/src/zeek.bif index 6fd13e5139..5f7fb6dec3 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -3333,8 +3333,8 @@ function lookup_connection%(cid: conn_id%): connection %%{ const char* conn_id_string(Val* c) { - Val* id = (*(c->AsRecord()))[0]; - const val_list* vl = id->AsRecord(); + const auto& id = (*(c->AsRecord()))[0]; + auto vl = id->AsRecord(); const IPAddr& orig_h = (*vl)[0]->AsAddr(); uint32_t orig_p = (*vl)[1]->AsPortVal()->Port(); @@ -3459,7 +3459,7 @@ function dump_packet%(pkt: pcap_packet, file_name: string%) : bool uint32_t caplen, len, link_type; u_char *data; - const val_list* pkt_vl = pkt->AsRecord(); + auto pkt_vl = pkt->AsRecord(); ts.tv_sec = (*pkt_vl)[0]->AsCount(); ts.tv_usec = (*pkt_vl)[1]->AsCount(); From f729247778997f7483783a8618a74bf64919bec7 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 19 May 2020 18:19:58 -0700 Subject: [PATCH 086/151] Deprecate RecordVal::Lookup(int), replace with GetField(int) --- NEWS | 2 ++ src/CompHash.cc | 4 ++-- src/Conn.cc | 4 ++-- src/Expr.cc | 10 +++++----- src/SmithWaterman.cc | 10 +++++----- src/Type.cc | 6 +++--- src/Val.cc | 23 +++++++++------------- src/Val.h | 22 ++++++++++++++++++++- src/analyzer/protocol/krb/krb-analyzer.pac | 2 +- src/analyzer/protocol/rpc/NFS.cc | 2 +- src/analyzer/protocol/rpc/Portmap.cc | 2 +- src/analyzer/protocol/tcp/TCP.cc | 2 +- src/broker/Data.cc | 4 ++-- src/broker/Manager.cc | 12 +++++------ src/broker/Store.cc | 8 ++++---- src/file_analysis/File.cc | 15 +++++++------- src/logging/Manager.cc | 2 +- src/option.bif | 2 +- src/reporter.bif | 2 +- src/strings.bif | 4 ++-- 20 files changed, 78 insertions(+), 60 deletions(-) diff --git a/NEWS b/NEWS index e0997318d4..a9b426b9a9 100644 --- a/NEWS +++ b/NEWS @@ -197,6 +197,8 @@ Deprecated Functionality - ``RecordVal::Assign(int, Val*)`` is deprecated, use the overload taking ``IntrusivePtr``. +- ``RecordVal::Lookup(int)`` is deprecated, use ``RecordVal::GetField(int)``. + Zeek 3.1.0 ========== diff --git a/src/CompHash.cc b/src/CompHash.cc index 2d3e674348..daf896fe16 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -180,7 +180,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, for ( int i = 0; i < num_fields; ++i ) { - auto rv_i = rv->Lookup(i); + auto rv_i = rv->GetField(i).get(); Attributes* a = rt->FieldDecl(i)->attrs.get(); bool optional = (a && a->FindAttr(ATTR_OPTIONAL)); @@ -518,7 +518,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, bool optional = (a && a->FindAttr(ATTR_OPTIONAL)); sz = SingleTypeKeySize(rt->GetFieldType(i).get(), - rv ? rv->Lookup(i) : nullptr, + rv ? rv->GetField(i).get() : nullptr, type_check, sz, optional, calc_static_size); if ( ! sz ) diff --git a/src/Conn.cc b/src/Conn.cc index 6d19444095..76495ddb57 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -430,7 +430,7 @@ void Connection::AppendAddl(const char* str) { const auto& cv = ConnVal(); - const char* old = cv->Lookup(6)->AsString()->CheckString(); + const char* old = cv->GetField(6)->AsString()->CheckString(); const char* format = *old ? "%s %s" : "%s%s"; cv->Assign(6, make_intrusive(fmt(format, old, str))); @@ -699,7 +699,7 @@ void Connection::CheckFlowLabel(bool is_orig, uint32_t flow_label) { if ( conn_val ) { - RecordVal *endp = conn_val->Lookup(is_orig ? 1 : 2)->AsRecordVal(); + RecordVal* endp = conn_val->GetField(is_orig ? 1 : 2)->AsRecordVal(); endp->Assign(4, val_mgr->Count(flow_label)); } diff --git a/src/Expr.cc b/src/Expr.cc index 0690bf74b6..3300b1bda0 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2897,8 +2897,8 @@ void FieldExpr::Delete(Frame* f) IntrusivePtr FieldExpr::Fold(Val* v) const { - if ( Val* result = v->AsRecordVal()->Lookup(field) ) - return {NewRef{}, result}; + if ( const auto& result = v->AsRecordVal()->GetField(field) ) + return result; // Check for &default. const Attr* def_attr = td ? td->FindAttr(ATTR_DEFAULT) : nullptr; @@ -2959,7 +2959,7 @@ HasFieldExpr::~HasFieldExpr() IntrusivePtr HasFieldExpr::Fold(Val* v) const { auto rv = v->AsRecordVal(); - return val_mgr->Bool(rv->Lookup(field)); + return val_mgr->Bool(rv->GetField(field) != nullptr); } void HasFieldExpr::ExprDescribe(ODesc* d) const @@ -3659,7 +3659,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const { if ( map[i] >= 0 ) { - IntrusivePtr rhs{NewRef{}, rv->Lookup(map[i])}; + auto rhs = rv->GetField(map[i]); if ( ! rhs ) { @@ -4830,7 +4830,7 @@ IntrusivePtr CastExpr::Eval(Frame* f) const d.Add("'"); if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) && - ! v->AsRecordVal()->Lookup(0) ) + ! v->AsRecordVal()->GetField(0) ) d.Add(" (nil $data field)"); RuntimeError(d.Description()); diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index ac32f6f28d..fe0d9876ab 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -107,19 +107,19 @@ BroSubstring::Vec* BroSubstring::VecFromPolicy(VectorVal* vec) if ( ! v ) continue; - const BroString* str = v->AsRecordVal()->Lookup(0)->AsString(); + const BroString* str = v->AsRecordVal()->GetField(0)->AsString(); BroSubstring* substr = new BroSubstring(*str); - const VectorVal* aligns = v->AsRecordVal()->Lookup(1)->AsVectorVal(); + const VectorVal* aligns = v->AsRecordVal()->GetField(1)->AsVectorVal(); for ( unsigned int j = 1; j <= aligns->Size(); ++j ) { const RecordVal* align = aligns->AsVectorVal()->Lookup(j)->AsRecordVal(); - const BroString* str = align->Lookup(0)->AsString(); - int index = align->Lookup(1)->AsCount(); + const BroString* str = align->GetField(0)->AsString(); + int index = align->GetField(1)->AsCount(); substr->AddAlignment(str, index); } - bool new_alignment = v->AsRecordVal()->Lookup(2)->AsBool(); + bool new_alignment = v->AsRecordVal()->GetField(2)->AsBool(); substr->MarkNewAlignment(new_alignment); result->push_back(substr); diff --git a/src/Type.cc b/src/Type.cc index bfa2fb6af9..0e0d00d4e5 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -804,10 +804,10 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const { const auto& ft = GetFieldType(i); const TypeDecl* fd = FieldDecl(i); - Val* fv = nullptr; + IntrusivePtr fv; if ( rv ) - fv = rv->Lookup(i); + fv = rv->GetField(i); bool logged = (fd->attrs && fd->FindAttr(ATTR_LOG) != nullptr); @@ -816,7 +816,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const string s = container_type_name(ft.get()); nr->Assign(0, make_intrusive(s)); nr->Assign(1, val_mgr->Bool(logged)); - nr->Assign(2, {NewRef{}, fv}); + nr->Assign(2, std::move(fv)); nr->Assign(3, FieldDefault(i)); Val* field_name = new StringVal(FieldName(i)); rval->Assign(field_name, std::move(nr)); diff --git a/src/Val.cc b/src/Val.cc index 7d5f59c60e..f31c56213d 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2741,11 +2741,6 @@ void RecordVal::Assign(int field, Val* new_val) Assign(field, {AdoptRef{}, new_val}); } -Val* RecordVal::Lookup(int field) const - { - return (*AsRecord())[field].get(); - } - IntrusivePtr RecordVal::LookupWithDefault(int field) const { const auto& val = (*AsRecord())[field]; @@ -2793,7 +2788,7 @@ IntrusivePtr RecordVal::Lookup(const char* field, bool with_default) const if ( idx < 0 ) reporter->InternalError("missing record field: %s", field); - return with_default ? LookupWithDefault(idx) : IntrusivePtr{NewRef{}, Lookup(idx)}; + return with_default ? LookupWithDefault(idx) : GetField(idx); } IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, @@ -2827,7 +2822,7 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, break; } - Val* v = Lookup(i); + const auto& v = GetField(i); if ( ! v ) // Check for allowable optional fields is outside the loop, below. @@ -2837,18 +2832,18 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, if ( ft->Tag() == TYPE_RECORD && ! same_type(ft.get(), v->GetType().get()) ) { - auto rhs = make_intrusive(IntrusivePtr{NewRef{}, v}); + auto rhs = make_intrusive(v); auto e = make_intrusive(std::move(rhs), cast_intrusive(ft)); aggr->Assign(t_i, e->Eval(nullptr)); continue; } - aggr->Assign(t_i, {NewRef{}, v}); + aggr->Assign(t_i, v); } for ( i = 0; i < ar_t->NumFields(); ++i ) - if ( ! aggr->Lookup(i) && + if ( ! aggr->GetField(i) && ! ar_t->FieldDecl(i)->FindAttr(ATTR_OPTIONAL) ) { char buf[512]; @@ -3390,12 +3385,12 @@ IntrusivePtr cast_value_to_type(Val* v, BroType* t) if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) { - auto dv = v->AsRecordVal()->Lookup(0); + const auto& dv = v->AsRecordVal()->GetField(0); if ( ! dv ) return nullptr; - return static_cast(dv)->castTo(t); + return static_cast(dv.get())->castTo(t); } return nullptr; @@ -3416,12 +3411,12 @@ bool can_cast_value_to_type(const Val* v, BroType* t) if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) { - auto dv = v->AsRecordVal()->Lookup(0); + const auto& dv = v->AsRecordVal()->GetField(0); if ( ! dv ) return false; - return static_cast(dv)->canCastTo(t); + return static_cast(dv.get())->canCastTo(t); } return false; diff --git a/src/Val.h b/src/Val.h index b635732f01..8671298135 100644 --- a/src/Val.h +++ b/src/Val.h @@ -965,7 +965,27 @@ public: void Assign(int field, std::nullptr_t) { Assign(field, IntrusivePtr{}); } - Val* Lookup(int field) const; // Does not Ref() value. + [[deprecated("Remove in v4.1. Use GetField().")]] + Val* Lookup(int field) const // Does not Ref() value. + { return (*AsRecord())[field].get(); } + + /** + * Returns the value of a given field index. + * @param field The field index to retrieve. + * @return The value at the given field index. + */ + const IntrusivePtr& GetField(int field) const + { return (*AsRecord())[field]; } + + /** + * Returns the value of a given field index as cast to type @c T. + * @param field The field index to retrieve. + * @return The value at the given field index cast to type @c T. + */ + template + IntrusivePtr GetField(int field) const + { return cast_intrusive(GetField(field)); } + IntrusivePtr LookupWithDefault(int field) const; /** diff --git a/src/analyzer/protocol/krb/krb-analyzer.pac b/src/analyzer/protocol/krb/krb-analyzer.pac index 86aa921895..928cdf4fd5 100644 --- a/src/analyzer/protocol/krb/krb-analyzer.pac +++ b/src/analyzer/protocol/krb/krb-analyzer.pac @@ -263,7 +263,7 @@ refine connection KRB_Conn += { rv->Assign(1, val_mgr->Bool(${msg.ap_options.mutual_required})); auto rvticket = proc_ticket(${msg.ticket}); - auto authenticationinfo = bro_analyzer()->GetAuthenticationInfo(rvticket->Lookup(2)->AsString(), rvticket->Lookup(4)->AsString(), rvticket->Lookup(3)->AsCount()); + auto authenticationinfo = bro_analyzer()->GetAuthenticationInfo(rvticket->GetField(2)->AsString(), rvticket->GetField(4)->AsString(), rvticket->GetField(3)->AsCount()); if ( authenticationinfo ) rvticket->Assign(5, authenticationinfo); diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index c687c85fac..1ca6bbd89d 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -175,7 +175,7 @@ bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, case BifEnum::NFS3::PROC_READ: bro_uint_t offset; - offset = c->RequestVal()->AsRecordVal()->Lookup(1)->AsCount(); + offset = c->RequestVal()->AsRecordVal()->GetField(1)->AsCount(); reply = nfs3_read_reply(buf, n, nfs_status, offset); event = nfs_proc_read; break; diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 1d1480fa42..1a35157c1b 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -125,7 +125,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu return false; RecordVal* rv = c->RequestVal()->AsRecordVal(); - Val* is_tcp = rv->Lookup(2); + const auto& is_tcp = rv->GetField(2); reply = val_mgr->Port(CheckPort(port), is_tcp->IsOne() ? TRANSPORT_TCP : TRANSPORT_UDP); event = pm_request_getport; diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index 9734ea30cb..85ef4f4a0d 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -1098,7 +1098,7 @@ void TCP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig, { syn_weirds(flags, endpoint, len); RecordVal* SYN_vals = build_syn_packet_val(is_orig, ip, tp); - init_window(endpoint, peer, flags, SYN_vals->Lookup(5)->CoerceToInt(), + init_window(endpoint, peer, flags, SYN_vals->GetField(5)->CoerceToInt(), base_seq, ack_seq); if ( connection_SYN_packet ) diff --git a/src/broker/Data.cc b/src/broker/Data.cc index a6ae4cc93a..82f41be02d 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -1124,7 +1124,7 @@ IntrusivePtr bro_broker::get_data_type(RecordVal* v, Frame* frame) broker::data& bro_broker::opaque_field_to_data(RecordVal* v, Frame* f) { - Val* d = v->Lookup(0); + const auto& d = v->GetField(0); if ( ! d ) reporter->RuntimeError(f->GetCall()->GetLocationInfo(), @@ -1132,7 +1132,7 @@ broker::data& bro_broker::opaque_field_to_data(RecordVal* v, Frame* f) // RuntimeError throws an exception which causes this line to never exceute. // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) - return static_cast(d)->data; + return static_cast(d.get())->data; } void bro_broker::DataVal::ValDescribe(ODesc* d) const diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index fb83682e86..3a1dc82906 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -386,18 +386,18 @@ bool Manager::PublishEvent(string topic, RecordVal* args) if ( peer_count == 0 ) return true; - if ( ! args->Lookup(0) ) + if ( ! args->GetField(0) ) return false; - auto event_name = args->Lookup(0)->AsString()->CheckString(); - auto vv = args->Lookup(1)->AsVectorVal(); + auto event_name = args->GetField(0)->AsString()->CheckString(); + auto vv = args->GetField(1)->AsVectorVal(); broker::vector xs; xs.reserve(vv->Size()); for ( auto i = 0u; i < vv->Size(); ++i ) { - auto val = vv->Lookup(i)->AsRecordVal()->Lookup(0); - auto data_val = static_cast(val); + const auto& val = vv->Lookup(i)->AsRecordVal()->GetField(0); + auto data_val = static_cast(val.get()); xs.emplace_back(data_val->data); } @@ -759,7 +759,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) else data_val = make_data_val((*args)[i]); - if ( ! data_val->Lookup(0) ) + if ( ! data_val->GetField(0) ) { rval->Assign(0, nullptr); Error("failed to convert param #%d of type %s to broker data", diff --git a/src/broker/Store.cc b/src/broker/Store.cc index fa76c14616..6ab0a408f3 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -104,15 +104,15 @@ broker::backend_options to_backend_options(broker::backend backend, switch ( backend ) { case broker::sqlite: { - auto path = options->Lookup(0)->AsRecordVal() - ->Lookup(0)->AsStringVal()->CheckString(); + auto path = options->GetField(0)->AsRecordVal() + ->GetField(0)->AsStringVal()->CheckString(); return {{"path", path}}; } case broker::rocksdb: { - auto path = options->Lookup(1)->AsRecordVal() - ->Lookup(0)->AsStringVal()->CheckString(); + auto path = options->GetField(1)->AsRecordVal() + ->GetField(0)->AsStringVal()->CheckString(); return {{"path", path}}; } diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 81605e3936..e514c9a266 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -21,7 +21,7 @@ using namespace file_analysis; -static IntrusivePtr empty_connection_table() +static IntrusivePtr empty_connection_table() { auto tbl_index = make_intrusive(zeek::id::conn_id); tbl_index->Append(zeek::id::conn_id); @@ -121,7 +121,7 @@ void File::UpdateLastActivityTime() double File::GetLastActivityTime() const { - return val->Lookup(last_active_idx)->AsTime(); + return val->GetField(last_active_idx)->AsTime(); } bool File::UpdateConnectionFields(Connection* conn, bool is_orig) @@ -129,7 +129,7 @@ bool File::UpdateConnectionFields(Connection* conn, bool is_orig) if ( ! conn ) return false; - Val* conns = val->Lookup(conns_idx); + Val* conns = val->GetField(conns_idx).get(); if ( ! conns ) { @@ -184,7 +184,7 @@ int File::Idx(const std::string& field, const RecordType* type) std::string File::GetSource() const { - Val* v = val->Lookup(source_idx); + const auto& v = val->GetField(source_idx); return v ? v->AsString()->CheckString() : std::string(); } @@ -234,7 +234,8 @@ void File::SetTotalBytes(uint64_t size) bool File::IsComplete() const { - Val* total = val->Lookup(total_bytes_idx); + const auto& total = val->GetField(total_bytes_idx); + if ( ! total ) return false; @@ -308,7 +309,7 @@ void File::InferMetadata() { did_metadata_inference = true; - Val* bof_buffer_val = val->Lookup(bof_buffer_idx); + Val* bof_buffer_val = val->GetField(bof_buffer_idx).get(); if ( ! bof_buffer_val ) { @@ -317,7 +318,7 @@ void File::InferMetadata() BroString* bs = concatenate(bof_buffer.chunks); val->Assign(bof_buffer_idx, bs); - bof_buffer_val = val->Lookup(bof_buffer_idx); + bof_buffer_val = val->GetField(bof_buffer_idx).get(); } if ( ! FileEventAvailable(file_sniff) ) diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 811346b766..d13c62fcb3 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1089,7 +1089,7 @@ threading::Value** Manager::RecordToFilterVals(Stream* stream, Filter* filter, for ( list::iterator j = indices.begin(); j != indices.end(); ++j ) { - val = val->AsRecordVal()->Lookup(*j); + val = val->AsRecordVal()->GetField(*j).get(); if ( ! val ) { diff --git a/src/option.bif b/src/option.bif index 84e3798744..f6869b6dad 100644 --- a/src/option.bif +++ b/src/option.bif @@ -81,7 +81,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool if ( same_type(val->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) { - auto dv = static_cast(val->AsRecordVal()->Lookup(0)); + auto dv = static_cast(val->AsRecordVal()->GetField(0).get()); auto val_from_data = dv->castTo(i->GetType().get()); if ( ! val_from_data ) diff --git a/src/reporter.bif b/src/reporter.bif index d9a8166ac1..c3faa748ed 100644 --- a/src/reporter.bif +++ b/src/reporter.bif @@ -138,7 +138,7 @@ function Reporter::conn_weird%(name: string, c: connection, addl: string &defaul ## Returns: true if the file was still valid, else false. function Reporter::file_weird%(name: string, f: fa_file, addl: string &default=""%): bool %{ - auto fuid = f->AsRecordVal()->Lookup(0)->AsStringVal(); + auto fuid = f->AsRecordVal()->GetField(0)->AsStringVal(); auto file = file_mgr->LookupFile(fuid->CheckString()); if ( ! file ) diff --git a/src/strings.bif b/src/strings.bif index 1390534d25..9d6b19884f 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -681,8 +681,8 @@ function string_to_ascii_hex%(s: string%): string ## Returns: The result of the Smith-Waterman algorithm calculation. function str_smith_waterman%(s1: string, s2: string, params: sw_params%) : sw_substring_vec %{ - SWParams sw_params(params->AsRecordVal()->Lookup(0)->AsCount(), - SWVariant(params->AsRecordVal()->Lookup(1)->AsCount())); + SWParams sw_params(params->AsRecordVal()->GetField(0)->AsCount(), + SWVariant(params->AsRecordVal()->GetField(1)->AsCount())); BroSubstring::Vec* subseq = smith_waterman(s1->AsString(), s2->AsString(), sw_params); From 2b4d80c8491112ab00b8f522cf33dc86b6b70b1b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 19 May 2020 19:49:43 -0700 Subject: [PATCH 087/151] Deprecate RecordVal::LookupWithDefault() replace with GetFieldOrDefault() (The former was previously changed during this release cycle to return Intrusive pointer, but this just changes it back to return Val* and deprecates it). --- NEWS | 3 +++ src/Val.cc | 6 +++--- src/Val.h | 14 +++++++++++++- src/broker/Data.cc | 2 +- src/file_analysis/File.cc | 4 ++-- src/file_analysis/File.h | 4 ++-- src/input/Manager.cc | 4 ++-- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index a9b426b9a9..e458562c8c 100644 --- a/NEWS +++ b/NEWS @@ -199,6 +199,9 @@ Deprecated Functionality - ``RecordVal::Lookup(int)`` is deprecated, use ``RecordVal::GetField(int)``. +- ``RecordVal::LookupWithDefault(int)`` is deprecated, use + ``RecordVal::GetFieldOrDefault(int)``. + Zeek 3.1.0 ========== diff --git a/src/Val.cc b/src/Val.cc index f31c56213d..f4c0f72d8b 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -580,7 +580,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* for ( auto i = 0; i < rt->NumFields(); ++i ) { - auto value = rval->LookupWithDefault(i); + auto value = rval->GetFieldOrDefault(i); if ( value && ( ! only_loggable || rt->FieldHasAttr(i, ATTR_LOG) ) ) { @@ -2741,7 +2741,7 @@ void RecordVal::Assign(int field, Val* new_val) Assign(field, {AdoptRef{}, new_val}); } -IntrusivePtr RecordVal::LookupWithDefault(int field) const +IntrusivePtr RecordVal::GetFieldOrDefault(int field) const { const auto& val = (*AsRecord())[field]; @@ -2788,7 +2788,7 @@ IntrusivePtr RecordVal::Lookup(const char* field, bool with_default) const if ( idx < 0 ) reporter->InternalError("missing record field: %s", field); - return with_default ? LookupWithDefault(idx) : GetField(idx); + return with_default ? GetFieldOrDefault(idx) : GetField(idx); } IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, diff --git a/src/Val.h b/src/Val.h index 8671298135..7401f9b8f3 100644 --- a/src/Val.h +++ b/src/Val.h @@ -986,7 +986,19 @@ public: IntrusivePtr GetField(int field) const { return cast_intrusive(GetField(field)); } - IntrusivePtr LookupWithDefault(int field) const; + /** + * Returns the value of a given field index if it's previously been + * assigned, * or else returns the value created from evaluating the + * record field's &default expression. + * @param field The field index to retrieve. + * @return The value at the given field index or the default value if + * the field hasn't been assigned yet. + */ + IntrusivePtr GetFieldOrDefault(int field) const; + + [[deprecated("Remove in v4.1. Use GetFieldOrDefault().")]] + Val* LookupWithDefault(int field) const + { return GetFieldOrDefault(field).release(); } /** * Looks up the value of a field by field name. If the field doesn't diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 82f41be02d..35dc12733a 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -971,7 +971,7 @@ broker::expected bro_broker::val_to_data(const Val* v) for ( auto i = 0u; i < num_fields; ++i ) { - auto item_val = rec->LookupWithDefault(i); + auto item_val = rec->GetFieldOrDefault(i); if ( ! item_val ) { diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index e514c9a266..c691880300 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -161,13 +161,13 @@ void File::RaiseFileOverNewConnection(Connection* conn, bool is_orig) uint64_t File::LookupFieldDefaultCount(int idx) const { - auto v = val->LookupWithDefault(idx); + auto v = val->GetFieldOrDefault(idx); return v->AsCount(); } double File::LookupFieldDefaultInterval(int idx) const { - auto v = val->LookupWithDefault(idx); + auto v = val->GetFieldOrDefault(idx); return v->AsInterval(); } diff --git a/src/file_analysis/File.h b/src/file_analysis/File.h index 82f286f70e..f4278500a5 100644 --- a/src/file_analysis/File.h +++ b/src/file_analysis/File.h @@ -259,7 +259,7 @@ protected: void IncrementByteCount(uint64_t size, int field_idx); /** - * Wrapper to RecordVal::LookupWithDefault for the field in #val at index + * Wrapper to RecordVal::GetFieldOrDefault for the field in #val at index * \a idx which automatically unrefs the Val and returns a converted value. * @param idx the index of a field of type "count" in \c fa_file. * @return the value of the field, which may be it &default. @@ -267,7 +267,7 @@ protected: uint64_t LookupFieldDefaultCount(int idx) const; /** - * Wrapper to RecordVal::LookupWithDefault for the field in #val at index + * Wrapper to RecordVal::GetFieldOrDefault for the field in #val at index * \a idx which automatically unrefs the Val and returns a converted value. * @param idx the index of a field of type "interval" in \c fa_file. * @return the value of the field, which may be it &default. diff --git a/src/input/Manager.cc b/src/input/Manager.cc index af80e6cbdb..d72d56a8b9 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1005,13 +1005,13 @@ Val* Manager::RecordValToIndexVal(RecordVal *r) const int num_fields = type->NumFields(); if ( num_fields == 1 && type->FieldDecl(0)->type->Tag() != TYPE_RECORD ) - idxval = r->LookupWithDefault(0); + idxval = r->GetFieldOrDefault(0); else { auto l = make_intrusive(TYPE_ANY); for ( int j = 0 ; j < num_fields; j++ ) - l->Append(r->LookupWithDefault(j)); + l->Append(r->GetFieldOrDefault(j)); idxval = std::move(l); } From 5bf2ed02d7e36da5ca05f755ad514561d78ffa56 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 19 May 2020 21:09:40 -0700 Subject: [PATCH 088/151] Deprecate RecordVal::Lookup(const char*, bool) Replace with GetField(const char*) and GetFieldOrDefault(const char*). --- NEWS | 3 ++ src/Val.cc | 14 +++++- src/Val.h | 44 ++++++++++++++++++- src/analyzer/protocol/conn-size/ConnSize.cc | 4 +- src/analyzer/protocol/icmp/ICMP.cc | 12 ++--- src/analyzer/protocol/icmp/ICMP.h | 2 +- src/analyzer/protocol/tcp/TCP.cc | 4 +- src/analyzer/protocol/udp/UDP.cc | 4 +- .../analyzer/data_event/DataEvent.cc | 4 +- src/file_analysis/analyzer/extract/Extract.cc | 8 ++-- src/file_analysis/analyzer/x509/OCSP.cc | 10 ----- src/input/Manager.cc | 39 ++++++++-------- src/logging/Manager.cc | 36 +++++++-------- src/supervisor/Supervisor.cc | 24 +++++----- 14 files changed, 128 insertions(+), 80 deletions(-) diff --git a/NEWS b/NEWS index e458562c8c..0932518fa4 100644 --- a/NEWS +++ b/NEWS @@ -202,6 +202,9 @@ Deprecated Functionality - ``RecordVal::LookupWithDefault(int)`` is deprecated, use ``RecordVal::GetFieldOrDefault(int)``. +- ``RecordVal::Lookup(const char*, bool)`` is deprecated, use either + ``RecordVal::GetField()`` or ``RecordVal::GetFieldOrDefault()``. + Zeek 3.1.0 ========== diff --git a/src/Val.cc b/src/Val.cc index f4c0f72d8b..e5d5852391 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2781,14 +2781,24 @@ void RecordVal::DoneParsing() parse_time_records.clear(); } -IntrusivePtr RecordVal::Lookup(const char* field, bool with_default) const +const IntrusivePtr& RecordVal::GetField(const char* field) const { int idx = GetType()->AsRecordType()->FieldOffset(field); if ( idx < 0 ) reporter->InternalError("missing record field: %s", field); - return with_default ? GetFieldOrDefault(idx) : GetField(idx); + return GetField(idx); + } + +IntrusivePtr RecordVal::GetFieldOrDefault(const char* field) const + { + int idx = GetType()->AsRecordType()->FieldOffset(field); + + if ( idx < 0 ) + reporter->InternalError("missing record field: %s", field); + + return GetFieldOrDefault(idx); } IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, diff --git a/src/Val.h b/src/Val.h index 7401f9b8f3..ff8c2e1c1b 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1000,6 +1000,46 @@ public: Val* LookupWithDefault(int field) const { return GetFieldOrDefault(field).release(); } + /** + * Returns the value of a given field name. + * @param field The name of a field to retrieve. + * @return The value of the given field. If no such field name exists, + * a fatal error occurs. + */ + const IntrusivePtr& GetField(const char* field) const; + + /** + * Returns the value of a given field name as cast to type @c T. + * @param field The name of a field to retrieve. + * @return The value of the given field cast to type @c T. If no such + * field name exists, a fatal error occurs. + */ + template + IntrusivePtr GetField(const char* field) const + { return cast_intrusive(GetField(field)); } + + /** + * Returns the value of a given field name if it's previously been + * assigned, or else returns the value created from evaluating the record + * fields' &default expression. + * @param field The name of a field to retrieve. + * @return The value of the given field. or the default value + * if the field hasn't been assigned yet. If no such field name exists, + * a fatal error occurs. + */ + IntrusivePtr GetFieldOrDefault(const char* field) const; + + /** + * Returns the value of a given field name or its default value + * as cast to type @c T. + * @param field The name of a field to retrieve. + * @return The value of the given field or its default value cast to + * type @c T. If no such field name exists, a fatal error occurs. + */ + template + IntrusivePtr GetFieldOrDefault(const char* field) const + { return cast_intrusive(GetField(field)); } + /** * Looks up the value of a field by field name. If the field doesn't * exist in the record type, it's an internal error: abort. @@ -1008,7 +1048,9 @@ public: * the field has yet to be initialized. * @return the value in field \a field. */ - IntrusivePtr Lookup(const char* field, bool with_default = false) const; + [[deprecated("Remove in v4.1. Use GetField() or GetFieldOrDefault().")]] + Val* Lookup(const char* field, bool with_default = false) const + { return with_default ? GetFieldOrDefault(field).release() : GetField(field).get(); } void Describe(ODesc* d) const override; diff --git a/src/analyzer/protocol/conn-size/ConnSize.cc b/src/analyzer/protocol/conn-size/ConnSize.cc index e7682111b2..28f9a95c52 100644 --- a/src/analyzer/protocol/conn-size/ConnSize.cc +++ b/src/analyzer/protocol/conn-size/ConnSize.cc @@ -170,8 +170,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->Lookup("orig")->AsRecordVal(); - RecordVal *resp_endp = conn_val->Lookup("resp")->AsRecordVal(); + RecordVal* orig_endp = conn_val->GetField("orig")->AsRecordVal(); + RecordVal* resp_endp = conn_val->GetField("resp")->AsRecordVal(); // endpoint is the RecordType from NetVar.h int pktidx = zeek::id::endpoint->FieldOffset("num_pkts"); diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 0a0eb3f1b8..664a5a8cdd 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -459,22 +459,22 @@ void ICMP_Analyzer::Describe(ODesc* d) const void ICMP_Analyzer::UpdateConnVal(RecordVal *conn_val) { - auto orig_endp = conn_val->Lookup("orig"); - auto resp_endp = conn_val->Lookup("resp"); + const auto& orig_endp = conn_val->GetField("orig"); + const auto& resp_endp = conn_val->GetField("resp"); - UpdateEndpointVal(&orig_endp, true); - UpdateEndpointVal(&resp_endp, false); + UpdateEndpointVal(orig_endp, true); + UpdateEndpointVal(resp_endp, false); // Call children's UpdateConnVal Analyzer::UpdateConnVal(conn_val); } -void ICMP_Analyzer::UpdateEndpointVal(IntrusivePtr* endp_arg, bool is_orig) +void ICMP_Analyzer::UpdateEndpointVal(const IntrusivePtr& endp_arg, bool is_orig) { Conn()->EnableStatusUpdateTimer(); int size = is_orig ? request_len : reply_len; - auto endp = (*endp_arg)->AsRecordVal(); + auto endp = endp_arg->AsRecordVal(); if ( size < 0 ) { diff --git a/src/analyzer/protocol/icmp/ICMP.h b/src/analyzer/protocol/icmp/ICMP.h index 3a91b26a5f..74ecb3a322 100644 --- a/src/analyzer/protocol/icmp/ICMP.h +++ b/src/analyzer/protocol/icmp/ICMP.h @@ -84,7 +84,7 @@ protected: RuleMatcherState matcher_state; private: - void UpdateEndpointVal(IntrusivePtr* endp, bool is_orig); + void UpdateEndpointVal(const IntrusivePtr& endp, bool is_orig); }; // Returns the counterpart type to the given type (e.g., the counterpart diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index 85ef4f4a0d..27d8235483 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -1287,8 +1287,8 @@ void TCP_Analyzer::FlipRoles() void TCP_Analyzer::UpdateConnVal(RecordVal *conn_val) { - RecordVal *orig_endp_val = conn_val->Lookup("orig")->AsRecordVal(); - RecordVal *resp_endp_val = conn_val->Lookup("resp")->AsRecordVal(); + RecordVal* orig_endp_val = conn_val->GetField("orig")->AsRecordVal(); + RecordVal* resp_endp_val = conn_val->GetField("resp")->AsRecordVal(); orig_endp_val->Assign(0, val_mgr->Count(orig->Size())); orig_endp_val->Assign(1, val_mgr->Count(int(orig->state))); diff --git a/src/analyzer/protocol/udp/UDP.cc b/src/analyzer/protocol/udp/UDP.cc index a68cd531ab..9965d3439d 100644 --- a/src/analyzer/protocol/udp/UDP.cc +++ b/src/analyzer/protocol/udp/UDP.cc @@ -216,8 +216,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->Lookup("orig")->AsRecordVal(); - RecordVal *resp_endp = conn_val->Lookup("resp")->AsRecordVal(); + RecordVal* orig_endp = conn_val->GetField("orig")->AsRecordVal(); + RecordVal* resp_endp = conn_val->GetField("resp")->AsRecordVal(); UpdateEndpointVal(orig_endp, true); UpdateEndpointVal(resp_endp, false); diff --git a/src/file_analysis/analyzer/data_event/DataEvent.cc b/src/file_analysis/analyzer/data_event/DataEvent.cc index df3f31348b..082618c4ec 100644 --- a/src/file_analysis/analyzer/data_event/DataEvent.cc +++ b/src/file_analysis/analyzer/data_event/DataEvent.cc @@ -21,8 +21,8 @@ DataEvent::DataEvent(RecordVal* args, File* file, file_analysis::Analyzer* DataEvent::Instantiate(RecordVal* args, File* file) { - auto chunk_val = args->Lookup("chunk_event"); - auto stream_val = args->Lookup("stream_event"); + const auto& chunk_val = args->GetField("chunk_event"); + const auto& stream_val = args->GetField("stream_event"); if ( ! chunk_val && ! stream_val ) return nullptr; diff --git a/src/file_analysis/analyzer/extract/Extract.cc b/src/file_analysis/analyzer/extract/Extract.cc index aa0ba1cbca..68daecab1f 100644 --- a/src/file_analysis/analyzer/extract/Extract.cc +++ b/src/file_analysis/analyzer/extract/Extract.cc @@ -32,9 +32,9 @@ Extract::~Extract() safe_close(fd); } -static IntrusivePtr get_extract_field_val(RecordVal* args, const char* name) +static const IntrusivePtr& get_extract_field_val(RecordVal* args, const char* name) { - auto rval = args->Lookup(name); + const auto& rval = args->GetField(name); if ( ! rval ) reporter->Error("File extraction analyzer missing arg field: %s", name); @@ -44,8 +44,8 @@ static IntrusivePtr get_extract_field_val(RecordVal* args, const char* name file_analysis::Analyzer* Extract::Instantiate(RecordVal* args, File* file) { - auto fname = get_extract_field_val(args, "extract_filename"); - auto limit = get_extract_field_val(args, "extract_limit"); + const auto& fname = get_extract_field_val(args, "extract_filename"); + const auto& limit = get_extract_field_val(args, "extract_limit"); if ( ! fname || ! limit ) return nullptr; diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index 5bd8a8a3c3..f2dd74883b 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -32,16 +32,6 @@ using namespace file_analysis; #define OCSP_STRING_BUF_SIZE 2048 -static IntrusivePtr get_ocsp_type(RecordVal* args, const char* name) - { - auto rval = args->Lookup(name); - - if ( ! rval ) - reporter->Error("File extraction analyzer missing arg field: %s", name); - - return rval; - } - static bool OCSP_RESPID_bio(OCSP_BASICRESP* basic_resp, BIO* bio) { #if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER) diff --git a/src/input/Manager.cc b/src/input/Manager.cc index d72d56a8b9..fcdb688087 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -233,7 +233,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) return false; } - string name = description->Lookup("name", true)->AsString()->CheckString(); + string name = description->GetFieldOrDefault("name")->AsString()->CheckString(); if ( Stream *i = FindStream(name) ) { @@ -242,17 +242,19 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) return false; } - auto reader = description->Lookup("reader", true); + auto reader = description->GetFieldOrDefault("reader"); // get the source ... - const BroString* bsource = description->Lookup("source", true)->AsString(); + auto source_val = description->GetFieldOrDefault("source"); + const BroString* bsource = source_val->AsString(); string source((const char*) bsource->Bytes(), bsource->Len()); ReaderBackend::ReaderInfo rinfo; rinfo.source = copy_string(source.c_str()); rinfo.name = copy_string(name.c_str()); - auto mode = description->Lookup("mode", true)->AsEnumVal(); + auto mode_val = description->GetFieldOrDefault("mode"); + auto mode = mode_val->AsEnumVal(); switch ( mode->InternalInt() ) { case 0: @@ -272,7 +274,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) return false; } - auto config = description->Lookup("config", true); + auto config = description->GetFieldOrDefault("config"); info->config = config.release()->AsTableVal(); { @@ -317,14 +319,15 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - string stream_name = fval->Lookup("name", true)->AsString()->CheckString(); + string stream_name = fval->GetFieldOrDefault("name")->AsString()->CheckString(); - auto fields_val = fval->Lookup("fields", true); + auto fields_val = fval->GetFieldOrDefault("fields"); RecordType* fields = fields_val->AsType()->AsTypeType()->Type()->AsRecordType(); - auto want_record = fval->Lookup("want_record", true); + auto want_record = fval->GetFieldOrDefault("want_record"); - Func* event = fval->Lookup("ev", true)->AsFunc(); + auto ev_val = fval->GetFieldOrDefault("ev"); + Func* event = ev_val->AsFunc(); const auto& etype = event->GetType(); @@ -412,7 +415,7 @@ bool Manager::CreateEventStream(RecordVal* fval) else assert(false); - auto error_event_val = fval->Lookup("error_ev", true); + auto error_event_val = fval->GetFieldOrDefault("error_ev"); Func* error_event = error_event_val ? error_event_val->AsFunc() : nullptr; if ( ! CheckErrorEventTypes(stream_name, error_event, false) ) @@ -470,19 +473,19 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - string stream_name = fval->Lookup("name", true)->AsString()->CheckString(); + string stream_name = fval->GetFieldOrDefault("name")->AsString()->CheckString(); - auto pred = fval->Lookup("pred", true); - auto idx_val = fval->Lookup("idx", true); + auto pred = fval->GetFieldOrDefault("pred"); + auto idx_val = fval->GetFieldOrDefault("idx"); RecordType* idx = idx_val->AsType()->AsTypeType()->Type()->AsRecordType(); IntrusivePtr val; - auto val_val = fval->Lookup("val", true); + auto val_val = fval->GetFieldOrDefault("val"); if ( val_val ) val = {NewRef{}, val_val->AsType()->AsTypeType()->Type()->AsRecordType()}; - auto dst = fval->Lookup("destination", true); + auto dst = fval->GetFieldOrDefault("destination"); // check if index fields match table description int num = idx->NumFields(); @@ -518,7 +521,7 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - auto want_record = fval->Lookup("want_record", true); + auto want_record = fval->GetFieldOrDefault("want_record"); if ( val ) { @@ -551,7 +554,7 @@ bool Manager::CreateTableStream(RecordVal* fval) } } - auto event_val = fval->Lookup("ev", true); + auto event_val = fval->GetFieldOrDefault("ev"); Func* event = event_val ? event_val->AsFunc() : nullptr; if ( event ) @@ -624,7 +627,7 @@ bool Manager::CreateTableStream(RecordVal* fval) assert(want_record->InternalInt() == 1 || want_record->InternalInt() == 0); } - auto error_event_val = fval->Lookup("error_ev", true); + auto error_event_val = fval->GetFieldOrDefault("error_ev"); Func* error_event = error_event_val ? error_event_val->AsFunc() : nullptr; if ( ! CheckErrorEventTypes(stream_name, error_event, true) ) diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index d13c62fcb3..2e798273ae 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -237,7 +237,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) return false; } - RecordType* columns = sval->Lookup("columns") + RecordType* columns = sval->GetField("columns") ->AsType()->AsTypeType()->Type()->AsRecordType(); bool log_attr_present = false; @@ -264,7 +264,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) return false; } - auto event_val = sval->Lookup("ev"); + const auto& event_val = sval->GetField("ev"); Func* event = event_val ? event_val->AsFunc() : nullptr; if ( event ) @@ -545,22 +545,22 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) return false; // Find the right writer type. - EnumVal* writer = fval->Lookup("writer", true)->AsEnumVal(); + auto writer = fval->GetFieldOrDefault("writer"); // Create a new Filter instance. - auto name = fval->Lookup("name", true); - auto pred = fval->Lookup("pred", true); - auto path_func = fval->Lookup("path_func", true); - auto log_local = fval->Lookup("log_local", true); - auto log_remote = fval->Lookup("log_remote", true); - auto interv = fval->Lookup("interv", true); - auto postprocessor = fval->Lookup("postprocessor", true); - auto config = fval->Lookup("config", true); - auto field_name_map = fval->Lookup("field_name_map", true); - auto scope_sep = fval->Lookup("scope_sep", true); - auto ext_prefix = fval->Lookup("ext_prefix", true); - auto ext_func = fval->Lookup("ext_func", true); + auto name = fval->GetFieldOrDefault("name"); + auto pred = fval->GetFieldOrDefault("pred"); + auto path_func = fval->GetFieldOrDefault("path_func"); + auto log_local = fval->GetFieldOrDefault("log_local"); + auto log_remote = fval->GetFieldOrDefault("log_remote"); + auto interv = fval->GetFieldOrDefault("interv"); + auto postprocessor = fval->GetFieldOrDefault("postprocessor"); + auto config = fval->GetFieldOrDefault("config"); + auto field_name_map = fval->GetFieldOrDefault("field_name_map"); + auto scope_sep = fval->GetFieldOrDefault("scope_sep"); + auto ext_prefix = fval->GetFieldOrDefault("ext_prefix"); + auto ext_func = fval->GetFieldOrDefault("ext_func"); Filter* filter = new Filter; filter->fval = fval->Ref(); @@ -581,8 +581,8 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) // Build the list of fields that the filter wants included, including // potentially rolling out fields. - auto include = fval->Lookup("include"); - auto exclude = fval->Lookup("exclude"); + const auto& include = fval->GetField("include"); + const auto& exclude = fval->GetField("exclude"); filter->num_ext_fields = 0; if ( filter->ext_func ) @@ -616,7 +616,7 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) } // Get the path for the filter. - auto path_val = fval->Lookup("path"); + auto path_val = fval->GetField("path"); if ( path_val ) { diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index ea76fd0a94..c02dc6ca5f 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -982,33 +982,33 @@ static BifEnum::Supervisor::ClusterRole role_str_to_enum(std::string_view r) Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node) { Supervisor::NodeConfig rval; - rval.name = node->Lookup("name")->AsString()->CheckString(); - auto iface_val = node->Lookup("interface"); + rval.name = node->GetField("name")->AsString()->CheckString(); + const auto& iface_val = node->GetField("interface"); if ( iface_val ) rval.interface = iface_val->AsString()->CheckString(); - auto directory_val = node->Lookup("directory"); + const auto& directory_val = node->GetField("directory"); if ( directory_val ) rval.directory = directory_val->AsString()->CheckString(); - auto stdout_val = node->Lookup("stdout_file"); + const auto& stdout_val = node->GetField("stdout_file"); if ( stdout_val ) rval.stdout_file = stdout_val->AsString()->CheckString(); - auto stderr_val = node->Lookup("stderr_file"); + const auto& stderr_val = node->GetField("stderr_file"); if ( stderr_val ) rval.stderr_file = stderr_val->AsString()->CheckString(); - auto affinity_val = node->Lookup("cpu_affinity"); + const auto& affinity_val = node->GetField("cpu_affinity"); if ( affinity_val ) rval.cpu_affinity = affinity_val->AsInt(); - auto scripts_val = node->Lookup("scripts")->AsVectorVal(); + auto scripts_val = node->GetField("scripts")->AsVectorVal(); for ( auto i = 0u; i < scripts_val->Size(); ++i ) { @@ -1016,7 +1016,7 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node) rval.scripts.emplace_back(std::move(script)); } - auto cluster_table_val = node->Lookup("cluster")->AsTableVal(); + auto cluster_table_val = node->GetField("cluster")->AsTableVal(); auto cluster_table = cluster_table_val->AsTable(); auto c = cluster_table->InitForIteration(); HashKey* k; @@ -1030,11 +1030,11 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node) auto rv = v->GetVal()->AsRecordVal(); Supervisor::ClusterEndpoint ep; - ep.role = static_cast(rv->Lookup("role")->AsEnum()); - ep.host = rv->Lookup("host")->AsAddr().AsString(); - ep.port = rv->Lookup("p")->AsPortVal()->Port(); + ep.role = static_cast(rv->GetField("role")->AsEnum()); + ep.host = rv->GetField("host")->AsAddr().AsString(); + ep.port = rv->GetField("p")->AsPortVal()->Port(); - auto iface = rv->Lookup("interface"); + const auto& iface = rv->GetField("interface"); if ( iface ) ep.interface = iface->AsStringVal()->ToStdString(); From 7e89c8f0df2fde3f840504563e47aa22af41fa33 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 12:46:51 -0700 Subject: [PATCH 089/151] Deprecate TableVal::Assign methods with Val*, add IntrusivePtr overloads --- NEWS | 3 ++ src/CompHash.cc | 4 +- src/Expr.cc | 10 ++--- src/Stats.cc | 10 ++--- src/Type.cc | 5 +-- src/Val.cc | 43 +++++++++---------- src/Val.h | 38 +++++++++++++--- .../protocol/bittorrent/BitTorrentTracker.cc | 20 +++------ src/analyzer/protocol/irc/IRC.cc | 13 +++--- src/analyzer/protocol/mime/MIME.cc | 2 +- .../protocol/radius/radius-analyzer.pac | 2 +- src/analyzer/protocol/rpc/Portmap.cc | 2 +- src/analyzer/protocol/sip/sip-analyzer.pac | 6 +-- src/broker/Data.cc | 4 +- src/file_analysis/File.cc | 2 +- src/file_analysis/analyzer/pe/pe-analyzer.pac | 2 +- src/input/Manager.cc | 13 +++--- src/reporter.bif | 2 +- src/stats.bif | 2 +- src/strings.bif | 6 +-- src/supervisor/Supervisor.cc | 8 ++-- src/zeek.bif | 4 +- 22 files changed, 106 insertions(+), 95 deletions(-) diff --git a/NEWS b/NEWS index 0932518fa4..90e2b76ffd 100644 --- a/NEWS +++ b/NEWS @@ -205,6 +205,9 @@ Deprecated Functionality - ``RecordVal::Lookup(const char*, bool)`` is deprecated, use either ``RecordVal::GetField()`` or ``RecordVal::GetFieldOrDefault()``. +- ``TableVal::Assign`` methods taking raw ``Val*`` are deprecated, use the + overloads taking ``IntrusivePtr``. + Zeek 3.1.0 ========== diff --git a/src/CompHash.cc b/src/CompHash.cc index daf896fe16..4a93675a28 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -952,13 +952,13 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, kp1 = RecoverOneVal(k, kp1, k_end, tt->Indices(), &key, false); if ( t->IsSet() ) - tv->Assign(key.get(), nullptr); + tv->Assign(std::move(key), nullptr); else { IntrusivePtr value; kp1 = RecoverOneVal(k, kp1, k_end, tt->Yield().get(), &value, false); - tv->Assign(key.get(), std::move(value)); + tv->Assign(std::move(key), std::move(value)); } } diff --git a/src/Expr.cc b/src/Expr.cc index 3300b1bda0..02a6ba83a0 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2321,7 +2321,7 @@ void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const if ( ! index || ! v ) return; - if ( ! tv->Assign(index.get(), std::move(v)) ) + if ( ! tv->Assign(std::move(index), std::move(v)) ) RuntimeError("type clash in table assignment"); } @@ -2532,7 +2532,7 @@ void IndexExpr::Add(Frame* f) if ( ! v2 ) return; - v1->AsTableVal()->Assign(v2.get(), nullptr); + v1->AsTableVal()->Assign(std::move(v2), nullptr); } void IndexExpr::Delete(Frame* f) @@ -2780,7 +2780,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) } case TYPE_TABLE: - if ( ! v1->AsTableVal()->Assign(v2.get(), std::move(v)) ) + if ( ! v1->AsTableVal()->Assign(std::move(v2), std::move(v)) ) { v = std::move(v_extra); @@ -3256,7 +3256,7 @@ IntrusivePtr SetConstructorExpr::Eval(Frame* f) const for ( const auto& expr : exprs ) { auto element = expr->Eval(f); - aggr->Assign(element.get(), nullptr); + aggr->Assign(std::move(element), nullptr); } return aggr; @@ -3278,7 +3278,7 @@ IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtrEval(nullptr), index_type, true); - if ( ! element || ! tval->Assign(element.get(), nullptr) ) + if ( ! element || ! tval->Assign(std::move(element), nullptr) ) { Error(fmt("initialization type mismatch in set"), e); return nullptr; diff --git a/src/Stats.cc b/src/Stats.cc index 09c5df495c..24e550a3d2 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -353,16 +353,14 @@ SampleLogger::~SampleLogger() void SampleLogger::FunctionSeen(const Func* func) { - Val* idx = new StringVal(func->Name()); - load_samples->Assign(idx, nullptr); - Unref(idx); + auto idx = make_intrusive(func->Name()); + load_samples->Assign(std::move(idx), nullptr); } void SampleLogger::LocationSeen(const Location* loc) { - Val* idx = new StringVal(loc->filename); - load_samples->Assign(idx, nullptr); - Unref(idx); + auto idx = make_intrusive(loc->filename); + load_samples->Assign(std::move(idx), nullptr); } void SampleLogger::SegmentProfile(const char* /* name */, diff --git a/src/Type.cc b/src/Type.cc index 0e0d00d4e5..02956ed517 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -818,9 +818,8 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const nr->Assign(1, val_mgr->Bool(logged)); nr->Assign(2, std::move(fv)); nr->Assign(3, FieldDefault(i)); - Val* field_name = new StringVal(FieldName(i)); - rval->Assign(field_name, std::move(nr)); - Unref(field_name); + auto field_name = make_intrusive(FieldName(i)); + rval->Assign(std::move(field_name), std::move(nr)); } return rval; diff --git a/src/Val.cc b/src/Val.cc index e5d5852391..88d67692e3 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1244,7 +1244,7 @@ IntrusivePtr ListVal::ToSetVal() const auto t = make_intrusive(std::move(s)); for ( const auto& val : vals ) - t->Assign(val.get(), nullptr); + t->Assign(val, nullptr); return t; } @@ -1506,24 +1506,24 @@ void TableVal::CheckExpireAttr(attr_tag at) } } -bool TableVal::Assign(Val* index, IntrusivePtr new_val) +bool TableVal::Assign(IntrusivePtr index, IntrusivePtr new_val) { - HashKey* k = ComputeHash(index); + HashKey* k = ComputeHash(index.get()); if ( ! k ) { index->Error("index type doesn't match table", table_type->Indices()); return false; } - return Assign(index, k, std::move(new_val)); + return Assign(std::move(index), k, std::move(new_val)); } bool TableVal::Assign(Val* index, Val* new_val) { - return Assign(index, {AdoptRef{}, new_val}); + return Assign({NewRef{}, index}, {AdoptRef{}, new_val}); } -bool TableVal::Assign(Val* index, HashKey* k, IntrusivePtr new_val) +bool TableVal::Assign(IntrusivePtr index, HashKey* k, IntrusivePtr new_val) { bool is_set = table_type->IsSet(); @@ -1548,7 +1548,7 @@ bool TableVal::Assign(Val* index, HashKey* k, IntrusivePtr new_val) subnets->Insert(v.get(), new_entry_val); } else - subnets->Insert(index, new_entry_val); + subnets->Insert(index.get(), new_entry_val); } // Keep old expiration time if necessary. @@ -1559,8 +1559,7 @@ bool TableVal::Assign(Val* index, HashKey* k, IntrusivePtr new_val) if ( change_func ) { - auto change_index = index ? IntrusivePtr{NewRef{}, index} - : RecoverIndex(&k_copy); + auto change_index = index ? std::move(index) : RecoverIndex(&k_copy); auto v = old_entry_val ? old_entry_val->GetVal() : new_val; CallChangeFunc(change_index.get(), v.get(), old_entry_val ? ELEMENT_CHANGED : ELEMENT_NEW); } @@ -1572,7 +1571,7 @@ bool TableVal::Assign(Val* index, HashKey* k, IntrusivePtr new_val) bool TableVal::Assign(Val* index, HashKey* k, Val* new_val) { - return Assign(index, k, {AdoptRef{}, new_val}); + return Assign({NewRef{}, index}, k, {AdoptRef{}, new_val}); } IntrusivePtr TableVal::SizeVal() const @@ -1618,7 +1617,7 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const if ( type->IsSet() ) { - if ( ! t->Assign(v->GetVal().get(), k, nullptr) ) + if ( ! t->Assign(v->GetVal(), k, nullptr) ) return false; } else @@ -1762,7 +1761,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) if ( index_type->Tag() != TYPE_LIST ) // Nothing to expand. - return CheckAndAssign(index.get(), std::move(new_val)); + return CheckAndAssign(std::move(index), std::move(new_val)); ListVal* iv = index->AsListVal(); if ( iv->BaseTag() != TYPE_ANY ) @@ -1795,7 +1794,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) if ( i >= iv->Length() ) // Nothing to expand. - return CheckAndAssign(index.get(), std::move(new_val)); + return CheckAndAssign(std::move(index), std::move(new_val)); else return ExpandCompoundAndInit(iv, i, std::move(new_val)); } @@ -1960,21 +1959,19 @@ IntrusivePtr TableVal::LookupSubnetValues(const SubNetVal* search) auto matches = subnets->FindAll(search); for ( auto element : matches ) { - SubNetVal* s = new SubNetVal(get<0>(element)); + auto s = make_intrusive(get<0>(element)); TableEntryVal* entry = reinterpret_cast(get<1>(element)); if ( entry && entry->GetVal() ) - nt->Assign(s, entry->GetVal()); + nt->Assign(std::move(s), entry->GetVal()); else - nt->Assign(s, nullptr); // set + nt->Assign(std::move(s), nullptr); // set if ( entry ) { if ( attrs && attrs->FindAttr(ATTR_EXPIRE_READ) ) entry->SetExpireAccess(network_time); } - - Unref(s); // assign does not consume index } return nt; @@ -2294,19 +2291,19 @@ bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr new_v return true; } -bool TableVal::CheckAndAssign(Val* index, IntrusivePtr new_val) +bool TableVal::CheckAndAssign(IntrusivePtr index, IntrusivePtr new_val) { Val* v = nullptr; if ( subnets ) // We need an exact match here. - v = (Val*) subnets->Lookup(index, true); + v = (Val*) subnets->Lookup(index.get(), true); else - v = Lookup(index, false).get(); + v = Lookup(index.get(), false).get(); if ( v ) index->Warn("multiple initializations for index"); - return Assign(index, std::move(new_val)); + return Assign(std::move(index), std::move(new_val)); } void TableVal::InitDefaultFunc(Frame* f) @@ -2655,7 +2652,7 @@ void TableVal::RebuildTable(ParseTimeTableState ptts) table_type->Indices())); for ( auto& [key, val] : ptts ) - Assign(key.get(), val.release()); + Assign(std::move(key), std::move(val)); } TableVal::ParseTimeTableStates TableVal::parse_time_table_states; diff --git a/src/Val.h b/src/Val.h index ff8c2e1c1b..ec8fed0ef2 100644 --- a/src/Val.h +++ b/src/Val.h @@ -741,14 +741,38 @@ public: explicit TableVal(IntrusivePtr t, IntrusivePtr attrs = nullptr); ~TableVal() override; + /** + * Assigns a value at an associated index in the table (or in the + * case of a set, just adds the index). + * @param index The key to assign. + * @param new_val The value to assign at the index. For a set, this + * must be nullptr. + * @return True if the assignment type-checked. + */ + bool Assign(IntrusivePtr index, IntrusivePtr new_val); + + /** + * Assigns a value at an associated index in the table (or in the + * case of a set, just adds the index). + * @param index The key to assign. For tables, this is allowed to be null + * (if needed, the index val can be recovered from the hash key). + * @param k A precomputed hash key to use (this method takes ownership + * of deleting it). + * @param new_val The value to assign at the index. For a set, this + * must be nullptr. + * @return True if the assignment type-checked. + */ + bool Assign(IntrusivePtr index, HashKey* k, IntrusivePtr new_val); + // Returns true if the assignment typechecked, false if not. The - // methods take ownership of new_val, but not of the index. Second - // version takes a HashKey and Unref()'s it when done. If we're a - // set, new_val has to be nil. If we aren't a set, index may be nil - // in the second version. - bool Assign(Val* index, IntrusivePtr new_val); + // methods take ownership of new_val, but not of the index. If we're + // a set, new_val has to be nil. + [[deprecated("Remove in v4.1. Use IntrusivePtr overload instead.")]] bool Assign(Val* index, Val* new_val); - bool Assign(Val* index, HashKey* k, IntrusivePtr new_val); + + // Same as other Assign() method, but takes a precomuted HashKey and + // deletes it when done. + [[deprecated("Remove in v4.1. Use IntrusivePtr overload instead.")]] bool Assign(Val* index, HashKey* k, Val* new_val); IntrusivePtr SizeVal() const override; @@ -890,7 +914,7 @@ protected: void CheckExpireAttr(attr_tag at); bool ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr new_val); - bool CheckAndAssign(Val* index, IntrusivePtr new_val); + bool CheckAndAssign(IntrusivePtr index, IntrusivePtr new_val); // Calculates default value for index. Returns 0 if none. IntrusivePtr Default(Val* index); diff --git a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc index 2257f22043..4172929eab 100644 --- a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc +++ b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc @@ -477,35 +477,29 @@ void BitTorrentTracker_Analyzer::ResponseBenc(int name_len, char* name, uint32_t ad = extract_uint32((u_char*) value); uint16_t pt = ntohs((value[4] << 8) | value[5]); - RecordVal* peer = new RecordVal(bittorrent_peer); + auto peer = make_intrusive(bittorrent_peer); peer->Assign(0, make_intrusive(ad)); peer->Assign(1, val_mgr->Port(pt, TRANSPORT_TCP)); - res_val_peers->Assign(peer, nullptr); - - Unref(peer); + res_val_peers->Assign(std::move(peer), nullptr); } } else { - StringVal* name_ = new StringVal(name_len, name); + auto name_ = make_intrusive(name_len, name); auto benc_value = make_intrusive(bittorrent_benc_value); benc_value->Assign(type, make_intrusive(value_len, value)); - res_val_benc->Assign(name_, std::move(benc_value)); - - Unref(name_); + res_val_benc->Assign(std::move(name_), std::move(benc_value)); } } void BitTorrentTracker_Analyzer::ResponseBenc(int name_len, char* name, enum btt_benc_types type, bro_int_t value) { - RecordVal* benc_value = new RecordVal(bittorrent_benc_value); - StringVal* name_ = new StringVal(name_len, name); + auto benc_value = make_intrusive(bittorrent_benc_value); + auto name_ = make_intrusive(name_len, name); benc_value->Assign(type, val_mgr->Int(value)); - res_val_benc->Assign(name_, benc_value); - - Unref(name_); + res_val_benc->Assign(std::move(name_), std::move(benc_value)); } void BitTorrentTracker_Analyzer::ResponseBody(void) diff --git a/src/analyzer/protocol/irc/IRC.cc b/src/analyzer/protocol/irc/IRC.cc index ba73af3ec6..583206bbf7 100644 --- a/src/analyzer/protocol/irc/IRC.cc +++ b/src/analyzer/protocol/irc/IRC.cc @@ -280,7 +280,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) if ( parts[i][0] == '@' ) parts[i] = parts[i].substr(1); auto idx = make_intrusive(parts[i].c_str()); - set->Assign(idx.get(), nullptr); + set->Assign(std::move(idx), nullptr); } EnqueueConnEvent(irc_names_info, @@ -471,7 +471,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) for ( unsigned int i = 0; i < parts.size(); ++i ) { auto idx = make_intrusive(parts[i].c_str()); - set->Assign(idx.get(), nullptr); + set->Assign(std::move(idx), nullptr); } EnqueueConnEvent(irc_whois_channel_line, @@ -849,7 +849,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) string empty_string = ""; for ( unsigned int i = 0; i < channels.size(); ++i ) { - RecordVal* info = new RecordVal(irc_join_info); + auto info = make_intrusive(irc_join_info); info->Assign(0, make_intrusive(nickname.c_str())); info->Assign(1, make_intrusive(channels[i].c_str())); if ( i < passwords.size() ) @@ -858,8 +858,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) info->Assign(2, make_intrusive(empty_string.c_str())); // User mode. info->Assign(3, make_intrusive(empty_string.c_str())); - list->Assign(info, nullptr); - Unref(info); + list->Assign(std::move(info), nullptr); } EnqueueConnEvent(irc_join_message, @@ -919,7 +918,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) info->Assign(2, make_intrusive(empty_string.c_str())); // User mode: info->Assign(3, make_intrusive(mode.c_str())); - list->Assign(info.get(), nullptr); + list->Assign(std::move(info), nullptr); } EnqueueConnEvent(irc_join_message, @@ -958,7 +957,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) for ( unsigned int i = 0; i < channelList.size(); ++i ) { auto idx = make_intrusive(channelList[i].c_str()); - set->Assign(idx.get(), nullptr); + set->Assign(std::move(idx), nullptr); } EnqueueConnEvent(irc_part_message, diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index 95d23bbad9..81222adf97 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -1308,7 +1308,7 @@ IntrusivePtr MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) { auto index = val_mgr->Count(i + 1); // index starting from 1 MIME_Header* h = hlist[i]; - t->Assign(index.get(), BuildHeaderVal(h)); + t->Assign(std::move(index), BuildHeaderVal(h)); } return t; diff --git a/src/analyzer/protocol/radius/radius-analyzer.pac b/src/analyzer/protocol/radius/radius-analyzer.pac index cf1548bd2f..50194a16fe 100644 --- a/src/analyzer/protocol/radius/radius-analyzer.pac +++ b/src/analyzer/protocol/radius/radius-analyzer.pac @@ -34,7 +34,7 @@ refine flow RADIUS_Flow += { { auto attribute_list = make_intrusive(zeek::BifType::Vector::RADIUS::AttributeList); attribute_list->Assign((unsigned int)0, std::move(val)); - attributes->Assign(index.get(), std::move(attribute_list)); + attributes->Assign(std::move(index), std::move(attribute_list)); } } diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 1a35157c1b..5fb2fb878e 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -151,7 +151,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu break; auto index = val_mgr->Count(++nmap); - mappings->Assign(index.get(), std::move(m)); + mappings->Assign(std::move(index), std::move(m)); } if ( ! buf ) diff --git a/src/analyzer/protocol/sip/sip-analyzer.pac b/src/analyzer/protocol/sip/sip-analyzer.pac index 91f4db8723..aad9df3a14 100644 --- a/src/analyzer/protocol/sip/sip-analyzer.pac +++ b/src/analyzer/protocol/sip/sip-analyzer.pac @@ -3,7 +3,7 @@ refine flow SIP_Flow += { %member{ int content_length; bool build_headers; - vector headers; + std::vector> headers; %} %init{ @@ -59,7 +59,7 @@ refine flow SIP_Flow += { if ( build_headers ) { - headers.push_back(build_sip_header_val(name, value)); + headers.push_back({AdoptRef{}, build_sip_header_val(name, value)}); } return true; @@ -73,7 +73,7 @@ refine flow SIP_Flow += { for ( unsigned int i = 0; i < headers.size(); ++i ) { // index starting from 1 auto index = val_mgr->Count(i + 1); - t->Assign(index.get(), headers[i]); + t->Assign(std::move(index), std::move(headers[i])); } return t; diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 35dc12733a..3670f02a1c 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -256,7 +256,7 @@ struct val_converter { } - rval->Assign(list_val.get(), nullptr); + rval->Assign(std::move(list_val), nullptr); } return rval.release(); @@ -320,7 +320,7 @@ struct val_converter { if ( ! value_val ) return nullptr; - rval->Assign(list_val.get(), std::move(value_val)); + rval->Assign(std::move(list_val), std::move(value_val)); } return rval.release(); diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index c691880300..92b0dd0e54 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -143,7 +143,7 @@ bool File::UpdateConnectionFields(Connection* conn, bool is_orig) if ( conns->AsTableVal()->Lookup(idx.get()) ) return false; - conns->AsTableVal()->Assign(idx.get(), conn->ConnVal()); + conns->AsTableVal()->Assign(std::move(idx), conn->ConnVal()); return true; } diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index cfab9f4c94..a620d1403c 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -30,7 +30,7 @@ IntrusivePtr characteristics_to_bro(uint32_t c, uint8_t len) if ( ((c >> i) & 0x1) == 1 ) { auto ch = val_mgr->Count((1<Assign(ch.get(), 0); + char_set->Assign(std::move(ch), 0); } } diff --git a/src/input/Manager.cc b/src/input/Manager.cc index fcdb688087..049d81d359 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1256,8 +1256,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) ih->idxkey = new HashKey(k->Key(), k->Size(), k->Hash()); ih->valhash = valhash; - stream->tab->Assign(idxval, k, valval); - Unref(idxval); // asssign does not consume idxval. + stream->tab->Assign({AdoptRef{}, idxval}, k, {AdoptRef{}, valval}); if ( predidx != nullptr ) Unref(predidx); @@ -1603,7 +1602,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) } - stream->tab->Assign(idxval, valval); + stream->tab->Assign({NewRef{}, idxval}, {AdoptRef{}, valval}); if ( stream->event ) { @@ -1641,7 +1640,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) } else // no predicates or other stuff - stream->tab->Assign(idxval, valval); + stream->tab->Assign({NewRef{}, idxval}, {AdoptRef{}, valval}); Unref(idxval); // not consumed by assign @@ -2331,8 +2330,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ { Val* assignval = ValueToVal(i, val->val.set_val.vals[j], type.get(), have_error); - t->Assign(assignval, nullptr); - Unref(assignval); // index is not consumed by assign. + t->Assign({AdoptRef{}, assignval}, nullptr); } return t; @@ -2512,8 +2510,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co { Val* assignval = ValueToVal(i, val->val.set_val.vals[j], have_error); - t->Assign(assignval, nullptr); - Unref(assignval); // index is not consumed by assign. + t->Assign({AdoptRef{}, assignval}, nullptr); } return t; diff --git a/src/reporter.bif b/src/reporter.bif index c3faa748ed..88c6aef5a7 100644 --- a/src/reporter.bif +++ b/src/reporter.bif @@ -157,7 +157,7 @@ function Reporter::get_weird_sampling_whitelist%(%): string_set for ( auto el : reporter->GetWeirdSamplingWhitelist() ) { auto idx = make_intrusive(el); - set->Assign(idx.get(), nullptr); + set->Assign(std::move(idx), nullptr); } return set; %} diff --git a/src/stats.bif b/src/stats.bif index 22008bc3ed..f97e00213a 100644 --- a/src/stats.bif +++ b/src/stats.bif @@ -475,7 +475,7 @@ function get_reporter_stats%(%): ReporterStats for ( auto& kv : reporter->GetWeirdsByType() ) { auto weird = make_intrusive(kv.first); - weirds_by_type->Assign(weird.get(), val_mgr->Count(kv.second)); + weirds_by_type->Assign(std::move(weird), val_mgr->Count(kv.second)); } r->Assign(n++, val_mgr->Count(reporter->GetWeirdCount())); diff --git a/src/strings.bif b/src/strings.bif index 9d6b19884f..dc5574ba04 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -287,7 +287,7 @@ Val* do_split(StringVal* str_val, RE_Matcher* re, int incl_sep, int max_num_sep) } auto ind = val_mgr->Count(++num); - a->Assign(ind.get(), make_intrusive(offset, (const char*) s)); + a->Assign(std::move(ind), make_intrusive(offset, (const char*) s)); // No more separators will be needed if this is the end of string. if ( n <= 0 ) @@ -296,7 +296,7 @@ Val* do_split(StringVal* str_val, RE_Matcher* re, int incl_sep, int max_num_sep) if ( incl_sep ) { // including the part that matches the pattern ind = val_mgr->Count(++num); - a->Assign(ind.get(), make_intrusive(end_of_match, (const char*) s+offset)); + a->Assign(std::move(ind), make_intrusive(end_of_match, (const char*) s+offset)); } if ( max_num_sep && num_sep >= max_num_sep ) @@ -919,7 +919,7 @@ function find_all%(str: string, re: pattern%) : string_set if ( n >= 0 ) { auto idx = make_intrusive(n, (const char*) t); - a->Assign(idx.get(), 0); + a->Assign(std::move(idx), 0); t += n - 1; } } diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index c02dc6ca5f..24a559ac98 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1150,7 +1150,7 @@ IntrusivePtr Supervisor::NodeConfig::ToRecord() const if ( ep.interface ) val->Assign(ept->FieldOffset("interface"), make_intrusive(*ep.interface)); - cluster_val->Assign(key.get(), std::move(val)); + cluster_val->Assign(std::move(key), std::move(val)); } return rval; @@ -1228,7 +1228,7 @@ bool Supervisor::SupervisedNode::InitCluster() const val->Assign(cluster_node_type->FieldOffset("manager"), make_intrusive(*manager_name)); - cluster_nodes->Assign(key.get(), std::move(val)); + cluster_nodes->Assign(std::move(key), std::move(val)); } cluster_manager_is_logger_id->SetVal(val_mgr->Bool(! has_logger)); @@ -1327,7 +1327,7 @@ IntrusivePtr Supervisor::Status(std::string_view node_name) const auto& node = n.second; auto key = make_intrusive(name); auto val = node.ToRecord(); - node_table_val->Assign(key.get(), std::move(val)); + node_table_val->Assign(std::move(key), std::move(val)); } } else @@ -1341,7 +1341,7 @@ IntrusivePtr Supervisor::Status(std::string_view node_name) const auto& node = it->second; auto key = make_intrusive(name); auto val = node.ToRecord(); - node_table_val->Assign(key.get(), std::move(val)); + node_table_val->Assign(std::move(key), std::move(val)); } return rval; diff --git a/src/zeek.bif b/src/zeek.bif index 5f7fb6dec3..51f5e1bd04 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1925,7 +1925,7 @@ function global_sizes%(%): var_sizes { auto id_name = make_intrusive(id->Name()); auto id_size = val_mgr->Count(id->GetVal()->MemoryAllocation()); - sizes->Assign(id_name.get(), std::move(id_size)); + sizes->Assign(std::move(id_name), std::move(id_size)); } } @@ -1962,7 +1962,7 @@ function global_ids%(%): id_table rec->Assign(6, id->GetVal()); auto id_name = make_intrusive(id->Name()); - ids->Assign(id_name.get(), std::move(rec)); + ids->Assign(std::move(id_name), std::move(rec)); } return ids; From e5f66cd2e665da3f835321f4d1cd4f91f87bdc59 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 15:13:55 -0700 Subject: [PATCH 090/151] Deprecate TableVal::Intersect(), replace with Intersection() --- src/Expr.cc | 2 +- src/Val.cc | 6 +++--- src/Val.h | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 02a6ba83a0..7b0d8e8f73 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -744,7 +744,7 @@ IntrusivePtr BinaryExpr::SetFold(Val* v1, Val* v2) const switch ( tag ) { case EXPR_AND: - return {AdoptRef{}, tv1->Intersect(tv2)}; + return tv1->Intersection(*tv2); case EXPR_OR: { diff --git a/src/Val.cc b/src/Val.cc index 88d67692e3..9e293a51b9 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1664,12 +1664,12 @@ bool TableVal::RemoveFrom(Val* val) const return true; } -TableVal* TableVal::Intersect(const TableVal* tv) const +IntrusivePtr TableVal::Intersection(const TableVal& tv) const { - TableVal* result = new TableVal(table_type); + auto result = make_intrusive(table_type); const PDict* t0 = AsTable(); - const PDict* t1 = tv->AsTable(); + const PDict* t1 = tv.AsTable(); PDict* t2 = result->AsNonConstTable(); // Figure out which is smaller; assign it to t1. diff --git a/src/Val.h b/src/Val.h index ec8fed0ef2..a552ec0e53 100644 --- a/src/Val.h +++ b/src/Val.h @@ -795,11 +795,19 @@ public: // Returns true if the addition typechecked, false if not. bool RemoveFrom(Val* v) const override; - // Returns a new table that is the intersection of this - // table and the given table. Intersection is just done - // on index, not on yield value, so this really only makes - // sense for sets. - TableVal* Intersect(const TableVal* v) const; + /** + * Returns a new table that is the intersection of this table + * and the given table. Intersection is done only on index, not on + * yield value, so this generally makes most sense to use for sets, + * not tables. + * @param v The intersecting table. + * @return The intersection of this table and the given one. + */ + IntrusivePtr Intersection(const TableVal& v) const; + + [[deprecated("Remove in v4.1. Use Intersection() instead.")]] + TableVal* Intersect(const TableVal* v) const + { return Intersection(*v).release(); } // Returns true if this set contains the same members as the // given set. Note that comparisons are done using hash keys, From e01d2c1b3709c9fa6c78a7061c613bc839924be9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 15:47:19 -0700 Subject: [PATCH 091/151] Deprecate ComputeHash(Val*) methods, replace with ComputeHash(Val&) --- src/CompHash.cc | 7 +++---- src/CompHash.h | 8 ++++++-- src/OpaqueVal.cc | 6 +++--- src/Stmt.cc | 4 ++-- src/Val.cc | 10 +++++----- src/Val.h | 6 +++++- src/file_analysis/AnalyzerSet.cc | 6 +++--- src/input/Manager.cc | 2 +- src/probabilistic/Topk.cc | 2 +- 9 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index 4a93675a28..3a35282f48 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -333,10 +333,9 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } -HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const +HashKey* CompositeHash::ComputeHash(const Val& argv, bool type_check) const { - if ( ! v ) - reporter->InternalError("null value given to CompositeHash::ComputeHash"); + auto v = &argv; if ( is_singleton ) return ComputeSingletonHash(v, type_check); @@ -350,7 +349,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const // be okay; the only thing is that the ListVal unref's it. Val* ncv = (Val*) v; lv.Append({NewRef{}, ncv}); - HashKey* hk = ComputeHash(&lv, type_check); + HashKey* hk = ComputeHash(lv, type_check); return hk; } diff --git a/src/CompHash.h b/src/CompHash.h index 849245b9db..27eb547e92 100644 --- a/src/CompHash.h +++ b/src/CompHash.h @@ -14,8 +14,12 @@ public: ~CompositeHash(); // Compute the hash corresponding to the given index val, - // or 0 if it fails to typecheck. - HashKey* ComputeHash(const Val* v, bool type_check) const; + // or nullptr if it fails to typecheck. + HashKey* ComputeHash(const Val& v, bool type_check) const; + + [[deprecated("Remove in v4.1. Pass a Val& instead.")]] + HashKey* ComputeHash(const Val* v, bool type_check) const + { return ComputeHash(*v, type_check); } // Given a hash key, recover the values used to create it. IntrusivePtr RecoverVals(const HashKey* k) const; diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 5c822f7fe5..6846485503 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -739,14 +739,14 @@ bool BloomFilterVal::Typify(IntrusivePtr arg_type) void BloomFilterVal::Add(const Val* val) { - HashKey* key = hash->ComputeHash(val, true); + HashKey* key = hash->ComputeHash(*val, true); bloom_filter->Add(key); delete key; } size_t BloomFilterVal::Count(const Val* val) const { - HashKey* key = hash->ComputeHash(val, true); + HashKey* key = hash->ComputeHash(*val, true); size_t cnt = bloom_filter->Count(key); delete key; return cnt; @@ -900,7 +900,7 @@ bool CardinalityVal::Typify(IntrusivePtr arg_type) void CardinalityVal::Add(const Val* val) { - HashKey* key = hash->ComputeHash(val, true); + HashKey* key = hash->ComputeHash(*val, true); c->AddElement(key->Hash()); delete key; } diff --git a/src/Stmt.cc b/src/Stmt.cc index 9bc48835c3..09a8d299f8 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -719,7 +719,7 @@ SwitchStmt::~SwitchStmt() bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx) { - HashKey* hk = comp_hash->ComputeHash(v, true); + HashKey* hk = comp_hash->ComputeHash(*v, true); if ( ! hk ) { @@ -763,7 +763,7 @@ std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const // Find matching expression cases. if ( case_label_value_map.Length() ) { - HashKey* hk = comp_hash->ComputeHash(v, true); + HashKey* hk = comp_hash->ComputeHash(*v, true); if ( ! hk ) { diff --git a/src/Val.cc b/src/Val.cc index 9e293a51b9..6ba6c29db4 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1508,7 +1508,7 @@ void TableVal::CheckExpireAttr(attr_tag at) bool TableVal::Assign(IntrusivePtr index, IntrusivePtr new_val) { - HashKey* k = ComputeHash(index.get()); + HashKey* k = ComputeHash(*index); if ( ! k ) { index->Error("index type doesn't match table", table_type->Indices()); @@ -1910,7 +1910,7 @@ IntrusivePtr TableVal::Lookup(Val* index, bool use_default_val) if ( tbl->Length() > 0 ) { - HashKey* k = ComputeHash(index); + HashKey* k = ComputeHash(*index); if ( k ) { TableEntryVal* v = AsTable()->Lookup(k); @@ -1985,7 +1985,7 @@ bool TableVal::UpdateTimestamp(Val* index) v = (TableEntryVal*) subnets->Lookup(index); else { - HashKey* k = ComputeHash(index); + HashKey* k = ComputeHash(*index); if ( ! k ) return false; @@ -2070,7 +2070,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe IntrusivePtr TableVal::Delete(const Val* index) { - HashKey* k = ComputeHash(index); + HashKey* k = ComputeHash(*index); TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr; IntrusivePtr va; @@ -2594,7 +2594,7 @@ unsigned int TableVal::MemoryAllocation() const + table_hash->MemoryAllocation(); } -HashKey* TableVal::ComputeHash(const Val* index) const +HashKey* TableVal::ComputeHash(const Val& index) const { return table_hash->ComputeHash(index, true); } diff --git a/src/Val.h b/src/Val.h index a552ec0e53..f5f567e06b 100644 --- a/src/Val.h +++ b/src/Val.h @@ -892,7 +892,11 @@ public: timer = nullptr; } - HashKey* ComputeHash(const Val* index) const; + HashKey* ComputeHash(const Val& index) const; + + [[deprecated("Remove in v4.1. Pass a Val& instead.")]] + HashKey* ComputeHash(const Val* index) const + { return ComputeHash(*index); } notifier::Modifiable* Modifiable() override { return this; } diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index b2ca39f954..01361339e7 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -163,11 +163,11 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set) HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const { - ListVal* lv = new ListVal(TYPE_ANY); + auto lv = make_intrusive(TYPE_ANY); lv->Append(t.AsVal()); lv->Append({NewRef{}, args}); - HashKey* key = analyzer_hash->ComputeHash(lv, true); - Unref(lv); + HashKey* key = analyzer_hash->ComputeHash(*lv, true); + if ( ! key ) reporter->InternalError("AnalyzerArgs type mismatch"); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 049d81d359..ee3e803f59 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1248,7 +1248,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) oldval = stream->tab->Lookup(idxval, false); } - HashKey* k = stream->tab->ComputeHash(idxval); + HashKey* k = stream->tab->ComputeHash(*idxval); if ( ! k ) reporter->InternalError("could not hash"); diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index f0c55c2e64..12515505a5 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -29,7 +29,7 @@ void TopkVal::Typify(IntrusivePtr t) HashKey* TopkVal::GetHash(Val* v) const { - HashKey* key = hash->ComputeHash(v, true); + HashKey* key = hash->ComputeHash(*v, true); assert(key); return key; } From b85cfc6fe4f8bf28cf18964a2cee83753ceb89f6 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 16:00:43 -0700 Subject: [PATCH 092/151] Deprecate TableVal IsSubsetOf and EqualTo taking Val*, use Val& --- src/Expr.cc | 8 ++++---- src/Val.cc | 8 ++++---- src/Val.h | 12 ++++++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 7b0d8e8f73..8f28bfdbb8 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -767,19 +767,19 @@ IntrusivePtr BinaryExpr::SetFold(Val* v1, Val* v2) const } case EXPR_EQ: - res = tv1->EqualTo(tv2); + res = tv1->EqualTo(*tv2); break; case EXPR_NE: - res = ! tv1->EqualTo(tv2); + res = ! tv1->EqualTo(*tv2); break; case EXPR_LT: - res = tv1->IsSubsetOf(tv2) && tv1->Size() < tv2->Size(); + res = tv1->IsSubsetOf(*tv2) && tv1->Size() < tv2->Size(); break; case EXPR_LE: - res = tv1->IsSubsetOf(tv2); + res = tv1->IsSubsetOf(*tv2); break; case EXPR_GE: diff --git a/src/Val.cc b/src/Val.cc index 6ba6c29db4..5213a916a3 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1695,10 +1695,10 @@ IntrusivePtr TableVal::Intersection(const TableVal& tv) const return result; } -bool TableVal::EqualTo(const TableVal* tv) const +bool TableVal::EqualTo(const TableVal& tv) const { const PDict* t0 = AsTable(); - const PDict* t1 = tv->AsTable(); + const PDict* t1 = tv.AsTable(); if ( t0->Length() != t1->Length() ) return false; @@ -1722,10 +1722,10 @@ bool TableVal::EqualTo(const TableVal* tv) const return true; } -bool TableVal::IsSubsetOf(const TableVal* tv) const +bool TableVal::IsSubsetOf(const TableVal& tv) const { const PDict* t0 = AsTable(); - const PDict* t1 = tv->AsTable(); + const PDict* t1 = tv.AsTable(); if ( t0->Length() > t1->Length() ) return false; diff --git a/src/Val.h b/src/Val.h index f5f567e06b..f4476bdd20 100644 --- a/src/Val.h +++ b/src/Val.h @@ -813,11 +813,19 @@ public: // given set. Note that comparisons are done using hash keys, // so errors can arise for compound sets such as sets-of-sets. // See https://bro-tracker.atlassian.net/browse/BIT-1949. - bool EqualTo(const TableVal* v) const; + bool EqualTo(const TableVal& v) const; + + [[deprecated("Remove in v4.1. Pass TableVal& instead.")]] + bool EqualTo(const TableVal* v) const + { return EqualTo(*v); } // Returns true if this set is a subset (not necessarily proper) // of the given set. - bool IsSubsetOf(const TableVal* v) const; + bool IsSubsetOf(const TableVal& v) const; + + [[deprecated("Remove in v4.1. Pass TableVal& instead.")]] + bool IsSubsetOf(const TableVal* v) const + { return IsSubsetOf(*v); } // Expands any lists in the index into multiple initializations. // Returns true if the initializations typecheck, false if not. From 85a0ddd62d106621729d45bf2ee3fbbf4ce84426 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 18:00:50 -0700 Subject: [PATCH 093/151] Deprecate TableVal::Lookup(), replace with Find()/FindOrDefault() --- NEWS | 3 ++ src/Anon.cc | 4 +- src/CompHash.cc | 14 +++--- src/Expr.cc | 4 +- src/Val.cc | 47 ++++++++++++++----- src/Val.h | 28 +++++++++-- src/analyzer/Manager.cc | 8 ++-- src/analyzer/protocol/dns/DNS.cc | 7 ++- .../protocol/radius/radius-analyzer.pac | 2 +- src/analyzer/protocol/tcp/TCP_Reassembler.cc | 2 +- src/analyzer/protocol/udp/UDP.cc | 8 ++-- src/file_analysis/File.cc | 2 +- src/file_analysis/Manager.cc | 2 +- src/file_analysis/analyzer/x509/X509.cc | 9 ++-- src/input/Manager.cc | 8 ++-- src/logging/Manager.cc | 18 +++---- src/zeek.bif | 2 +- 17 files changed, 105 insertions(+), 63 deletions(-) diff --git a/NEWS b/NEWS index 90e2b76ffd..ed465b2230 100644 --- a/NEWS +++ b/NEWS @@ -208,6 +208,9 @@ Deprecated Functionality - ``TableVal::Assign`` methods taking raw ``Val*`` are deprecated, use the overloads taking ``IntrusivePtr``. +- ``TableVal::Lookup()`` is deprecated, use ``TableVal::Find()`` or + ``TableVal::FindOrDefault()``. + Zeek 3.1.0 ========== diff --git a/src/Anon.cc b/src/Anon.cc index d129d0663a..e6b0ee3b80 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -387,7 +387,7 @@ void init_ip_addr_anonymizers() ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl) { TableVal* preserve_addr = nullptr; - AddrVal addr(ip); + auto addr = make_intrusive(ip); int method = -1; @@ -410,7 +410,7 @@ ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl) ipaddr32_t new_ip = 0; - if ( preserve_addr && preserve_addr->Lookup(&addr) ) + if ( preserve_addr && preserve_addr->FindOrDefault(addr) ) new_ip = ip; else if ( method >= 0 && method < NUM_ADDR_ANONYMIZATION_METHODS ) diff --git a/src/CompHash.cc b/src/CompHash.cc index 3a35282f48..7c1e70ccbc 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -238,15 +238,15 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, for ( auto& kv : hashkeys ) { auto idx = kv.second; - Val* key = lv->Idx(idx).get(); + const auto& key = lv->Idx(idx); - if ( ! (kp1 = SingleValHash(type_check, kp1, key->GetType().get(), key, - false)) ) + if ( ! (kp1 = SingleValHash(type_check, kp1, key->GetType().get(), + key.get(), false)) ) return nullptr; if ( ! v->GetType()->IsSet() ) { - auto val = tv->Lookup(key); + auto val = tv->FindOrDefault(key); if ( ! (kp1 = SingleValHash(type_check, kp1, val->GetType().get(), val.get(), false)) ) @@ -537,15 +537,15 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, auto lv = tv->ToListVal(); for ( int i = 0; i < tv->Size(); ++i ) { - Val* key = lv->Idx(i).get(); - sz = SingleTypeKeySize(key->GetType().get(), key, type_check, sz, false, + const auto& key = lv->Idx(i); + sz = SingleTypeKeySize(key->GetType().get(), key.get(), type_check, sz, false, calc_static_size); if ( ! sz ) return 0; if ( ! bt->IsSet() ) { - auto val = tv->Lookup(key); + auto val = tv->FindOrDefault(key); sz = SingleTypeKeySize(val->GetType().get(), val.get(), type_check, sz, false, calc_static_size); if ( ! sz ) diff --git a/src/Expr.cc b/src/Expr.cc index 8f28bfdbb8..52f0dcfd29 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2669,7 +2669,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const break; case TYPE_TABLE: - v = v1->AsTableVal()->Lookup(v2); // Then, we jump into the TableVal here. + v = v1->AsTableVal()->FindOrDefault({NewRef{}, v2}); // Then, we jump into the TableVal here. break; case TYPE_STRING: @@ -3995,7 +3995,7 @@ IntrusivePtr InExpr::Fold(Val* v1, Val* v2) const if ( is_vector(v2) ) res = (bool)v2->AsVectorVal()->Lookup(v1); else - res = (bool)v2->AsTableVal()->Lookup(v1, false); + res = (bool)v2->AsTableVal()->Find({NewRef{}, v1}); return val_mgr->Bool(res); } diff --git a/src/Val.cc b/src/Val.cc index 5213a916a3..f38cf5e788 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1801,7 +1801,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) } -IntrusivePtr TableVal::Default(Val* index) +IntrusivePtr TableVal::Default(const IntrusivePtr& index) { Attr* def_attr = FindAttr(ATTR_DEFAULT); @@ -1863,7 +1863,7 @@ IntrusivePtr TableVal::Default(Val* index) vl.emplace_back(v); } else - vl.emplace_back(NewRef{}, index); + vl.emplace_back(index); IntrusivePtr result; @@ -1884,26 +1884,26 @@ IntrusivePtr TableVal::Default(Val* index) return result; } -IntrusivePtr TableVal::Lookup(Val* index, bool use_default_val) +const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) { + static IntrusivePtr nil; + static IntrusivePtr exists = val_mgr->True(); + if ( subnets ) { - TableEntryVal* v = (TableEntryVal*) subnets->Lookup(index); + TableEntryVal* v = (TableEntryVal*) subnets->Lookup(index.get()); if ( v ) { if ( attrs && attrs->FindAttr(ATTR_EXPIRE_READ) ) - v->SetExpireAccess(network_time); + v->SetExpireAccess(network_time); if ( v->GetVal() ) return v->GetVal(); - return {NewRef{}, this}; + return exists; } - if ( ! use_default_val ) - return nullptr; - - return Default(index); + return nil; } const PDict* tbl = AsTable(); @@ -1924,15 +1924,36 @@ IntrusivePtr TableVal::Lookup(Val* index, bool use_default_val) if ( v->GetVal() ) return v->GetVal(); - return {NewRef{}, this}; + return exists; } } } + return nil; + } + +IntrusivePtr TableVal::FindOrDefault(const IntrusivePtr& index) + { + if ( auto rval = Find(index) ) + return rval; + + return Default(index); + } + +Val* TableVal::Lookup(Val* index, bool use_default_val) + { + static IntrusivePtr last_default; + last_default = nullptr; + IntrusivePtr idx{NewRef{}, index}; + + if ( const auto& rval = Find(idx) ) + return rval.get(); + if ( ! use_default_val ) return nullptr; - return Default(index); + last_default = Default(idx); + return last_default.get(); } IntrusivePtr TableVal::LookupSubnets(const SubNetVal* search) @@ -2298,7 +2319,7 @@ bool TableVal::CheckAndAssign(IntrusivePtr index, IntrusivePtr new_val // We need an exact match here. v = (Val*) subnets->Lookup(index.get(), true); else - v = Lookup(index.get(), false).get(); + v = Find(index).get(); if ( v ) index->Warn("multiple initializations for index"); diff --git a/src/Val.h b/src/Val.h index f4476bdd20..42210518ea 100644 --- a/src/Val.h +++ b/src/Val.h @@ -831,10 +831,32 @@ public: // Returns true if the initializations typecheck, false if not. bool ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val); + /** + * Finds an index in the table and returns its associated value. + * @param index The index to lookup in the table. + * @return The value associated with the index. If the index doesn't + * exist, this is a nullptr. For sets that don't really contain associated + * values, a placeholder value is returned to differentiate it from + * non-existent index (nullptr), but otherwise has no meaning in relation + * to the set's contents. + */ + const IntrusivePtr& Find(const IntrusivePtr& index); + + /** + * Finds an index in the table and returns its associated value or else + * the &default value. + * @param index The index to lookup in the table. + * @return The value associated with the index. If the index doesn't + * exist, instead returns the &default value. If there's no &default + * attribute, then nullptr is still returned for non-existent index. + */ + IntrusivePtr FindOrDefault(const IntrusivePtr& index); + // Returns the element's value if it exists in the table, // nil otherwise. Note, "index" is not const because we // need to Ref/Unref it when calling the default function. - IntrusivePtr Lookup(Val* index, bool use_default_val = true); + [[deprecated("Remove in v4.1. Use Find() or FindOrDefault().")]] + Val* Lookup(Val* index, bool use_default_val = true); // For a table[subnet]/set[subnet], return all subnets that cover // the given subnet. @@ -936,8 +958,8 @@ protected: bool ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr new_val); bool CheckAndAssign(IntrusivePtr index, IntrusivePtr new_val); - // Calculates default value for index. Returns 0 if none. - IntrusivePtr Default(Val* index); + // Calculates default value for index. Returns nullptr if none. + IntrusivePtr Default(const IntrusivePtr& index); // Returns true if item expiration is enabled. bool ExpirationEnabled() { return expire_time != nullptr; } diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index 2925f012cb..343641d99c 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -443,10 +443,10 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) const auto& dport = val_mgr->Port(ntohs(conn->RespPort()), TRANSPORT_TCP); if ( ! reass ) - reass = (bool)tcp_content_delivery_ports_orig->Lookup(dport.get()); + reass = (bool)tcp_content_delivery_ports_orig->FindOrDefault(dport); if ( ! reass ) - reass = (bool)tcp_content_delivery_ports_resp->Lookup(dport.get()); + reass = (bool)tcp_content_delivery_ports_resp->FindOrDefault(dport); } if ( reass ) @@ -463,9 +463,9 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) if ( resp_port == 22 || resp_port == 23 || resp_port == 513 ) { static auto stp_skip_src = zeek::id::find_val("stp_skip_src"); + auto src = make_intrusive(conn->OrigAddr()); - AddrVal src(conn->OrigAddr()); - if ( ! stp_skip_src->Lookup(&src) ) + if ( ! stp_skip_src->FindOrDefault(src) ) tcp->AddChildAnalyzer(new stepping_stone::SteppingStone_Analyzer(conn), false); } } diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index d2283a31b1..5368c7cb41 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -85,19 +85,18 @@ void DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) analyzer->ProtocolConfirmation(); - AddrVal server(analyzer->Conn()->RespAddr()); - int skip_auth = dns_skip_all_auth; int skip_addl = dns_skip_all_addl; if ( msg.ancount > 0 ) { // We did an answer, so can potentially skip auth/addl. static auto dns_skip_auth = zeek::id::find_val("dns_skip_auth"); static auto dns_skip_addl = zeek::id::find_val("dns_skip_addl"); + auto server = make_intrusive(analyzer->Conn()->RespAddr()); skip_auth = skip_auth || msg.nscount == 0 || - dns_skip_auth->Lookup(&server); + dns_skip_auth->FindOrDefault(server); skip_addl = skip_addl || msg.arcount == 0 || - dns_skip_addl->Lookup(&server); + dns_skip_addl->FindOrDefault(server); } if ( skip_auth && skip_addl ) diff --git a/src/analyzer/protocol/radius/radius-analyzer.pac b/src/analyzer/protocol/radius/radius-analyzer.pac index 50194a16fe..02c500e676 100644 --- a/src/analyzer/protocol/radius/radius-analyzer.pac +++ b/src/analyzer/protocol/radius/radius-analyzer.pac @@ -21,7 +21,7 @@ refine flow RADIUS_Flow += { auto index = val_mgr->Count(${msg.attributes[i].code}); // Do we already have a vector of attributes for this type? - auto current = attributes->Lookup(index.get()); + auto current = attributes->FindOrDefault(index); IntrusivePtr val = to_stringval(${msg.attributes[i].value}); if ( current ) diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.cc b/src/analyzer/protocol/tcp/TCP_Reassembler.cc index 5f70e02560..2e9ef2c84d 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.cc +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.cc @@ -48,7 +48,7 @@ TCP_Reassembler::TCP_Reassembler(analyzer::Analyzer* arg_dst_analyzer, const auto& ports = IsOrig() ? tcp_content_delivery_ports_orig : tcp_content_delivery_ports_resp; - auto result = ports->Lookup(dst_port_val.get()); + auto result = ports->FindOrDefault(dst_port_val); if ( (IsOrig() && tcp_content_deliver_all_orig) || (! IsOrig() && tcp_content_deliver_all_resp) || diff --git a/src/analyzer/protocol/udp/UDP.cc b/src/analyzer/protocol/udp/UDP.cc index 9965d3439d..a320b9ee76 100644 --- a/src/analyzer/protocol/udp/UDP.cc +++ b/src/analyzer/protocol/udp/UDP.cc @@ -141,8 +141,8 @@ void UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig, const auto& sport_val = val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP); const auto& dport_val = val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP); - if ( udp_content_ports->Lookup(dport_val.get()) || - udp_content_ports->Lookup(sport_val.get()) ) + if ( udp_content_ports->FindOrDefault(dport_val) || + udp_content_ports->FindOrDefault(sport_val) ) do_udp_contents = true; else { @@ -152,14 +152,14 @@ void UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig, if ( is_orig ) { - auto result = udp_content_delivery_ports_orig->Lookup(port_val.get()); + auto result = udp_content_delivery_ports_orig->FindOrDefault(port_val); if ( udp_content_deliver_all_orig || (result && result->AsBool()) ) do_udp_contents = true; } else { - auto result = udp_content_delivery_ports_resp->Lookup(port_val.get()); + auto result = udp_content_delivery_ports_resp->FindOrDefault(port_val); if ( udp_content_deliver_all_resp || (result && result->AsBool()) ) do_udp_contents = true; diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 92b0dd0e54..2c8167aaec 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -140,7 +140,7 @@ bool File::UpdateConnectionFields(Connection* conn, bool is_orig) auto idx = get_conn_id_val(conn); - if ( conns->AsTableVal()->Lookup(idx.get()) ) + if ( conns->AsTableVal()->FindOrDefault(idx) ) return false; conns->AsTableVal()->Assign(std::move(idx), conn->ConnVal()); diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index 2975025a4a..cfc61d33ae 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -434,7 +434,7 @@ bool Manager::IsDisabled(const analyzer::Tag& tag) disabled = zeek::id::find_const("Files::disable")->AsTableVal(); auto index = val_mgr->Count(bool(tag)); - auto yield = disabled->Lookup(index.get()); + auto yield = disabled->FindOrDefault(index); if ( ! yield ) return false; diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 5c5cfaaab5..edd0de10f8 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -51,7 +51,8 @@ bool file_analysis::X509::EndOfFile() hash_final(ctx, buf); std::string cert_sha256 = sha256_digest_print(buf); auto index = make_intrusive(cert_sha256); - auto entry = certificate_cache->Lookup(index.get(), false); + const auto& entry = certificate_cache->Find(index); + if ( entry ) // in this case, the certificate is in the cache and we do not // do any further processing here. However, if there is a callback, we execute it. @@ -61,8 +62,7 @@ bool file_analysis::X509::EndOfFile() // yup, let's call the callback. cache_hit_callback->Call(IntrusivePtr{NewRef{}, GetFile()->GetVal()}, - std::move(entry), - make_intrusive(cert_sha256)); + entry, make_intrusive(cert_sha256)); return false; } } @@ -250,7 +250,8 @@ X509_STORE* file_analysis::X509::GetRootStore(TableVal* root_certs) for ( int i = 0; i < idxs->Length(); ++i ) { const auto& key = idxs->Idx(i); - StringVal *sv = root_certs->Lookup(key.get())->AsStringVal(); + auto val = root_certs->FindOrDefault(key); + StringVal* sv = val->AsStringVal(); assert(sv); const uint8_t* data = sv->Bytes(); ::X509* x = d2i_X509(NULL, &data, sv->Len()); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index ee3e803f59..c8c70801b5 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1245,7 +1245,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) { assert(stream->num_val_fields > 0); // in that case, we need the old value to send the event (if we send an event). - oldval = stream->tab->Lookup(idxval, false); + oldval = stream->tab->Find({NewRef{}, idxval}); } HashKey* k = stream->tab->ComputeHash(*idxval); @@ -1344,7 +1344,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) { auto idx = stream->tab->RecoverIndex(ih->idxkey); assert(idx != nullptr); - val = stream->tab->Lookup(idx.get()); + val = stream->tab->FindOrDefault(idx); assert(val != nullptr); predidx = {AdoptRef{}, ListValToRecordVal(idx.get(), stream->itype, &startpos)}; ev = zeek::BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED); @@ -1555,7 +1555,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) if ( stream->num_val_fields > 0 ) { // in that case, we need the old value to send the event (if we send an event). - oldval = stream->tab->Lookup(idxval, false); + oldval = stream->tab->Find({NewRef{}, idxval}); } if ( oldval != nullptr ) @@ -1699,7 +1699,7 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) if ( stream->pred || stream->event ) { - auto val = stream->tab->Lookup(idxval); + auto val = stream->tab->FindOrDefault({NewRef{}, idxval}); if ( stream->pred ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 2e798273ae..8991b134d0 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -477,10 +477,8 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, // If include fields are specified, only include if explicitly listed. if ( include ) { - StringVal* new_path_val = new StringVal(new_path.c_str()); - bool result = (bool)include->Lookup(new_path_val); - - Unref(new_path_val); + auto new_path_val = make_intrusive(new_path.c_str()); + bool result = (bool)include->FindOrDefault(new_path_val); if ( ! result ) continue; @@ -489,10 +487,8 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, // If exclude fields are specified, do not only include if listed. if ( exclude ) { - StringVal* new_path_val = new StringVal(new_path.c_str()); - bool result = (bool)exclude->Lookup(new_path_val); - - Unref(new_path_val); + auto new_path_val = make_intrusive(new_path.c_str()); + bool result = (bool)exclude->FindOrDefault(new_path_val); if ( result ) continue; @@ -848,13 +844,13 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) if ( filter->field_name_map ) { const char* name = filter->fields[j]->name; - StringVal *fn = new StringVal(name); - if ( auto val = filter->field_name_map->Lookup(fn, false) ) + auto fn = make_intrusive(name); + + if ( const auto& val = filter->field_name_map->Find(fn) ) { delete [] filter->fields[j]->name; filter->fields[j]->name = copy_string(val->AsStringVal()->CheckString()); } - delete fn; } arg_fields[j] = new threading::Field(*filter->fields[j]); } diff --git a/src/zeek.bif b/src/zeek.bif index 51f5e1bd04..5d2fc12f35 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -406,7 +406,7 @@ static bool prepare_environment(TableVal* tbl, bool set) for ( int i = 0; i < idxs->Length(); ++i ) { const auto& key = idxs->Idx(i); - auto val = tbl->Lookup(key.get(), false); + const auto& val = tbl->Find(key); if ( key->GetType()->Tag() != TYPE_STRING || val->GetType()->Tag() != TYPE_STRING ) From 087a0f36366b76510b307a809583f641d9f06ba4 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 18:41:59 -0700 Subject: [PATCH 094/151] Switch Func::Call(val_list*) back to returning Val* And renamed the method returning IntrusivePtr to operator(). This corrects the deprecation process for Func::Call(val_list*). --- NEWS | 8 ++++---- src/Discard.cc | 8 ++++---- src/EventHandler.cc | 2 +- src/Expr.cc | 2 +- src/Func.cc | 10 ++++------ src/Func.h | 17 +++++++++-------- src/RuleCondition.cc | 2 +- src/Val.cc | 6 +++--- src/broker/Manager.cc | 4 ++-- src/broker/messaging.bif | 4 ++-- src/file_analysis/analyzer/x509/X509.cc | 4 ++-- src/input/Manager.cc | 2 +- src/logging/Manager.cc | 12 ++++++------ src/option.bif | 2 +- src/zeek.bif | 4 ++-- 15 files changed, 43 insertions(+), 44 deletions(-) diff --git a/NEWS b/NEWS index ed465b2230..16569dbb8e 100644 --- a/NEWS +++ b/NEWS @@ -104,10 +104,10 @@ Removed Functionality Deprecated Functionality ------------------------ -- The ``Func::Call(val_list*, ...)`` method is now deprecated. The alternate - overload taking a ``zeek::Args`` (``std::vector>``) should - be used instead. There's also now a variadic template that forwards all - arguments. +- The ``Func::Call(val_list*, ...)`` method is now deprecated. Use operator() + instead which takes a ``zeek::Args`` (``std::vector>``). + There's also a variadic template for operator() that forwards all arguments + into a ``zeek::Args`` for you. - The ``EventMgr::QueueEvent()`` and EventMgr::QueueEventFast()`` methods are now deprecated, use ``EventMgr::Enqueue()`` instead. diff --git a/src/Discard.cc b/src/Discard.cc index 6e5aee9826..1984ced575 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -43,7 +43,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_ip->Call(args)->AsBool(); + discard_packet = check_ip->operator()(args)->AsBool(); } catch ( InterpreterException& e ) @@ -98,7 +98,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_tcp->Call(args)->AsBool(); + discard_packet = check_tcp->operator()(args)->AsBool(); } catch ( InterpreterException& e ) @@ -122,7 +122,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_udp->Call(args)->AsBool(); + discard_packet = check_udp->operator()(args)->AsBool(); } catch ( InterpreterException& e ) @@ -142,7 +142,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_icmp->Call(args)->AsBool(); + discard_packet = check_icmp->operator()(args)->AsBool(); } catch ( InterpreterException& e ) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 45014bc73b..fe3472fbf5 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -115,7 +115,7 @@ void EventHandler::Call(const zeek::Args& vl, bool no_remote) if ( local ) // No try/catch here; we pass exceptions upstream. - local->Call(vl); + local->operator()(vl); } void EventHandler::NewEvent(const zeek::Args& vl) diff --git a/src/Expr.cc b/src/Expr.cc index 52f0dcfd29..fe32e54df8 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4144,7 +4144,7 @@ IntrusivePtr CallExpr::Eval(Frame* f) const if ( f ) f->SetCall(this); - ret = funcv->Call(*v, f); + ret = funcv->operator()(*v, f); if ( f ) f->SetCall(current_call); diff --git a/src/Func.cc b/src/Func.cc index 3b1b5893fe..99ec67496c 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -294,12 +294,10 @@ bool BroFunc::IsPure() const [](const Body& b) { return b.stmts->IsPure(); }); } -IntrusivePtr Func::Call(val_list* args, Frame* parent) const - { - return Call(zeek::val_list_to_args(*args), parent); - } +Val* Func::Call(val_list* args, Frame* parent) const + { return operator()(zeek::val_list_to_args(*args), parent).release(); }; -IntrusivePtr BroFunc::Call(const zeek::Args& args, Frame* parent) const +IntrusivePtr BroFunc::operator()(const zeek::Args& args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -605,7 +603,7 @@ bool BuiltinFunc::IsPure() const return is_pure; } -IntrusivePtr BuiltinFunc::Call(const zeek::Args& args, Frame* parent) const +IntrusivePtr BuiltinFunc::operator()(const zeek::Args& args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); diff --git a/src/Func.h b/src/Func.h index 6bec0d259c..6b96373045 100644 --- a/src/Func.h +++ b/src/Func.h @@ -49,8 +49,8 @@ public: const std::vector& GetBodies() const { return bodies; } bool HasBodies() const { return bodies.size(); } - [[deprecated("Remove in v4.1. Use zeek::Args overload instead.")]] - virtual IntrusivePtr Call(val_list* args, Frame* parent = nullptr) const; + [[deprecated("Remove in v4.1. Use operator() instead.")]] + Val* Call(val_list* args, Frame* parent = nullptr) const; /** * Calls a Zeek function. @@ -58,18 +58,19 @@ public: * @param parent the frame from which the function is being called. * @return the return value of the function call. */ - virtual IntrusivePtr Call(const zeek::Args& args, Frame* parent = nullptr) const = 0; + virtual IntrusivePtr operator()(const zeek::Args& args, + Frame* parent = nullptr) const = 0; /** - * A version of Call() taking a variable number of individual arguments. + * A version of operator() taking a variable number of individual arguments. */ template std::enable_if_t< std::is_convertible_v>, IntrusivePtr>, IntrusivePtr> - Call(Args&&... args) const - { return Call(zeek::Args{std::forward(args)...}); } + operator()(Args&&... args) const + { return operator()(zeek::Args{std::forward(args)...}); } // Add a new event handler to an existing function (event). virtual void AddBody(IntrusivePtr new_body, id_list* new_inits, @@ -128,7 +129,7 @@ public: ~BroFunc() override; bool IsPure() const override; - IntrusivePtr Call(const zeek::Args& args, Frame* parent) const override; + IntrusivePtr operator()(const zeek::Args& args, Frame* parent) const override; /** * Adds adds a closure to the function. Closures are cloned and @@ -224,7 +225,7 @@ public: ~BuiltinFunc() override; bool IsPure() const override; - IntrusivePtr Call(const zeek::Args& args, Frame* parent) const override; + IntrusivePtr operator()(const zeek::Args& args, Frame* parent) const override; built_in_func TheFunc() const { return func; } void Describe(ODesc* d) const override; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 86c5bbdb63..ed179f1c85 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -181,7 +181,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, try { - auto val = id->GetVal()->AsFunc()->Call(args); + auto val = id->GetVal()->AsFunc()->operator()(args); result = val && val->AsBool(); } diff --git a/src/Val.cc b/src/Val.cc index f38cf5e788..a11c26b0f7 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1869,7 +1869,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) try { - result = f->Call(vl); + result = f->operator()(vl); } catch ( InterpreterException& e ) @@ -2080,7 +2080,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe vl.emplace_back(NewRef{}, old_value); in_change_func = true; - f->Call(vl); + f->operator()(vl); } catch ( InterpreterException& e ) { @@ -2538,7 +2538,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) vl.emplace_back(std::move(idx)); } - auto result = f->Call(vl); + auto result = f->operator()(vl); if ( result ) secs = result->AsInterval(); diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 3a1dc82906..6d185084e6 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -552,8 +552,8 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int std::string serial_data(data, len); free(data); - auto v = log_topic_func->Call(IntrusivePtr{NewRef{}, stream}, - make_intrusive(path)); + auto v = log_topic_func->operator()(IntrusivePtr{NewRef{}, stream}, + make_intrusive(path)); if ( ! v ) { diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index 0189c07c82..8125020ad3 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -188,7 +188,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool topic_func = global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; - auto topic = topic_func->Call(vl); + auto topic = topic_func->operator()(vl); if ( ! topic->AsString()->Len() ) return val_mgr->False(); @@ -225,7 +225,7 @@ function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool topic_func = global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; - auto topic = topic_func->Call(vl); + auto topic = topic_func->operator()(vl); if ( ! topic->AsString()->Len() ) return val_mgr->False(); diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index edd0de10f8..6588153646 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -61,8 +61,8 @@ bool file_analysis::X509::EndOfFile() return false; // yup, let's call the callback. - cache_hit_callback->Call(IntrusivePtr{NewRef{}, GetFile()->GetVal()}, - entry, make_intrusive(cert_sha256)); + cache_hit_callback->operator()(IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + entry, make_intrusive(cert_sha256)); return false; } } diff --git a/src/input/Manager.cc b/src/input/Manager.cc index c8c70801b5..9788fbd802 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1778,7 +1778,7 @@ bool Manager::CallPred(Func* pred_func, const int numvals, ...) const va_end(lP); - auto v = pred_func->Call(vl); + auto v = pred_func->operator()(vl); if ( v ) result = v->AsBool(); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 8991b134d0..5ae05cb2af 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -721,7 +721,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) // See whether the predicates indicates that we want // to log this record. int result = 1; - auto v = filter->pred->Call(columns); + auto v = filter->pred->operator()(columns); if ( v ) result = v->AsBool(); @@ -748,9 +748,9 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) // Can be TYPE_ANY here. rec_arg = columns; - auto v = filter->path_func->Call(IntrusivePtr{NewRef{}, id}, - std::move(path_arg), - std::move(rec_arg)); + auto v = filter->path_func->operator()(IntrusivePtr{NewRef{}, id}, + std::move(path_arg), + std::move(rec_arg)); if ( ! v ) return false; @@ -1054,7 +1054,7 @@ threading::Value** Manager::RecordToFilterVals(Stream* stream, Filter* filter, if ( filter->num_ext_fields > 0 ) { - auto res = filter->ext_func->Call(IntrusivePtr{NewRef{}, filter->path_val}); + auto res = filter->ext_func->operator()(IntrusivePtr{NewRef{}, filter->path_val}); if ( res ) ext_rec = {AdoptRef{}, res.release()->AsRecordVal()}; @@ -1531,7 +1531,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con // Call the postprocessor function. int result = 0; - auto v = func->Call(std::move(info)); + auto v = func->operator()(std::move(info)); if ( v ) result = v->AsBool(); diff --git a/src/option.bif b/src/option.bif index f6869b6dad..27fd236fc2 100644 --- a/src/option.bif +++ b/src/option.bif @@ -24,7 +24,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, const IntrusiveP if ( add_loc ) vl.emplace_back(NewRef{}, location); - val = handler_function->Call(vl); // consumed by next call. + val = handler_function->operator()(vl); // consumed by next call. if ( ! val ) { diff --git a/src/zeek.bif b/src/zeek.bif index 5d2fc12f35..51a95cbaf3 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1338,8 +1338,8 @@ bool sort_function(Val* a, Val* b) if ( ! b ) return 1; - auto result = sort_function_comp->Call(IntrusivePtr{NewRef{}, a}, - IntrusivePtr{NewRef{}, b}); + auto result = sort_function_comp->operator()(IntrusivePtr{NewRef{}, a}, + IntrusivePtr{NewRef{}, b}); int int_result = result->CoerceToInt(); return int_result < 0; From dc03f0bb837471e5d08f1454a7652c1568eb0a59 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 20:29:49 -0700 Subject: [PATCH 095/151] Deprecate TableVal::Delete(), replace with Remove() --- src/Expr.cc | 2 +- src/Val.cc | 12 ++++++------ src/Val.h | 28 +++++++++++++++++++++++++--- src/input/Manager.cc | 4 ++-- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index fe32e54df8..1e01d7bc39 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2550,7 +2550,7 @@ void IndexExpr::Delete(Frame* f) if ( ! v2 ) return; - v1->AsTableVal()->Delete(v2.get()); + v1->AsTableVal()->Remove(*v2); } IntrusivePtr IndexExpr::MakeLvalue() diff --git a/src/Val.cc b/src/Val.cc index a11c26b0f7..bfa3ed9a37 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1657,7 +1657,7 @@ bool TableVal::RemoveFrom(Val* val) const // OTOH, they are both the same type, so as long as // we don't have hash keys that are keyed per dictionary, // it should work ... - t->Delete(k); + t->Remove(k); delete k; } @@ -2089,16 +2089,16 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe in_change_func = false; } -IntrusivePtr TableVal::Delete(const Val* index) +IntrusivePtr TableVal::Remove(const Val& index) { - HashKey* k = ComputeHash(*index); + HashKey* k = ComputeHash(index); TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr; IntrusivePtr va; if ( v ) va = v->GetVal() ? v->GetVal() : IntrusivePtr{NewRef{}, this}; - if ( subnets && ! subnets->Remove(index) ) + if ( subnets && ! subnets->Remove(&index) ) reporter->InternalWarning("index not in prefix table"); delete k; @@ -2107,12 +2107,12 @@ IntrusivePtr TableVal::Delete(const Val* index) Modified(); if ( change_func ) - CallChangeFunc(index, va.get(), ELEMENT_REMOVED); + CallChangeFunc(&index, va.get(), ELEMENT_REMOVED); return va; } -IntrusivePtr TableVal::Delete(const HashKey* k) +IntrusivePtr TableVal::Remove(const HashKey* k) { TableEntryVal* v = AsNonConstTable()->RemoveEntry(k); IntrusivePtr va; diff --git a/src/Val.h b/src/Val.h index 42210518ea..c00dc07afc 100644 --- a/src/Val.h +++ b/src/Val.h @@ -875,9 +875,31 @@ public: // Returns the index corresponding to the given HashKey. IntrusivePtr RecoverIndex(const HashKey* k) const; - // Returns the element if it was in the table, false otherwise. - IntrusivePtr Delete(const Val* index); - IntrusivePtr Delete(const HashKey* k); + /** + * Remove an element from the table and return it. + * @param index The index to remove. + * @return The value associated with the index if it exists, else nullptr. + * For a sets that don't really contain associated values, a placeholder + * value is returned to differentiate it from non-existent index (nullptr), + * but otherwise has no meaning in relation to the set's contents. + */ + IntrusivePtr Remove(const Val& index); + + /** + * Same as Remove(const Val&), but uses a precomputed hash key. + * @param k The hash key to lookup. This method takes ownership of + * deleting it. + * @return Same as Remove(const Val&). + */ + IntrusivePtr Remove(const HashKey* k); + + [[deprecated("Remove in v4.1. Use Remove().")]] + Val* Delete(const Val* index) + { return Remove(*index).release(); } + + [[deprecated("Remove in v4.1. Use Remove().")]] + Val* Delete(const HashKey* k) + { return Remove(k).release(); } // Returns a ListVal representation of the table (which must be a set). IntrusivePtr ToListVal(TypeTag t = TYPE_ANY) const; diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 9788fbd802..1191b6233f 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1371,7 +1371,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) SendEvent(stream->event, 4, stream->description->Ref(), ev->Ref(), predidx->Ref(), val->Ref()); - stream->tab->Delete(ih->idxkey); + stream->tab->Remove(ih->idxkey); stream->lastDict->Remove(lastDictIdxKey); // delete in next line delete lastDictIdxKey; delete(ih); @@ -1737,7 +1737,7 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) // only if stream = true -> no streaming if ( streamresult ) { - if ( ! stream->tab->Delete(idxval) ) + if ( ! stream->tab->Remove(*idxval) ) Warning(i, "Internal error while deleting values from input table"); } } From ad224419ad7ab0592a8b1384b753dd2060f3f7ab Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 20:35:08 -0700 Subject: [PATCH 096/151] Deprecate TableVal::Attrs(), replace with GetAttrs() --- src/Expr.cc | 3 +-- src/Val.h | 5 +++++ src/option.bif | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 1e01d7bc39..27594c23e2 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3757,8 +3757,7 @@ IntrusivePtr TableCoerceExpr::Fold(Val* v) const if ( tv->Size() > 0 ) RuntimeErrorWithCallStack("coercion of non-empty table/set"); - return make_intrusive(GetType(), - IntrusivePtr{NewRef{}, tv->Attrs()}); + return make_intrusive(GetType(), tv->GetAttrs()); } VectorCoerceExpr::VectorCoerceExpr(IntrusivePtr arg_op, diff --git a/src/Val.h b/src/Val.h index c00dc07afc..83c36b400c 100644 --- a/src/Val.h +++ b/src/Val.h @@ -915,8 +915,13 @@ public: void SetAttrs(IntrusivePtr attrs); Attr* FindAttr(attr_tag t) const; + + [[deprecated("Remove in v4.1. Use GetAttrs().")]] Attributes* Attrs() { return attrs.get(); } + const IntrusivePtr& GetAttrs() const + { return attrs; } + // Returns the size of the table. int Size() const; int RecursiveSize() const; diff --git a/src/option.bif b/src/option.bif index 27fd236fc2..9f3f359148 100644 --- a/src/option.bif +++ b/src/option.bif @@ -104,7 +104,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool // Just coerce an empty/unspecified table to the right type. auto tv = make_intrusive( cast_intrusive(i->GetType()), - IntrusivePtr{NewRef{}, i->GetVal()->AsTableVal()->Attrs()}); + i->GetVal()->AsTableVal()->GetAttrs()); auto rval = call_option_handlers_and_set_value(ID, i, std::move(tv), location); return val_mgr->Bool(rval); } From 8a6a92c348afc0d6b5ddbecb47376cacfe54d377 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 20:42:18 -0700 Subject: [PATCH 097/151] Add back in a deprecated TableVal ctor taking raw pointers --- src/Val.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Val.h b/src/Val.h index 83c36b400c..7effbacb1d 100644 --- a/src/Val.h +++ b/src/Val.h @@ -739,6 +739,11 @@ class Frame; class TableVal final : public Val, public notifier::Modifiable { public: explicit TableVal(IntrusivePtr t, IntrusivePtr attrs = nullptr); + [[deprecated("Remove in v4.1. Construct from IntrusivePtrs instead.")]] + explicit TableVal(TableType* t, Attributes* attrs = nullptr) + : TableVal({NewRef{}, t}, {NewRef{}, attrs}) + {} + ~TableVal() override; /** From 3f92df51b710cb62c3b8ab3efb1a4e0f5850f4ae Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 22:16:47 -0700 Subject: [PATCH 098/151] Improve TableVal HashKey management * Deprecated ComputeHash() methods and replaced with MakeHashKey() which returns std::unique_ptr * Deprecated RecoverIndex() and replaced with RecreateIndex() which takes HashKey& and returns IntrusivePtr. * Updated the new TableVal Assign()/Remove() methods to take either std::unique_ptr or HashKey& as appropriate for clarity of ownership expectations. --- src/CompHash.cc | 39 +++++++++-------- src/CompHash.h | 18 +++++--- src/Dict.h | 2 + src/IPAddr.cc | 10 ++++- src/IPAddr.h | 13 ++++-- src/OpaqueVal.cc | 13 +++--- src/Reporter.cc | 2 +- src/Stmt.cc | 18 +++----- src/Val.cc | 72 +++++++++++++++++--------------- src/Val.h | 35 ++++++++++------ src/broker/Data.cc | 2 +- src/broker/messaging.bif | 2 +- src/file_analysis/AnalyzerSet.cc | 4 +- src/input/Manager.cc | 11 ++--- src/logging/Manager.cc | 2 +- src/probabilistic/Topk.cc | 4 +- src/reporter.bif | 2 +- src/supervisor/Supervisor.cc | 2 +- 18 files changed, 137 insertions(+), 114 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index 7c1e70ccbc..ea754dcea1 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -229,7 +229,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, while ( tbl->NextEntry(k, it) ) { hashkeys[k] = idx++; - lv->Append(tv->RecoverIndex(k)); + lv->Append(tv->RecreateIndex(*k)); } for ( auto& kv : hashkeys ) @@ -333,7 +333,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } -HashKey* CompositeHash::ComputeHash(const Val& argv, bool type_check) const +std::unique_ptr CompositeHash::MakeHashKey(const Val& argv, bool type_check) const { auto v = &argv; @@ -349,8 +349,7 @@ HashKey* CompositeHash::ComputeHash(const Val& argv, bool type_check) const // be okay; the only thing is that the ListVal unref's it. Val* ncv = (Val*) v; lv.Append({NewRef{}, ncv}); - HashKey* hk = ComputeHash(lv, type_check); - return hk; + return MakeHashKey(lv, type_check); } char* k = key; @@ -383,10 +382,10 @@ HashKey* CompositeHash::ComputeHash(const Val& argv, bool type_check) const return nullptr; } - return new HashKey((k == key), (void*) k, kp - k); + return std::make_unique((k == key), (void*) k, kp - k); } -HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) const +std::unique_ptr CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) const { if ( v->GetType()->Tag() == TYPE_LIST ) { @@ -404,21 +403,21 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) cons switch ( singleton_tag ) { case TYPE_INTERNAL_INT: case TYPE_INTERNAL_UNSIGNED: - return new HashKey(v->ForceAsInt()); + return std::make_unique(v->ForceAsInt()); case TYPE_INTERNAL_ADDR: - return v->AsAddr().GetHashKey(); + return v->AsAddr().MakeHashKey(); case TYPE_INTERNAL_SUBNET: - return v->AsSubNet().GetHashKey(); + return v->AsSubNet().MakeHashKey(); case TYPE_INTERNAL_DOUBLE: - return new HashKey(v->InternalDouble()); + return std::make_unique(v->InternalDouble()); case TYPE_INTERNAL_VOID: case TYPE_INTERNAL_OTHER: if ( v->GetType()->Tag() == TYPE_FUNC ) - return new HashKey(v->AsFunc()->GetUniqueFuncID()); + return std::make_unique(v->AsFunc()->GetUniqueFuncID()); if ( v->GetType()->Tag() == TYPE_PATTERN ) { @@ -430,14 +429,14 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) cons char* key = new char[n]; std::memcpy(key, texts[0], strlen(texts[0]) + 1); std::memcpy(key + strlen(texts[0]) + 1, texts[1], strlen(texts[1]) + 1); - return new HashKey(false, key, n); + return std::make_unique(false, key, n); } reporter->InternalError("bad index type in CompositeHash::ComputeSingletonHash"); return nullptr; case TYPE_INTERNAL_STRING: - return new HashKey(v->AsString()); + return std::make_unique(v->AsString()); case TYPE_INTERNAL_ERROR: return nullptr; @@ -707,12 +706,12 @@ int CompositeHash::SizeAlign(int offset, unsigned int size) const return offset; } -IntrusivePtr CompositeHash::RecoverVals(const HashKey* k) const +IntrusivePtr CompositeHash::RecoverVals(const HashKey& k) const { auto l = make_intrusive(TYPE_ANY); const auto& tl = type->Types(); - const char* kp = (const char*) k->Key(); - const char* const k_end = kp + k->Size(); + const char* kp = (const char*) k.Key(); + const char* const k_end = kp + k.Size(); for ( const auto& type : tl ) { @@ -728,12 +727,12 @@ IntrusivePtr CompositeHash::RecoverVals(const HashKey* k) const return l; } -const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, +const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, const char* const k_end, BroType* t, IntrusivePtr* pval, bool optional) const { // k->Size() == 0 for a single empty string. - if ( kp0 >= k_end && k->Size() > 0 ) + if ( kp0 >= k_end && k.Size() > 0 ) reporter->InternalError("over-ran key in CompositeHash::RecoverVals"); TypeTag tag = t->Tag(); @@ -874,7 +873,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, kp1 = kp0; int divider = strlen(kp0) + 1; re = new RE_Matcher(kp1, kp1 + divider); - kp1 += k->Size(); + kp1 += k.Size(); } else { @@ -1033,7 +1032,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, if ( is_singleton ) { kp1 = kp0; - n = k->Size(); + n = k.Size(); } else { diff --git a/src/CompHash.h b/src/CompHash.h index 27eb547e92..e3204fe630 100644 --- a/src/CompHash.h +++ b/src/CompHash.h @@ -2,6 +2,8 @@ #pragma once +#include + #include "Type.h" #include "IntrusivePtr.h" @@ -15,19 +17,23 @@ public: // Compute the hash corresponding to the given index val, // or nullptr if it fails to typecheck. - HashKey* ComputeHash(const Val& v, bool type_check) const; + std::unique_ptr MakeHashKey(const Val& v, bool type_check) const; - [[deprecated("Remove in v4.1. Pass a Val& instead.")]] + [[deprecated("Remove in v4.1. Use MakeHashKey().")]] HashKey* ComputeHash(const Val* v, bool type_check) const - { return ComputeHash(*v, type_check); } + { return MakeHashKey(*v, type_check).release(); } // Given a hash key, recover the values used to create it. - IntrusivePtr RecoverVals(const HashKey* k) const; + IntrusivePtr RecoverVals(const HashKey& k) const; + + [[deprecated("Remove in v4.1. Pass in HashKey& instead.")]] + IntrusivePtr RecoverVals(const HashKey* k) const + { return RecoverVals(*k); } unsigned int MemoryAllocation() const { return padded_sizeof(*this) + pad_size(size); } protected: - HashKey* ComputeSingletonHash(const Val* v, bool type_check) const; + std::unique_ptr ComputeSingletonHash(const Val* v, bool type_check) const; // Computes the piece of the hash for Val*, returning the new kp. // Used as a helper for ComputeHash in the non-singleton case. @@ -38,7 +44,7 @@ protected: // Upon return, pval will point to the recovered Val of type t. // Returns and updated kp for the next Val. Calls reporter->InternalError() // upon errors, so there is no return value for invalid input. - const char* RecoverOneVal(const HashKey* k, + const char* RecoverOneVal(const HashKey& k, const char* kp, const char* const k_end, BroType* t, IntrusivePtr* pval, bool optional) const; diff --git a/src/Dict.h b/src/Dict.h index d4187aa01f..22840a0dad 100644 --- a/src/Dict.h +++ b/src/Dict.h @@ -218,4 +218,6 @@ public: { return (T*) Dictionary::NextEntry(h, cookie, 1); } T* RemoveEntry(const HashKey* key) { return (T*) Remove(key->Key(), key->Size(), key->Hash()); } + T* RemoveEntry(const HashKey& key) + { return (T*) Remove(key.Key(), key.Size(), key.Hash()); } }; diff --git a/src/IPAddr.cc b/src/IPAddr.cc index f097307daf..4db211da02 100644 --- a/src/IPAddr.cc +++ b/src/IPAddr.cc @@ -53,8 +53,11 @@ IPAddr::IPAddr(const BroString& s) } HashKey* IPAddr::GetHashKey() const + { return MakeHashKey().release(); } + +std::unique_ptr IPAddr::MakeHashKey() const { - return new HashKey((void*)in6.s6_addr, sizeof(in6.s6_addr)); + return std::make_unique((void*)in6.s6_addr, sizeof(in6.s6_addr)); } static inline uint32_t bit_mask32(int bottom_bits) @@ -303,6 +306,9 @@ std::string IPPrefix::AsString() const } HashKey* IPPrefix::GetHashKey() const + { return MakeHashKey().release(); } + +std::unique_ptr IPPrefix::MakeHashKey() const { struct { in6_addr ip; @@ -312,7 +318,7 @@ HashKey* IPPrefix::GetHashKey() const key.ip = prefix.in6; key.len = Length(); - return new HashKey(&key, sizeof(key)); + return std::make_unique(&key, sizeof(key)); } bool IPPrefix::ConvertString(const char* text, IPPrefix* result) diff --git a/src/IPAddr.h b/src/IPAddr.h index 6fb5a124dc..a945c8b53f 100644 --- a/src/IPAddr.h +++ b/src/IPAddr.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "threading/SerialTypes.h" @@ -247,9 +248,11 @@ public: } /** - * Returns a key that can be used to lookup the IP Address in a hash - * table. Passes ownership to caller. + * Returns a key that can be used to lookup the IP Address in a hash table. */ + std::unique_ptr MakeHashKey() const; + + [[deprecated("Remove in v4.1. Use MakeHashKey().")]] HashKey* GetHashKey() const; /** @@ -629,9 +632,11 @@ public: operator std::string() const { return AsString(); } /** - * Returns a key that can be used to lookup the IP Prefix in a hash - * table. Passes ownership to caller. + * Returns a key that can be used to lookup the IP Prefix in a hash table. */ + std::unique_ptr MakeHashKey() const; + + [[deprecated("Remove in v4.1. Use MakeHashKey().")]] HashKey* GetHashKey() const; /** Converts the prefix into the type used internally by the diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 6846485503..80d8462949 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -739,16 +739,14 @@ bool BloomFilterVal::Typify(IntrusivePtr arg_type) void BloomFilterVal::Add(const Val* val) { - HashKey* key = hash->ComputeHash(*val, true); - bloom_filter->Add(key); - delete key; + auto key = hash->MakeHashKey(*val, true); + bloom_filter->Add(key.get()); } size_t BloomFilterVal::Count(const Val* val) const { - HashKey* key = hash->ComputeHash(*val, true); - size_t cnt = bloom_filter->Count(key); - delete key; + auto key = hash->MakeHashKey(*val, true); + size_t cnt = bloom_filter->Count(key.get()); return cnt; } @@ -900,9 +898,8 @@ bool CardinalityVal::Typify(IntrusivePtr arg_type) void CardinalityVal::Add(const Val* val) { - HashKey* key = hash->ComputeHash(*val, true); + auto key = hash->MakeHashKey(*val, true); c->AddElement(key->Hash()); - delete key; } IMPLEMENT_OPAQUE_VALUE(CardinalityVal) diff --git a/src/Reporter.cc b/src/Reporter.cc index 923d74615f..5cd6161c8c 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -78,7 +78,7 @@ void Reporter::InitOptions() while ( (v = wl_table->NextEntry(k, c)) ) { - auto index = wl_val->RecoverIndex(k); + auto index = wl_val->RecreateIndex(*k); std::string key = index->Idx(0)->AsString()->CheckString(); weird_sampling_whitelist.emplace(move(key)); delete k; diff --git a/src/Stmt.cc b/src/Stmt.cc index 09a8d299f8..3dcd4374b4 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -719,7 +719,7 @@ SwitchStmt::~SwitchStmt() bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx) { - HashKey* hk = comp_hash->ComputeHash(*v, true); + auto hk = comp_hash->MakeHashKey(*v, true); if ( ! hk ) { @@ -728,16 +728,12 @@ bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx) type_name(v->GetType()->Tag()), type_name(e->GetType()->Tag())); } - int* label_idx = case_label_value_map.Lookup(hk); + int* label_idx = case_label_value_map.Lookup(hk.get()); if ( label_idx ) - { - delete hk; return false; - } - case_label_value_map.Insert(hk, new int(idx)); - delete hk; + case_label_value_map.Insert(hk.get(), new int(idx)); return true; } @@ -763,7 +759,7 @@ std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const // Find matching expression cases. if ( case_label_value_map.Length() ) { - HashKey* hk = comp_hash->ComputeHash(*v, true); + auto hk = comp_hash->MakeHashKey(*v, true); if ( ! hk ) { @@ -773,10 +769,8 @@ std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const return std::make_pair(-1, nullptr); } - if ( auto i = case_label_value_map.Lookup(hk) ) + if ( auto i = case_label_value_map.Lookup(hk.get()) ) label_idx = *i; - - delete hk; } // Find matching type cases. @@ -1193,7 +1187,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const IterCookie* c = loop_vals->InitForIteration(); while ( (current_tev = loop_vals->NextEntry(k, c)) ) { - auto ind_lv = tv->RecoverIndex(k); + auto ind_lv = tv->RecreateIndex(*k); delete k; if ( value_var ) diff --git a/src/Val.cc b/src/Val.cc index bfa3ed9a37..370fa1fbac 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -540,7 +540,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* auto c = table->InitForIteration(); while ( (entry = table->NextEntry(k, c)) ) { - auto lv = tval->RecoverIndex(k); + auto lv = tval->RecreateIndex(*k); delete k; Val* entry_key = lv->Length() == 1 ? lv->Idx(0).get() : lv.get(); @@ -1508,14 +1508,15 @@ void TableVal::CheckExpireAttr(attr_tag at) bool TableVal::Assign(IntrusivePtr index, IntrusivePtr new_val) { - HashKey* k = ComputeHash(*index); + auto k = MakeHashKey(*index); + if ( ! k ) { index->Error("index type doesn't match table", table_type->Indices()); return false; } - return Assign(std::move(index), k, std::move(new_val)); + return Assign(std::move(index), std::move(k), std::move(new_val)); } bool TableVal::Assign(Val* index, Val* new_val) @@ -1523,7 +1524,8 @@ bool TableVal::Assign(Val* index, Val* new_val) return Assign({NewRef{}, index}, {AdoptRef{}, new_val}); } -bool TableVal::Assign(IntrusivePtr index, HashKey* k, IntrusivePtr new_val) +bool TableVal::Assign(IntrusivePtr index, std::unique_ptr k, + IntrusivePtr new_val) { bool is_set = table_type->IsSet(); @@ -1532,19 +1534,18 @@ bool TableVal::Assign(IntrusivePtr index, HashKey* k, IntrusivePtr new TableEntryVal* new_entry_val = new TableEntryVal(new_val); HashKey k_copy(k->Key(), k->Size(), k->Hash()); - TableEntryVal* old_entry_val = AsNonConstTable()->Insert(k, new_entry_val); + TableEntryVal* old_entry_val = AsNonConstTable()->Insert(k.get(), new_entry_val); // If the dictionary index already existed, the insert may free up the // memory allocated to the key bytes, so have to assume k is invalid // from here on out. - delete k; k = nullptr; if ( subnets ) { if ( ! index ) { - auto v = RecoverIndex(&k_copy); + auto v = RecreateIndex(k_copy); subnets->Insert(v.get(), new_entry_val); } else @@ -1559,7 +1560,7 @@ bool TableVal::Assign(IntrusivePtr index, HashKey* k, IntrusivePtr new if ( change_func ) { - auto change_index = index ? std::move(index) : RecoverIndex(&k_copy); + auto change_index = index ? std::move(index) : RecreateIndex(k_copy); auto v = old_entry_val ? old_entry_val->GetVal() : new_val; CallChangeFunc(change_index.get(), v.get(), old_entry_val ? ELEMENT_CHANGED : ELEMENT_NEW); } @@ -1571,7 +1572,7 @@ bool TableVal::Assign(IntrusivePtr index, HashKey* k, IntrusivePtr new bool TableVal::Assign(Val* index, HashKey* k, Val* new_val) { - return Assign({NewRef{}, index}, k, {AdoptRef{}, new_val}); + return Assign({NewRef{}, index}, std::unique_ptr{k}, {AdoptRef{}, new_val}); } IntrusivePtr TableVal::SizeVal() const @@ -1607,9 +1608,11 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const TableEntryVal* v; while ( (v = tbl->NextEntry(k, c)) ) { + std::unique_ptr hk{k}; + if ( is_first_init && t->AsTable()->Lookup(k) ) { - auto key = table_hash->RecoverVals(k); + auto key = table_hash->RecoverVals(*k); // ### Shouldn't complain if their values are equal. key->Warn("multiple initializations for index"); continue; @@ -1617,12 +1620,12 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const if ( type->IsSet() ) { - if ( ! t->Assign(v->GetVal(), k, nullptr) ) + if ( ! t->Assign(v->GetVal(), std::move(hk), nullptr) ) return false; } else { - if ( ! t->Assign(nullptr, k, v->GetVal()) ) + if ( ! t->Assign(nullptr, std::move(hk), v->GetVal()) ) return false; } } @@ -1657,7 +1660,7 @@ bool TableVal::RemoveFrom(Val* val) const // OTOH, they are both the same type, so as long as // we don't have hash keys that are keyed per dictionary, // it should work ... - t->Remove(k); + t->Remove(*k); delete k; } @@ -1910,11 +1913,11 @@ const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) if ( tbl->Length() > 0 ) { - HashKey* k = ComputeHash(*index); + auto k = MakeHashKey(*index); + if ( k ) { - TableEntryVal* v = AsTable()->Lookup(k); - delete k; + TableEntryVal* v = AsTable()->Lookup(k.get()); if ( v ) { @@ -2006,13 +2009,12 @@ bool TableVal::UpdateTimestamp(Val* index) v = (TableEntryVal*) subnets->Lookup(index); else { - HashKey* k = ComputeHash(*index); + auto k = MakeHashKey(*index); + if ( ! k ) return false; - v = AsTable()->Lookup(k); - - delete k; + v = AsTable()->Lookup(k.get()); } if ( ! v ) @@ -2023,7 +2025,7 @@ bool TableVal::UpdateTimestamp(Val* index) return true; } -IntrusivePtr TableVal::RecoverIndex(const HashKey* k) const +IntrusivePtr TableVal::RecreateIndex(const HashKey& k) const { return table_hash->RecoverVals(k); } @@ -2091,8 +2093,8 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe IntrusivePtr TableVal::Remove(const Val& index) { - HashKey* k = ComputeHash(index); - TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr; + auto k = MakeHashKey(index); + TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k.get()) : nullptr; IntrusivePtr va; if ( v ) @@ -2101,7 +2103,6 @@ IntrusivePtr TableVal::Remove(const Val& index) if ( subnets && ! subnets->Remove(&index) ) reporter->InternalWarning("index not in prefix table"); - delete k; delete v; Modified(); @@ -2112,7 +2113,7 @@ IntrusivePtr TableVal::Remove(const Val& index) return va; } -IntrusivePtr TableVal::Remove(const HashKey* k) +IntrusivePtr TableVal::Remove(const HashKey& k) { TableEntryVal* v = AsNonConstTable()->RemoveEntry(k); IntrusivePtr va; @@ -2151,7 +2152,7 @@ IntrusivePtr TableVal::ToListVal(TypeTag t) const HashKey* k; while ( tbl->NextEntry(k, c) ) { - auto index = table_hash->RecoverVals(k); + auto index = table_hash->RecoverVals(*k); if ( t == TYPE_ANY ) l->Append(std::move(index)); @@ -2226,7 +2227,7 @@ void TableVal::Describe(ODesc* d) const if ( ! v ) reporter->InternalError("hash table underflow in TableVal::Describe"); - auto vl = table_hash->RecoverVals(k); + auto vl = table_hash->RecoverVals(*k); int dim = vl->Length(); if ( i > 0 ) @@ -2398,7 +2399,7 @@ void TableVal::DoExpire(double t) if ( expire_func ) { - idx = RecoverIndex(k); + idx = RecreateIndex(*k); double secs = CallExpireFunc(idx); // It's possible that the user-provided @@ -2428,7 +2429,7 @@ void TableVal::DoExpire(double t) if ( subnets ) { if ( ! idx ) - idx = RecoverIndex(k); + idx = RecreateIndex(*k); if ( ! subnets->Remove(idx.get()) ) reporter->InternalWarning("index not in prefix table"); } @@ -2437,7 +2438,7 @@ void TableVal::DoExpire(double t) if ( change_func ) { if ( ! idx ) - idx = RecoverIndex(k); + idx = RecreateIndex(*k); CallChangeFunc(idx.get(), v->GetVal().get(), ELEMENT_EXPIRED); } @@ -2568,7 +2569,7 @@ IntrusivePtr TableVal::DoClone(CloneState* state) if ( subnets ) { - auto idx = RecoverIndex(key); + auto idx = RecreateIndex(*key); tv->subnets->Insert(idx.get(), nval); } @@ -2615,9 +2616,12 @@ unsigned int TableVal::MemoryAllocation() const + table_hash->MemoryAllocation(); } -HashKey* TableVal::ComputeHash(const Val& index) const +HashKey* TableVal::ComputeHash(const Val* index) const + { return MakeHashKey(*index).release(); } + +std::unique_ptr TableVal::MakeHashKey(const Val& index) const { - return table_hash->ComputeHash(index, true); + return table_hash->MakeHashKey(index, true); } void TableVal::SaveParseTimeTableState(RecordType* rt) @@ -2658,7 +2662,7 @@ TableVal::ParseTimeTableState TableVal::DumpTableState() while ( (val = tbl->NextEntry(key, cookie)) ) { - rval.emplace_back(RecoverIndex(key), val->GetVal()); + rval.emplace_back(RecreateIndex(*key), val->GetVal()); delete key; } diff --git a/src/Val.h b/src/Val.h index 7effbacb1d..6c6967e599 100644 --- a/src/Val.h +++ b/src/Val.h @@ -761,13 +761,13 @@ public: * case of a set, just adds the index). * @param index The key to assign. For tables, this is allowed to be null * (if needed, the index val can be recovered from the hash key). - * @param k A precomputed hash key to use (this method takes ownership - * of deleting it). + * @param k A precomputed hash key to use. * @param new_val The value to assign at the index. For a set, this * must be nullptr. * @return True if the assignment type-checked. */ - bool Assign(IntrusivePtr index, HashKey* k, IntrusivePtr new_val); + bool Assign(IntrusivePtr index, std::unique_ptr k, + IntrusivePtr new_val); // Returns true if the assignment typechecked, false if not. The // methods take ownership of new_val, but not of the index. If we're @@ -877,8 +877,14 @@ public: // Returns false if index does not exist. bool UpdateTimestamp(Val* index); - // Returns the index corresponding to the given HashKey. - IntrusivePtr RecoverIndex(const HashKey* k) const; + /** + * @return The index corresponding to the given HashKey. + */ + IntrusivePtr RecreateIndex(const HashKey& k) const; + + [[deprecated("Remove in v4.1. Use RecreateIndex().")]] + ListVal* RecoverIndex(const HashKey* k) const + { return RecreateIndex(*k).release(); } /** * Remove an element from the table and return it. @@ -892,11 +898,10 @@ public: /** * Same as Remove(const Val&), but uses a precomputed hash key. - * @param k The hash key to lookup. This method takes ownership of - * deleting it. + * @param k The hash key to lookup. * @return Same as Remove(const Val&). */ - IntrusivePtr Remove(const HashKey* k); + IntrusivePtr Remove(const HashKey& k); [[deprecated("Remove in v4.1. Use Remove().")]] Val* Delete(const Val* index) @@ -904,7 +909,7 @@ public: [[deprecated("Remove in v4.1. Use Remove().")]] Val* Delete(const HashKey* k) - { return Remove(k).release(); } + { return Remove(*k).release(); } // Returns a ListVal representation of the table (which must be a set). IntrusivePtr ToListVal(TypeTag t = TYPE_ANY) const; @@ -954,11 +959,15 @@ public: timer = nullptr; } - HashKey* ComputeHash(const Val& index) const; + /** + * @param The index value to hash. + * @return The hash of the index value or nullptr if + * type-checking failed. + */ + std::unique_ptr MakeHashKey(const Val& index) const; - [[deprecated("Remove in v4.1. Pass a Val& instead.")]] - HashKey* ComputeHash(const Val* index) const - { return ComputeHash(*index); } + [[deprecated("Remove in v4.1. Use MakeHashKey().")]] + HashKey* ComputeHash(const Val* index) const; notifier::Modifiable* Modifiable() override { return this; } diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 3670f02a1c..26e680d4cb 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -901,7 +901,7 @@ broker::expected bro_broker::val_to_data(const Val* v) while ( (entry = table->NextEntry(hk, c)) ) { - auto vl = table_val->RecoverIndex(hk); + auto vl = table_val->RecreateIndex(*hk); delete hk; broker::vector composite_key; diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index 8125020ad3..6416fa7d41 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -38,7 +38,7 @@ std::set val_to_topic_set(Val* val) while ( tbl->NextEntry(k, c) ) { - auto index = val->AsTableVal()->RecoverIndex(k); + auto index = val->AsTableVal()->RecreateIndex(*k); rval.emplace(index->Idx(0)->AsString()->CheckString()); delete k; } diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index 01361339e7..d196a2515e 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -166,12 +166,12 @@ HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const auto lv = make_intrusive(TYPE_ANY); lv->Append(t.AsVal()); lv->Append({NewRef{}, args}); - HashKey* key = analyzer_hash->ComputeHash(*lv, true); + auto key = analyzer_hash->MakeHashKey(*lv, true); if ( ! key ) reporter->InternalError("AnalyzerArgs type mismatch"); - return key; + return key.release(); } file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(const Tag& tag, diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 1191b6233f..c2d2f54b88 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -285,7 +285,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) TableEntryVal* v; while ( (v = info->config->AsTable()->NextEntry(k, c)) ) { - auto index = info->config->RecoverIndex(k); + auto index = info->config->RecreateIndex(*k); string key = index->Idx(0)->AsString()->CheckString(); string value = v->GetVal()->AsString()->CheckString(); rinfo.config.insert(std::make_pair(copy_string(key.c_str()), copy_string(value.c_str()))); @@ -1248,7 +1248,8 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) oldval = stream->tab->Find({NewRef{}, idxval}); } - HashKey* k = stream->tab->ComputeHash(*idxval); + auto k = stream->tab->MakeHashKey(*idxval); + if ( ! k ) reporter->InternalError("could not hash"); @@ -1256,7 +1257,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) ih->idxkey = new HashKey(k->Key(), k->Size(), k->Hash()); ih->valhash = valhash; - stream->tab->Assign({AdoptRef{}, idxval}, k, {AdoptRef{}, valval}); + stream->tab->Assign({AdoptRef{}, idxval}, std::move(k), {AdoptRef{}, valval}); if ( predidx != nullptr ) Unref(predidx); @@ -1342,7 +1343,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) if ( stream->pred || stream->event ) { - auto idx = stream->tab->RecoverIndex(ih->idxkey); + auto idx = stream->tab->RecreateIndex(*ih->idxkey); assert(idx != nullptr); val = stream->tab->FindOrDefault(idx); assert(val != nullptr); @@ -1371,7 +1372,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) SendEvent(stream->event, 4, stream->description->Ref(), ev->Ref(), predidx->Ref(), val->Ref()); - stream->tab->Remove(ih->idxkey); + stream->tab->Remove(*ih->idxkey); stream->lastDict->Remove(lastDictIdxKey); // delete in next line delete lastDictIdxKey; delete(ih); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 5ae05cb2af..b5dc099068 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -865,7 +865,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) TableEntryVal* v; while ( (v = filter->config->AsTable()->NextEntry(k, c)) ) { - auto index = filter->config->RecoverIndex(k); + auto index = filter->config->RecreateIndex(*k); string key = index->Idx(0)->AsString()->CheckString(); string value = v->GetVal()->AsString()->CheckString(); info->config.insert(std::make_pair(copy_string(key.c_str()), copy_string(value.c_str()))); diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 12515505a5..38bf2d625f 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -29,9 +29,9 @@ void TopkVal::Typify(IntrusivePtr t) HashKey* TopkVal::GetHash(Val* v) const { - HashKey* key = hash->ComputeHash(*v, true); + auto key = hash->MakeHashKey(*v, true); assert(key); - return key; + return key.release(); } TopkVal::TopkVal(uint64_t arg_size) : OpaqueVal(topk_type) diff --git a/src/reporter.bif b/src/reporter.bif index 88c6aef5a7..8425798ddb 100644 --- a/src/reporter.bif +++ b/src/reporter.bif @@ -179,7 +179,7 @@ function Reporter::set_weird_sampling_whitelist%(weird_sampling_whitelist: strin while ( (v = wl_table->NextEntry(k, c)) ) { - auto index = wl_val->RecoverIndex(k); + auto index = wl_val->RecreateIndex(*k); string key = index->Idx(0)->AsString()->CheckString(); whitelist_set.emplace(move(key)); delete k; diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 24a559ac98..2972291f97 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1024,7 +1024,7 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node) while ( (v = cluster_table->NextEntry(k, c)) ) { - auto key = cluster_table_val->RecoverIndex(k); + auto key = cluster_table_val->RecreateIndex(*k); delete k; auto name = key->Idx(0)->AsStringVal()->ToStdString(); auto rv = v->GetVal()->AsRecordVal(); From 61b44a9c6325de1ec33468c27adb712fa4aff355 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 22:23:13 -0700 Subject: [PATCH 099/151] Minor TableVal::Assign() ref-counting optimization --- src/Val.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index 370fa1fbac..8290de068b 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1532,7 +1532,7 @@ bool TableVal::Assign(IntrusivePtr index, std::unique_ptr k, if ( (is_set && new_val) || (! is_set && ! new_val) ) InternalWarning("bad set/table in TableVal::Assign"); - TableEntryVal* new_entry_val = new TableEntryVal(new_val); + TableEntryVal* new_entry_val = new TableEntryVal(std::move(new_val)); HashKey k_copy(k->Key(), k->Size(), k->Hash()); TableEntryVal* old_entry_val = AsNonConstTable()->Insert(k.get(), new_entry_val); @@ -1561,7 +1561,7 @@ bool TableVal::Assign(IntrusivePtr index, std::unique_ptr k, if ( change_func ) { auto change_index = index ? std::move(index) : RecreateIndex(k_copy); - auto v = old_entry_val ? old_entry_val->GetVal() : new_val; + auto v = old_entry_val ? old_entry_val->GetVal() : new_entry_val->GetVal(); CallChangeFunc(change_index.get(), v.get(), old_entry_val ? ELEMENT_CHANGED : ELEMENT_NEW); } From 9798c4b763db3ad835802f49281ab171bdd62e21 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 22:58:44 -0700 Subject: [PATCH 100/151] Fix ambiguous ODesc::Add() call --- src/Val.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Val.cc b/src/Val.cc index 8290de068b..fb1719cfac 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2911,7 +2911,7 @@ void RecordVal::Describe(ODesc* d) const { record_type->Describe(d); d->SP(); - d->Add(n); + d->Add(static_cast(n)); d->SP(); } else From adb9d2881c9f259f7cb457b0a1374c4293f731c0 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 23:17:25 -0700 Subject: [PATCH 101/151] Switch a TableVal::CallChangeFunc param to IntrusivePtr --- src/Val.cc | 16 +++++++++------- src/Val.h | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index fb1719cfac..2f6a5b940d 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1561,8 +1561,8 @@ bool TableVal::Assign(IntrusivePtr index, std::unique_ptr k, if ( change_func ) { auto change_index = index ? std::move(index) : RecreateIndex(k_copy); - auto v = old_entry_val ? old_entry_val->GetVal() : new_entry_val->GetVal(); - CallChangeFunc(change_index.get(), v.get(), old_entry_val ? ELEMENT_CHANGED : ELEMENT_NEW); + const auto& v = old_entry_val ? old_entry_val->GetVal() : new_entry_val->GetVal(); + CallChangeFunc(change_index.get(), v, old_entry_val ? ELEMENT_CHANGED : ELEMENT_NEW); } delete old_entry_val; @@ -2030,7 +2030,9 @@ IntrusivePtr TableVal::RecreateIndex(const HashKey& k) const return table_hash->RecoverVals(k); } -void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe) +void TableVal::CallChangeFunc(const Val* index, + const IntrusivePtr& old_value, + OnChangeType tpe) { if ( ! change_func || ! index || in_change_func ) return; @@ -2079,7 +2081,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe vl.emplace_back(v); if ( table_type->IsTable() ) - vl.emplace_back(NewRef{}, old_value); + vl.emplace_back(old_value); in_change_func = true; f->operator()(vl); @@ -2108,7 +2110,7 @@ IntrusivePtr TableVal::Remove(const Val& index) Modified(); if ( change_func ) - CallChangeFunc(&index, va.get(), ELEMENT_REMOVED); + CallChangeFunc(&index, va, ELEMENT_REMOVED); return va; } @@ -2136,7 +2138,7 @@ IntrusivePtr TableVal::Remove(const HashKey& k) if ( change_func && va ) { auto index = table_hash->RecoverVals(k); - CallChangeFunc(index.get(), va.get(), ELEMENT_REMOVED); + CallChangeFunc(index.get(), va, ELEMENT_REMOVED); } return va; @@ -2439,7 +2441,7 @@ void TableVal::DoExpire(double t) { if ( ! idx ) idx = RecreateIndex(*k); - CallChangeFunc(idx.get(), v->GetVal().get(), ELEMENT_EXPIRED); + CallChangeFunc(idx.get(), v->GetVal(), ELEMENT_EXPIRED); } delete v; diff --git a/src/Val.h b/src/Val.h index 6c6967e599..565dd6e6f0 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1017,7 +1017,8 @@ protected: enum OnChangeType { ELEMENT_NEW, ELEMENT_CHANGED, ELEMENT_REMOVED, ELEMENT_EXPIRED }; // Calls &change_func. Does not take ownership of values. (Refs if needed). - void CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe); + void CallChangeFunc(const Val* index, const IntrusivePtr& old_value, + OnChangeType tpe); IntrusivePtr DoClone(CloneState* state) override; From 5af962e11ffce0ad91d1f175274c0be4e2c931c2 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 20 May 2020 23:36:28 -0700 Subject: [PATCH 102/151] Deprecate StringVal::Substitute(), replace with Replace() --- src/Val.cc | 12 +++++++----- src/Val.h | 7 ++++++- src/strings.bif | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index 2f6a5b940d..0f81712e73 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -591,7 +591,8 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* { auto blank = make_intrusive(""); auto fn_val = make_intrusive(field_name); - auto key_val = fn_val->Substitute(re, blank.get(), false); + const auto& bs = *blank->AsString(); + auto key_val = fn_val->Replace(re, bs, false); key_str = key_val->ToStdString(); } else @@ -1031,7 +1032,8 @@ unsigned int StringVal::MemoryAllocation() const return padded_sizeof(*this) + val.string_val->MemoryAllocation(); } -IntrusivePtr StringVal::Substitute(RE_Matcher* re, StringVal* repl, bool do_all) +IntrusivePtr StringVal::Replace(RE_Matcher* re, + const BroString& repl, bool do_all) { const u_char* s = Bytes(); int offset = 0; @@ -1079,7 +1081,7 @@ IntrusivePtr StringVal::Substitute(RE_Matcher* re, StringVal* repl, b // size now reflects amount of space copied. Factor in amount // of space for replacement text. - size += cut_points.size() * repl->Len(); + size += cut_points.size() * repl.Len(); // And a final NUL for good health. ++size; @@ -1098,8 +1100,8 @@ IntrusivePtr StringVal::Substitute(RE_Matcher* re, StringVal* repl, b start_offset = point.second; // Now add in replacement text. - memcpy(r, repl->Bytes(), repl->Len()); - r += repl->Len(); + memcpy(r, repl.Bytes(), repl.Len()); + r += repl.Len(); } // Copy final trailing characters. diff --git a/src/Val.h b/src/Val.h index 565dd6e6f0..fdaea07f5d 100644 --- a/src/Val.h +++ b/src/Val.h @@ -600,7 +600,12 @@ public: unsigned int MemoryAllocation() const override; - IntrusivePtr Substitute(RE_Matcher* re, StringVal* repl, bool do_all); + IntrusivePtr Replace(RE_Matcher* re, const BroString& repl, + bool do_all); + + [[deprecated("Remove in v4.1. Use Replace().")]] + Val* Substitute(RE_Matcher* re, StringVal* repl, bool do_all) + { return Replace(re, *repl->AsString(), do_all).release(); } protected: void ValDescribe(ODesc* d) const override; diff --git a/src/strings.bif b/src/strings.bif index dc5574ba04..bfc5853bc7 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -412,7 +412,7 @@ function split_string_n%(str: string, re: pattern, ## .. zeek:see:: gsub subst_string function sub%(str: string, re: pattern, repl: string%): string %{ - return str->Substitute(re, repl, false); + return str->Replace(re, *repl->AsString(), false); %} ## Substitutes a given replacement string for all occurrences of a pattern @@ -429,7 +429,7 @@ function sub%(str: string, re: pattern, repl: string%): string ## .. zeek:see:: sub subst_string function gsub%(str: string, re: pattern, repl: string%): string %{ - return str->Substitute(re, repl, true); + return str->Replace(re, *repl->AsString(), true); %} From 3b6f60a8103d7e88d273f7d7713ab3b60908234c Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 00:50:48 -0700 Subject: [PATCH 103/151] Add Val::AsFuncPtr() convenience method Since it's not trivial to store IntrusivePtr in BroValUnion and also not satisfying to store IntrusivePtr*. --- src/ID.cc | 2 +- src/Val.cc | 6 ++++++ src/Val.h | 2 ++ src/option.bif | 3 +-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ID.cc b/src/ID.cc index c72137d534..e7b7638a75 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -84,7 +84,7 @@ IntrusivePtr zeek::id::find_func(std::string_view name) reporter->InternalError("Expected variable '%s' to be a function", std::string(name).data()); - return {NewRef{}, v->AsFunc()}; + return v->AsFuncPtr(); } void zeek::id::detail::init() diff --git a/src/Val.cc b/src/Val.cc index 0f81712e73..bc7fd36d91 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -153,6 +153,12 @@ IntrusivePtr Val::DoClone(CloneState* state) return nullptr; } +IntrusivePtr Val::AsFuncPtr() const + { + CHECK_TAG(type->Tag(), TYPE_FUNC, "Val::Func", type_name) + return {NewRef{}, val.func_val}; + } + bool Val::IsZero() const { switch ( type->InternalType() ) { diff --git a/src/Val.h b/src/Val.h index fdaea07f5d..8bf278943d 100644 --- a/src/Val.h +++ b/src/Val.h @@ -257,6 +257,8 @@ public: ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) ACCESSOR(TYPE_VECTOR, std::vector*, vector_val, AsVector) + IntrusivePtr AsFuncPtr() const; + const IPPrefix& AsSubNet() { CHECK_TAG(type->Tag(), TYPE_SUBNET, "Val::SubNet", type_name) diff --git a/src/option.bif b/src/option.bif index 9f3f359148..fd118ca5cc 100644 --- a/src/option.bif +++ b/src/option.bif @@ -206,7 +206,6 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - auto* func = on_change->AsFunc(); - i->AddOptionHandler({NewRef{}, func}, -priority); + i->AddOptionHandler(on_change->AsFuncPtr(), -priority); return val_mgr->True(); %} From fbc7725278fd08b24df8849bd0ae6ec3d5fc2128 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 01:06:05 -0700 Subject: [PATCH 104/151] Change EventHandler to store IntrusivePtr Also deprecates the LocalHandler() and SetLocalHandler() methods, replaced with GetFunc() and SetFunc(). --- src/EventHandler.cc | 15 --------------- src/EventHandler.h | 20 ++++++++++++++------ src/EventRegistry.cc | 8 ++++---- src/ID.cc | 4 ++-- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index fe3472fbf5..051a7f98d2 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -14,17 +14,11 @@ EventHandler::EventHandler(std::string arg_name) { name = std::move(arg_name); used = false; - local = nullptr; error_handler = false; enabled = true; generate_always = false; } -EventHandler::~EventHandler() - { - Unref(local); - } - EventHandler::operator bool() const { return enabled && ((local && local->HasBodies()) @@ -52,15 +46,6 @@ const IntrusivePtr& EventHandler::GetType(bool check_export) return type; } -void EventHandler::SetLocalHandler(Func* f) - { - if ( local ) - Unref(local); - - Ref(f); - local = f; - } - void EventHandler::Call(const zeek::Args& vl, bool no_remote) { #ifdef PROFILE_BRO_FUNCTIONS diff --git a/src/EventHandler.h b/src/EventHandler.h index 86d6defb4f..ccbd90e44b 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -5,19 +5,22 @@ #include "BroList.h" #include "ZeekArgs.h" #include "Type.h" +#include "Func.h" #include #include -class Func; - class EventHandler { public: explicit EventHandler(std::string name); - ~EventHandler(); const char* Name() { return name.data(); } - Func* LocalHandler() { return local; } + + const IntrusivePtr& GetFunc() + { return local; } + + [[deprecated("Remove in v4.1. Use GetFunc().")]] + Func* LocalHandler() { return local.get(); } const IntrusivePtr& GetType(bool check_export = true); @@ -25,7 +28,12 @@ public: FuncType* FType(bool check_export = true) { return GetType().get(); } - void SetLocalHandler(Func* f); + void SetFunc(IntrusivePtr f) + { local = std::move(f); } + + [[deprecated("Remove in v4.1. Use SetFunc().")]] + void SetLocalHandler(Func* f) + { SetFunc({NewRef{}, f}); } void AutoPublish(std::string topic) { @@ -61,7 +69,7 @@ private: void NewEvent(const zeek::Args& vl); // Raise new_event() meta event. std::string name; - Func* local; + IntrusivePtr local; IntrusivePtr type; bool used; // this handler is indeed used somewhere bool enabled; diff --git a/src/EventRegistry.cc b/src/EventRegistry.cc index ea6f3a0ca2..7cf05a7042 100644 --- a/src/EventRegistry.cc +++ b/src/EventRegistry.cc @@ -47,7 +47,7 @@ EventRegistry::string_list EventRegistry::Match(RE_Matcher* pattern) for ( const auto& entry : handlers ) { EventHandler* v = entry.second.get(); - if ( v->LocalHandler() && pattern->MatchExactly(v->Name()) ) + if ( v->GetFunc() && pattern->MatchExactly(v->Name()) ) names.push_back(entry.first); } @@ -61,7 +61,7 @@ EventRegistry::string_list EventRegistry::UnusedHandlers() for ( const auto& entry : handlers ) { EventHandler* v = entry.second.get(); - if ( v->LocalHandler() && ! v->Used() ) + if ( v->GetFunc() && ! v->Used() ) names.push_back(entry.first); } @@ -75,7 +75,7 @@ EventRegistry::string_list EventRegistry::UsedHandlers() for ( const auto& entry : handlers ) { EventHandler* v = entry.second.get(); - if ( v->LocalHandler() && v->Used() ) + if ( v->GetFunc() && v->Used() ) names.push_back(entry.first); } @@ -100,7 +100,7 @@ void EventRegistry::PrintDebug() { EventHandler* v = entry.second.get(); fprintf(stderr, "Registered event %s (%s handler / %s)\n", v->Name(), - v->LocalHandler()? "local" : "no", + v->GetFunc() ? "local" : "no", *v ? "active" : "not active" ); } diff --git a/src/ID.cc b/src/ID.cc index e7b7638a75..95da8e6568 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -164,14 +164,14 @@ void ID::SetVal(IntrusivePtr v, bool arg_weak_ref) if ( ! handler ) { handler = new EventHandler(name); - handler->SetLocalHandler(val->AsFunc()); + handler->SetFunc(val->AsFuncPtr()); event_registry->Register(handler); } else { // Otherwise, internally defined events cannot // have local handler. - handler->SetLocalHandler(val->AsFunc()); + handler->SetFunc(val->AsFuncPtr()); } } } From de1e3d7d6d0a6b15765d26b2f5074817a93aba39 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 15:31:04 -0700 Subject: [PATCH 105/151] Deprecate VectorVal::Assign methods taking raw Val* And adapt usages to pass in to alternate method taking IntrusivePtr --- NEWS | 3 ++ src/BroString.cc | 6 +-- src/Expr.cc | 12 +++--- src/Val.cc | 9 +--- src/Val.h | 41 ++++++++++++++----- src/analyzer/protocol/dhcp/dhcp-options.pac | 4 +- src/analyzer/protocol/krb/krb-padata.pac | 16 ++++---- src/analyzer/protocol/rpc/NFS.cc | 4 +- .../protocol/ssl/tls-handshake-analyzer.pac | 8 ++-- src/analyzer/protocol/tcp/TCP.cc | 4 +- src/broker/comm.bif | 4 +- src/file_analysis/analyzer/x509/X509.cc | 8 ++-- src/input/Manager.cc | 5 ++- src/probabilistic/Topk.cc | 2 +- src/threading/SerialTypes.cc | 5 ++- 15 files changed, 77 insertions(+), 54 deletions(-) diff --git a/NEWS b/NEWS index 16569dbb8e..c7c9c6bc3e 100644 --- a/NEWS +++ b/NEWS @@ -211,6 +211,9 @@ Deprecated Functionality - ``TableVal::Lookup()`` is deprecated, use ``TableVal::Find()`` or ``TableVal::FindOrDefault()``. +- ``VectorVal::Assign`` methods taking raw ``Val*`` are deprecated, use the + methods that take ``IntrusivePtr``. + Zeek 3.1.0 ========== diff --git a/src/BroString.cc b/src/BroString.cc index 2fe950b87d..15c7f6a773 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -345,9 +345,9 @@ VectorVal* BroString:: VecToPolicy(Vec* vec) for ( unsigned int i = 0; i < vec->size(); ++i ) { BroString* string = (*vec)[i]; - StringVal* val = new StringVal(string->Len(), - (const char*) string->Bytes()); - result->Assign(i+1, val); + auto val = make_intrusive(string->Len(), + (const char*) string->Bytes()); + result->Assign(i+1, std::move(val)); } return result.release(); diff --git a/src/Expr.cc b/src/Expr.cc index 27594c23e2..33c26f3e35 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -1572,7 +1572,7 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const { result = make_intrusive(GetType()); result->Resize(vector_v->Size()); - result->AssignRepeat(0, result->Size(), scalar_v.get()); + result->AssignRepeat(0, result->Size(), std::move(scalar_v)); } else result = std::move(vector_v); @@ -1937,7 +1937,7 @@ IntrusivePtr CondExpr::Eval(Frame* f) const if ( local_cond ) { Val* v = local_cond->IsZero() ? b->Lookup(i) : a->Lookup(i); - result->Assign(i, v ? v->Ref() : nullptr); + result->Assign(i, v ? IntrusivePtr{NewRef{}, v} : nullptr); } else result->Assign(i, nullptr); @@ -2595,7 +2595,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const if ( v_v2->Lookup(i)->AsBool() ) { auto a = v_v1->Lookup(i); - v_result->Assign(v_result->Size() + 1, a ? a->Ref() : nullptr); + v_result->Assign(v_result->Size() + 1, a ? IntrusivePtr{NewRef{}, a} : nullptr); } } } @@ -2608,7 +2608,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const for ( unsigned int i = 0; i < v_v2->Size(); ++i ) { auto a = v_v1->Lookup(v_v2->Lookup(i)->CoerceToInt()); - v_result->Assign(i, a ? a->Ref() : nullptr); + v_result->Assign(i, a ? IntrusivePtr{NewRef{}, a} : nullptr); } } @@ -2659,7 +2659,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const for ( int idx = first; idx < last; idx++ ) { auto a = vect->Lookup(idx); - result->Assign(idx - first, a ? a->Ref() : nullptr); + result->Assign(idx - first, a ? IntrusivePtr{NewRef{}, a} : nullptr); } } @@ -2758,7 +2758,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) for ( auto idx = 0u; idx < v_vect->Size(); idx++, first++ ) v1_vect->Insert(first, v_vect->Lookup(idx)->Ref()); } - else if ( ! v1_vect->Assign(v2.get(), std::move(v)) ) + else if ( ! v1_vect->Assign(lv->Idx(0)->CoerceToUnsigned(), std::move(v)) ) { v = std::move(v_extra); diff --git a/src/Val.cc b/src/Val.cc index bc7fd36d91..bf2966dca1 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -3080,18 +3080,13 @@ bool VectorVal::Assign(unsigned int index, IntrusivePtr element) return true; } -bool VectorVal::Assign(unsigned int index, Val* element) - { - return Assign(index, {AdoptRef{}, element}); - } - bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, - Val* element) + IntrusivePtr element) { ResizeAtLeast(index + how_many); for ( unsigned int i = index; i < index + how_many; ++i ) - if ( ! Assign(i, {NewRef{}, element}) ) + if ( ! Assign(i, element) ) return false; return true; diff --git a/src/Val.h b/src/Val.h index 8bf278943d..bf3541c02d 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1245,25 +1245,44 @@ public: IntrusivePtr SizeVal() const override; - // Returns false if the type of the argument was wrong. - // The vector will automatically grow to accomodate the index. - // + /** + * Assigns an element to a given vector index. + * @param index The index to assign. + * @param element The element value to assign. + * @return True if the element was successfully assigned, or false if + * the element was the wrong type. + */ + bool Assign(unsigned int index, IntrusivePtr element); + // Note: does NOT Ref() the element! Remember to do so unless // the element was just created and thus has refcount 1. - // - bool Assign(unsigned int index, IntrusivePtr element); - bool Assign(unsigned int index, Val* element); + [[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]] + bool Assign(unsigned int index, Val* element) + { return Assign(index, {AdoptRef{}, element}); } + // Note: the following nullptr method can also go upon removing the above. + void Assign(unsigned int index, std::nullptr_t) + { Assign(index, IntrusivePtr{}); } - template - bool Assign(Val* index, E&& element) + [[deprecated("Remove in v4.1. Assign using integer index and IntrusivePtr element.")]] + bool Assign(Val* index, Val* element) { return Assign(index->AsListVal()->Idx(0)->CoerceToUnsigned(), - std::forward(element)); + {AdoptRef{}, element}); } - // Assigns the value to how_many locations starting at index. + /** + * Assigns a given value to multiple indices in the vector. + * @param index The starting index to assign to. + * @param how_many The number of indices to assign, counting from *index*. + * @return True if the elements were successfully assigned, or false if + * the element was the wrong type. + */ bool AssignRepeat(unsigned int index, unsigned int how_many, - Val* element); + IntrusivePtr element); + + [[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]] + bool AssignRepeat(unsigned int index, unsigned int how_many, Val* element) + { return AssignRepeat(index, how_many, {NewRef{}, element}); } // Add this value to the given value (if appropriate). // Returns true if succcessful. diff --git a/src/analyzer/protocol/dhcp/dhcp-options.pac b/src/analyzer/protocol/dhcp/dhcp-options.pac index a53398eabc..96dfd8bacf 100644 --- a/src/analyzer/protocol/dhcp/dhcp-options.pac +++ b/src/analyzer/protocol/dhcp/dhcp-options.pac @@ -750,11 +750,11 @@ refine flow DHCP_Flow += { for ( auto ptrsubopt = ${v.relay_agent_inf}->begin(); ptrsubopt != ${v.relay_agent_inf}->end(); ++ptrsubopt ) { - auto r = new RecordVal(zeek::BifType::Record::DHCP::SubOpt); + auto r = make_intrusive(zeek::BifType::Record::DHCP::SubOpt); r->Assign(0, val_mgr->Count((*ptrsubopt)->code())); r->Assign(1, to_stringval((*ptrsubopt)->value())); - relay_agent_sub_opt->Assign(i, r); + relay_agent_sub_opt->Assign(i, std::move(r)); ++i; } diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index 5617e48fb6..957df4e789 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -36,26 +36,26 @@ IntrusivePtr proc_padata(const KRB_PA_Data_Sequence* data, const BroA break; case PA_PW_SALT: { - RecordVal * type_val = new RecordVal(zeek::BifType::Record::KRB::Type_Value); + auto type_val = make_intrusive(zeek::BifType::Record::KRB::Type_Value); type_val->Assign(0, val_mgr->Count(element->data_type())); type_val->Assign(1, to_stringval(element->pa_data_element()->pa_pw_salt()->encoding()->content())); - vv->Assign(vv->Size(), type_val); + vv->Assign(vv->Size(), std::move(type_val)); break; } case PA_ENCTYPE_INFO: { - RecordVal * type_val = new RecordVal(zeek::BifType::Record::KRB::Type_Value); + auto type_val = make_intrusive(zeek::BifType::Record::KRB::Type_Value); type_val->Assign(0, val_mgr->Count(element->data_type())); type_val->Assign(1, to_stringval(element->pa_data_element()->pf_enctype_info()->salt())); - vv->Assign(vv->Size(), type_val); + vv->Assign(vv->Size(), std::move(type_val)); break; } case PA_ENCTYPE_INFO2: { - RecordVal * type_val = new RecordVal(zeek::BifType::Record::KRB::Type_Value); + auto type_val = make_intrusive(zeek::BifType::Record::KRB::Type_Value); type_val->Assign(0, val_mgr->Count(element->data_type())); type_val->Assign(1, to_stringval(element->pa_data_element()->pf_enctype_info2()->salt())); - vv->Assign(vv->Size(), type_val); + vv->Assign(vv->Size(), std::move(type_val)); break; } case PA_PW_AS_REQ: @@ -110,10 +110,10 @@ IntrusivePtr proc_padata(const KRB_PA_Data_Sequence* data, const BroA { if ( ! is_error && element->pa_data_element()->unknown()->meta()->length() > 0 ) { - RecordVal * type_val = new RecordVal(zeek::BifType::Record::KRB::Type_Value); + auto type_val = make_intrusive(zeek::BifType::Record::KRB::Type_Value); type_val->Assign(0, val_mgr->Count(element->data_type())); type_val->Assign(1, to_stringval(element->pa_data_element()->unknown()->content())); - vv->Assign(vv->Size(), type_val); + vv->Assign(vv->Size(), std::move(type_val)); } break; } diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index 1ca6bbd89d..68a054dc6d 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -765,7 +765,7 @@ IntrusivePtr NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char while ( extract_XDR_uint32(buf,n) ) { - RecordVal *entry = new RecordVal(zeek::BifType::Record::NFS3::direntry_t); + auto entry = make_intrusive(zeek::BifType::Record::NFS3::direntry_t); entry->Assign(0, ExtractUint64(buf,n)); // fileid entry->Assign(1, nfs3_filename(buf,n)); // fname entry->Assign(2, ExtractUint64(buf,n)); // cookie @@ -776,7 +776,7 @@ IntrusivePtr NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char entry->Assign(4, nfs3_post_op_fh(buf,n)); } - entries->Assign(pos, entry); + entries->Assign(pos, std::move(entry)); pos++; } diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index ca7801c395..7db8d7584f 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -161,10 +161,10 @@ refine connection Handshake_Conn += { { for ( unsigned int i = 0; i < supported_signature_algorithms->size(); ++i ) { - RecordVal* el = new RecordVal(zeek::BifType::Record::SSL::SignatureAndHashAlgorithm); + auto el = make_intrusive(zeek::BifType::Record::SSL::SignatureAndHashAlgorithm); el->Assign(0, val_mgr->Count((*supported_signature_algorithms)[i]->HashAlgorithm())); el->Assign(1, val_mgr->Count((*supported_signature_algorithms)[i]->SignatureAlgorithm())); - slist->Assign(i, el); + slist->Assign(i, std::move(el)); } } @@ -498,10 +498,10 @@ refine connection Handshake_Conn += { { for ( auto&& identity : *(identities->identities()) ) { - RecordVal* el = new RecordVal(zeek::BifType::Record::SSL::PSKIdentity); + auto el = make_intrusive(zeek::BifType::Record::SSL::PSKIdentity); el->Assign(0, make_intrusive(identity->identity().length(), (const char*) identity->identity().data())); el->Assign(1, val_mgr->Count(identity->obfuscated_ticket_age())); - slist->Assign(slist->Size(), el); + slist->Assign(slist->Size(), std::move(el)); } } diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index 27d8235483..d61c246c8f 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -1358,7 +1358,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) { auto option_list = make_intrusive(zeek::BifType::Vector::TCP::OptionList); - auto add_option_data = [](RecordVal* rv, const u_char* odata, int olen) + auto add_option_data = [](const IntrusivePtr& rv, const u_char* odata, int olen) { if ( olen <= 2 ) return; @@ -1372,7 +1372,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) { auto kind = o[0]; auto length = kind < 2 ? 1 : o[1]; - auto option_record = new RecordVal(zeek::BifType::Record::TCP::Option); + auto option_record = make_intrusive(zeek::BifType::Record::TCP::Option); option_list->Assign(option_list->Size(), option_record); option_record->Assign(0, val_mgr->Count(kind)); option_record->Assign(1, val_mgr->Count(length)); diff --git a/src/broker/comm.bif b/src/broker/comm.bif index c49e90801e..6b63029f17 100644 --- a/src/broker/comm.bif +++ b/src/broker/comm.bif @@ -102,7 +102,7 @@ function Broker::__peers%(%): PeerInfos const auto& pi = zeek::id::find_type("Broker::PeerInfo"); const auto& ei = zeek::id::find_type("Broker::EndpointInfo"); const auto& ni = zeek::id::find_type("Broker::NetworkInfo"); - auto peer_info = new RecordVal(pi); + auto peer_info = make_intrusive(pi); auto endpoint_info = make_intrusive(ei); auto network_info = make_intrusive(ni); auto n = p.peer.network; @@ -125,7 +125,7 @@ function Broker::__peers%(%): PeerInfos peer_info->Assign(0, std::move(endpoint_info)); peer_info->Assign(1, zeek::BifType::Enum::Broker::PeerStatus->GetVal(ps)); - rval->Assign(i, peer_info); + rval->Assign(i, std::move(peer_info)); ++i; } diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 6588153646..b3bd999dd9 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -362,7 +362,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) #else const char* name = (const char*) ASN1_STRING_get0_data(gen->d.ia5); #endif - StringVal* bs = new StringVal(name); + auto bs = make_intrusive(name); switch ( gen->type ) { @@ -370,21 +370,21 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) if ( names == nullptr ) names = make_intrusive(zeek::id::string_vec); - names->Assign(names->Size(), bs); + names->Assign(names->Size(), std::move(bs)); break; case GEN_URI: if ( uris == nullptr ) uris = make_intrusive(zeek::id::string_vec); - uris->Assign(uris->Size(), bs); + uris->Assign(uris->Size(), std::move(bs)); break; case GEN_EMAIL: if ( emails == nullptr ) emails = make_intrusive(zeek::id::string_vec); - emails->Assign(emails->Size(), bs); + emails->Assign(emails->Size(), std::move(bs)); break; } } diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 532f9f9e03..2871b42ba8 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -2275,7 +2275,10 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ auto v = make_intrusive(std::move(vt)); for ( int j = 0; j < val->val.vector_val.size; j++ ) - v->Assign(j, ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error)); + { + auto el = ValueToVal(i, val->val.vector_val.vals[j], type.get(), have_error); + v->Assign(j, {AdoptRef{}, el}); + } return v.release(); } diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 38bf2d625f..a6942ddbca 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -209,7 +209,7 @@ IntrusivePtr TopkVal::GetTopK(int k) const // returns vector while ( eit != (*it)->elements.end() ) { //printf("Size: %ld\n", (*it)->elements.size()); - t->Assign(read, (*eit)->value->Ref()); + t->Assign(read, (*eit)->value); read++; eit++; } diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index 1e48e78c17..1f6e6acd34 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -588,7 +588,10 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e auto v = make_intrusive(std::move(vt)); for ( int j = 0; j < val->val.vector_val.size; j++ ) - v->Assign(j, ValueToVal(source, val->val.vector_val.vals[j], have_error)); + { + auto el = ValueToVal(source, val->val.vector_val.vals[j], have_error); + v->Assign(j, {AdoptRef{}, el}); + } return v.release(); } From 40db09ccbf0a0bb717d7de5321ace9023411f267 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 15:44:06 -0700 Subject: [PATCH 106/151] Deprecate VectorVal::Insert() taking raw Val*, use IntrusivePtr --- NEWS | 4 ++-- src/Expr.cc | 2 +- src/Val.cc | 5 ++--- src/Val.h | 15 +++++++++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index c7c9c6bc3e..5f4f479c6f 100644 --- a/NEWS +++ b/NEWS @@ -211,8 +211,8 @@ Deprecated Functionality - ``TableVal::Lookup()`` is deprecated, use ``TableVal::Find()`` or ``TableVal::FindOrDefault()``. -- ``VectorVal::Assign`` methods taking raw ``Val*`` are deprecated, use the - methods that take ``IntrusivePtr``. +- ``VectorVal::Assign`` and ``Insert`` methods taking raw ``Val*`` are + deprecated, use the methods that take ``IntrusivePtr``. Zeek 3.1.0 ========== diff --git a/src/Expr.cc b/src/Expr.cc index 33c26f3e35..04dfdbecd2 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2756,7 +2756,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) VectorVal* v_vect = v->AsVectorVal(); for ( auto idx = 0u; idx < v_vect->Size(); idx++, first++ ) - v1_vect->Insert(first, v_vect->Lookup(idx)->Ref()); + v1_vect->Insert(first, {NewRef{}, v_vect->Lookup(idx)}); } else if ( ! v1_vect->Assign(lv->Idx(0)->CoerceToUnsigned(), std::move(v)) ) { diff --git a/src/Val.cc b/src/Val.cc index bf2966dca1..d1c914e951 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -3092,12 +3092,11 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, return true; } -bool VectorVal::Insert(unsigned int index, Val* element) +bool VectorVal::Insert(unsigned int index, IntrusivePtr element) { if ( element && ! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) ) { - Unref(element); return false; } @@ -3111,7 +3110,7 @@ bool VectorVal::Insert(unsigned int index, Val* element) // Note: we do *not* Ref() the element, if any, at this point. // AssignExpr::Eval() already does this; other callers must remember // to do it similarly. - val.vector_val->insert(it, element); + val.vector_val->insert(it, element.release()); Modified(); return true; diff --git a/src/Val.h b/src/Val.h index bf3541c02d..1a0a7de7e6 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1309,8 +1309,19 @@ public: notifier::Modifiable* Modifiable() override { return this; } - // Insert an element at a specific position into the underlying vector. - bool Insert(unsigned int index, Val* element); + /** + * Inserts an element at the given position in the vector. All elements + * at that original position and higher are shifted up by one. + * @param index The index to insert the element at. + * @param element The value to insert into the vector. + * @return True if the element was inserted or false if the element was + * the wrong type. + */ + bool Insert(unsigned int index, IntrusivePtr element); + + [[deprecated("Remove in v4.1. Insert an IntrusivePtr instead.")]] + bool Insert(unsigned int index, Val* element) + { return Insert(index, {AdoptRef{}, element}); } // Removes an element at a specific position. bool Remove(unsigned int index); From 69533bcbc62ea4850f788e092332d93046ced033 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 16:24:34 -0700 Subject: [PATCH 107/151] Switch VectorVal BroValUnion to store std::vector> This changes the return type of AsVector() from std::vector* --- NEWS | 2 ++ src/Val.cc | 31 +++++++------------------------ src/Val.h | 9 +++------ src/strings.bif | 2 +- src/zeek.bif | 30 ++++++++++++++---------------- 5 files changed, 27 insertions(+), 47 deletions(-) diff --git a/NEWS b/NEWS index 5f4f479c6f..40206022cb 100644 --- a/NEWS +++ b/NEWS @@ -92,6 +92,8 @@ Changed Functionality - ``AsRecord()`` and ``AsNonConstRecord()`` have changed to return ``std::vector>*``. +- ``AsVector()`` has changed to return ``std::vector>*``. + Removed Functionality --------------------- diff --git a/src/Val.cc b/src/Val.cc index d1c914e951..8b150d18b3 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -3040,14 +3040,11 @@ VectorVal::VectorVal(VectorType* t) : VectorVal({NewRef{}, t}) VectorVal::VectorVal(IntrusivePtr t) : Val(std::move(t)) { - val.vector_val = new vector(); + val.vector_val = new vector>(); } VectorVal::~VectorVal() { - for ( unsigned int i = 0; i < val.vector_val->size(); ++i ) - Unref((*val.vector_val)[i]); - delete val.vector_val; } @@ -3062,19 +3059,10 @@ bool VectorVal::Assign(unsigned int index, IntrusivePtr element) ! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) ) return false; - Val* val_at_index = nullptr; - - if ( index < val.vector_val->size() ) - val_at_index = (*val.vector_val)[index]; - else + if ( index >= val.vector_val->size() ) val.vector_val->resize(index + 1); - Unref(val_at_index); - - // Note: we do *not* Ref() the element, if any, at this point. - // AssignExpr::Eval() already does this; other callers must remember - // to do it similarly. - (*val.vector_val)[index] = element.release(); + (*val.vector_val)[index] = std::move(element); Modified(); return true; @@ -3100,17 +3088,14 @@ bool VectorVal::Insert(unsigned int index, IntrusivePtr element) return false; } - vector::iterator it; + vector>::iterator it; if ( index < val.vector_val->size() ) it = std::next(val.vector_val->begin(), index); else it = val.vector_val->end(); - // Note: we do *not* Ref() the element, if any, at this point. - // AssignExpr::Eval() already does this; other callers must remember - // to do it similarly. - val.vector_val->insert(it, element.release()); + val.vector_val->insert(it, std::move(element)); Modified(); return true; @@ -3121,10 +3106,8 @@ bool VectorVal::Remove(unsigned int index) if ( index >= val.vector_val->size() ) return false; - Val* val_at_index = (*val.vector_val)[index]; auto it = std::next(val.vector_val->begin(), index); val.vector_val->erase(it); - Unref(val_at_index); Modified(); return true; @@ -3159,7 +3142,7 @@ Val* VectorVal::Lookup(unsigned int index) const if ( index >= val.vector_val->size() ) return nullptr; - return (*val.vector_val)[index]; + return (*val.vector_val)[index].get(); } unsigned int VectorVal::Resize(unsigned int new_num_elements) @@ -3188,7 +3171,7 @@ IntrusivePtr VectorVal::DoClone(CloneState* state) for ( unsigned int i = 0; i < val.vector_val->size(); ++i ) { auto v = (*val.vector_val)[i]->Clone(state); - vv->val.vector_val->push_back(v.release()); + vv->val.vector_val->push_back(std::move(v)); } return vv; diff --git a/src/Val.h b/src/Val.h index 1a0a7de7e6..b7248f217a 100644 --- a/src/Val.h +++ b/src/Val.h @@ -81,7 +81,7 @@ union BroValUnion { RE_Matcher* re_val; PDict* table_val; std::vector>* record_val; - std::vector* vector_val; + std::vector>* vector_val; BroValUnion() = default; @@ -114,9 +114,6 @@ union BroValUnion { constexpr BroValUnion(PDict* value) noexcept : table_val(value) {} - - constexpr BroValUnion(std::vector *value) noexcept - : vector_val(value) {} }; class Val : public BroObj { @@ -221,7 +218,7 @@ public: CONST_ACCESSOR(TYPE_RECORD, std::vector>*, record_val, AsRecord) CONST_ACCESSOR(TYPE_FILE, BroFile*, file_val, AsFile) CONST_ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) - CONST_ACCESSOR(TYPE_VECTOR, std::vector*, vector_val, AsVector) + CONST_ACCESSOR(TYPE_VECTOR, std::vector>*, vector_val, AsVector) const IPPrefix& AsSubNet() const { @@ -255,7 +252,7 @@ public: ACCESSOR(TYPE_FUNC, Func*, func_val, AsFunc) ACCESSOR(TYPE_FILE, BroFile*, file_val, AsFile) ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) - ACCESSOR(TYPE_VECTOR, std::vector*, vector_val, AsVector) + ACCESSOR(TYPE_VECTOR, std::vector>*, vector_val, AsVector) IntrusivePtr AsFuncPtr() const; diff --git a/src/strings.bif b/src/strings.bif index bfc5853bc7..b22fb894c6 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -705,7 +705,7 @@ function str_smith_waterman%(s1: string, s2: string, params: sw_params%) : sw_su ## .. zeek:see:: split_string split_string1 split_string_all split_string_n function str_split%(s: string, idx: index_vec%): string_vec %{ - vector* idx_v = idx->AsVector(); + auto idx_v = idx->AsVector(); BroString::IdxVec indices(idx_v->size()); unsigned int i; diff --git a/src/zeek.bif b/src/zeek.bif index 51a95cbaf3..37f7af26d2 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1327,10 +1327,10 @@ function all_set%(v: any%) : bool %} %%{ -static Func* sort_function_comp = 0; -static Val** index_map = 0; // used for indirect sorting to support order() +static Func* sort_function_comp = nullptr; +static std::vector*> index_map; // used for indirect sorting to support order() -bool sort_function(Val* a, Val* b) +bool sort_function(const IntrusivePtr& a, const IntrusivePtr& b) { // Sort missing values as "high". if ( ! a ) @@ -1338,8 +1338,7 @@ bool sort_function(Val* a, Val* b) if ( ! b ) return 1; - auto result = sort_function_comp->operator()(IntrusivePtr{NewRef{}, a}, - IntrusivePtr{NewRef{}, b}); + auto result = sort_function_comp->operator()(a, b); int int_result = result->CoerceToInt(); return int_result < 0; @@ -1347,10 +1346,10 @@ bool sort_function(Val* a, Val* b) bool indirect_sort_function(size_t a, size_t b) { - return sort_function(index_map[a], index_map[b]); + return sort_function(*index_map[a], *index_map[b]); } -bool signed_sort_function (Val* a, Val* b) +bool signed_sort_function (const IntrusivePtr& a, const IntrusivePtr& b) { if ( ! a ) return 0; @@ -1363,7 +1362,7 @@ bool signed_sort_function (Val* a, Val* b) return ia < ib; } -bool unsigned_sort_function (Val* a, Val* b) +bool unsigned_sort_function (const IntrusivePtr& a, const IntrusivePtr& b) { if ( ! a ) return 0; @@ -1378,12 +1377,12 @@ bool unsigned_sort_function (Val* a, Val* b) bool indirect_signed_sort_function(size_t a, size_t b) { - return signed_sort_function(index_map[a], index_map[b]); + return signed_sort_function(*index_map[a], *index_map[b]); } bool indirect_unsigned_sort_function(size_t a, size_t b) { - return unsigned_sort_function(index_map[a], index_map[b]); + return unsigned_sort_function(*index_map[a], *index_map[b]); } %%} @@ -1431,7 +1430,7 @@ function sort%(v: any, ...%) : any if ( ! comp && ! IsIntegral(elt_type->Tag()) ) builtin_error("comparison function required for sort() with non-integral types"); - vector& vv = *v->AsVector(); + auto& vv = *v->AsVector(); if ( comp ) { @@ -1501,18 +1500,18 @@ function order%(v: any, ...%) : index_vec if ( ! comp && ! IsIntegral(elt_type->Tag()) ) builtin_error("comparison function required for order() with non-integral types"); - vector& vv = *v->AsVector(); + auto& vv = *v->AsVector(); auto n = vv.size(); // Set up initial mapping of indices directly to corresponding // elements. vector ind_vv(n); - index_map = new Val*[n]; + index_map.reserve(n); size_t i; for ( i = 0; i < n; ++i ) { ind_vv[i] = i; - index_map[i] = vv[i]; + index_map.emplace_back(&vv[i]); } if ( comp ) @@ -1537,8 +1536,7 @@ function order%(v: any, ...%) : index_vec sort(ind_vv.begin(), ind_vv.end(), indirect_signed_sort_function); } - delete [] index_map; - index_map = 0; + index_map = {}; // Now spin through ind_vv to read out the rearrangement. for ( i = 0; i < n; ++i ) From a384bb8b8144815730381194ddab7f298f80b894 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 17:03:46 -0700 Subject: [PATCH 108/151] Deprecate VectorVal::Lookup(), replace with At() --- NEWS | 2 + src/BroString.cc | 2 +- src/CompHash.cc | 9 +-- src/Expr.cc | 55 ++++++++----------- src/SmithWaterman.cc | 4 +- src/Stmt.cc | 2 +- src/Val.cc | 14 +++-- src/Val.h | 19 +++++-- src/analyzer/protocol/ssh/ssh-protocol.pac | 6 +- src/broker/Data.cc | 4 +- src/broker/Manager.cc | 2 +- src/file_analysis/analyzer/x509/functions.bif | 12 ++-- src/logging/Manager.cc | 2 +- src/strings.bif | 2 +- src/supervisor/Supervisor.cc | 2 +- src/zeek.bif | 6 +- 16 files changed, 74 insertions(+), 69 deletions(-) diff --git a/NEWS b/NEWS index 40206022cb..bda8f5718e 100644 --- a/NEWS +++ b/NEWS @@ -216,6 +216,8 @@ Deprecated Functionality - ``VectorVal::Assign`` and ``Insert`` methods taking raw ``Val*`` are deprecated, use the methods that take ``IntrusivePtr``. +- ``VectorVal::Lookup()`` is deprecated, use ``VectorVal::At()``. + Zeek 3.1.0 ========== diff --git a/src/BroString.cc b/src/BroString.cc index 15c7f6a773..2cd5059cc8 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -360,7 +360,7 @@ BroString::Vec* BroString::VecFromPolicy(VectorVal* vec) // VectorVals start at index 1! for ( unsigned int i = 1; i <= vec->Size(); ++i ) { - Val* v = vec->Lookup(i); // get the RecordVal + const auto& v = vec->At(i); // get the RecordVal if ( ! v ) continue; diff --git a/src/CompHash.cc b/src/CompHash.cc index ea754dcea1..4331603b5d 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -266,7 +266,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, kp1 = reinterpret_cast(kp+1); for ( unsigned int i = 0; i < vv->Size(); ++i ) { - Val* val = vv->Lookup(i); + const auto& val = vv->At(i); unsigned int* kp = AlignAndPadType(kp1); *kp = i; kp1 = reinterpret_cast(kp+1); @@ -277,7 +277,8 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, if ( val ) { if ( ! (kp1 = SingleValHash(type_check, kp1, - vt->Yield().get(), val, false)) ) + vt->Yield().get(), val.get(), + false)) ) return nullptr; } } @@ -564,12 +565,12 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, VectorVal* vv = const_cast(v->AsVectorVal()); for ( unsigned int i = 0; i < vv->Size(); ++i ) { - Val* val = vv->Lookup(i); + const auto& val = vv->At(i); sz = SizeAlign(sz, sizeof(unsigned int)); sz = SizeAlign(sz, sizeof(unsigned int)); if ( val ) sz = SingleTypeKeySize(bt->AsVectorType()->Yield().get(), - val, type_check, sz, false, + val.get(), type_check, sz, false, calc_static_size); if ( ! sz ) return 0; } diff --git a/src/Expr.cc b/src/Expr.cc index 04dfdbecd2..c828b1dd93 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -366,8 +366,8 @@ IntrusivePtr UnaryExpr::Eval(Frame* f) const for ( unsigned int i = 0; i < v_op->Size(); ++i ) { - Val* v_i = v_op->Lookup(i); - result->Assign(i, v_i ? Fold(v_i) : nullptr); + const auto& v_i = v_op->At(i); + result->Assign(i, v_i ? Fold(v_i.get()) : nullptr); } return result; @@ -457,8 +457,8 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const for ( unsigned int i = 0; i < v_op1->Size(); ++i ) { - if ( v_op1->Lookup(i) && v_op2->Lookup(i) ) - v_result->Assign(i, Fold(v_op1->Lookup(i), v_op2->Lookup(i))); + if ( v_op1->At(i) && v_op2->At(i) ) + v_result->Assign(i, Fold(v_op1->At(i).get(), v_op2->At(i).get())); else v_result->Assign(i, nullptr); // SetError("undefined element in vector operation"); @@ -474,9 +474,9 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const for ( unsigned int i = 0; i < vv->Size(); ++i ) { - if ( Val* vv_i = vv->Lookup(i) ) - v_result->Assign(i, is_vec1 ? Fold(vv_i, v2.get()) - : Fold(v1.get(), vv_i)); + if ( const auto& vv_i = vv->At(i) ) + v_result->Assign(i, is_vec1 ? Fold(vv_i.get(), v2.get()) + : Fold(v1.get(), vv_i.get())); else v_result->Assign(i, nullptr); @@ -971,10 +971,10 @@ IntrusivePtr IncrExpr::Eval(Frame* f) const for ( unsigned int i = 0; i < v_vec->Size(); ++i ) { - Val* elt = v_vec->Lookup(i); + const auto& elt = v_vec->At(i); if ( elt ) - v_vec->Assign(i, DoSingleEval(f, elt)); + v_vec->Assign(i, DoSingleEval(f, elt.get())); else v_vec->Assign(i, nullptr); } @@ -1600,8 +1600,8 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const for ( unsigned int i = 0; i < vec_v1->Size(); ++i ) { - Val* op1 = vec_v1->Lookup(i); - Val* op2 = vec_v2->Lookup(i); + const auto& op1 = vec_v1->At(i); + const auto& op2 = vec_v2->At(i); if ( op1 && op2 ) { bool local_result = (tag == EXPR_AND_AND) ? @@ -1932,12 +1932,12 @@ IntrusivePtr CondExpr::Eval(Frame* f) const for ( unsigned int i = 0; i < cond->Size(); ++i ) { - Val* local_cond = cond->Lookup(i); + const auto& local_cond = cond->At(i); if ( local_cond ) { - Val* v = local_cond->IsZero() ? b->Lookup(i) : a->Lookup(i); - result->Assign(i, v ? IntrusivePtr{NewRef{}, v} : nullptr); + const auto& v = local_cond->IsZero() ? b->At(i) : a->At(i); + result->Assign(i, v); } else result->Assign(i, nullptr); @@ -2592,11 +2592,8 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const for ( unsigned int i = 0; i < v_v2->Size(); ++i ) { - if ( v_v2->Lookup(i)->AsBool() ) - { - auto a = v_v1->Lookup(i); - v_result->Assign(v_result->Size() + 1, a ? IntrusivePtr{NewRef{}, a} : nullptr); - } + if ( v_v2->At(i)->AsBool() ) + v_result->Assign(v_result->Size() + 1, v_v1->At(i)); } } else @@ -2606,10 +2603,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const // Probably only do this if *all* are negative. v_result->Resize(v_v2->Size()); for ( unsigned int i = 0; i < v_v2->Size(); ++i ) - { - auto a = v_v1->Lookup(v_v2->Lookup(i)->CoerceToInt()); - v_result->Assign(i, a ? IntrusivePtr{NewRef{}, a} : nullptr); - } + v_result->Assign(i, v_v1->At(v_v2->At(i)->CoerceToInt())); } return v_result; @@ -2642,7 +2636,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const const ListVal* lv = v2->AsListVal(); if ( lv->Length() == 1 ) - v = {NewRef{}, vect->Lookup(v2)}; + v = vect->At(lv->Idx(0)->CoerceToUnsigned()); else { size_t len = vect->Size(); @@ -2657,10 +2651,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const result->Resize(sub_length); for ( int idx = first; idx < last; idx++ ) - { - auto a = vect->Lookup(idx); - result->Assign(idx - first, a ? IntrusivePtr{NewRef{}, a} : nullptr); - } + result->Assign(idx - first, vect->At(idx)); } return result; @@ -2756,7 +2747,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) VectorVal* v_vect = v->AsVectorVal(); for ( auto idx = 0u; idx < v_vect->Size(); idx++, first++ ) - v1_vect->Insert(first, {NewRef{}, v_vect->Lookup(idx)}); + v1_vect->Insert(first, v_vect->At(idx)); } else if ( ! v1_vect->Assign(lv->Idx(0)->CoerceToUnsigned(), std::move(v)) ) { @@ -3509,8 +3500,8 @@ IntrusivePtr ArithCoerceExpr::Fold(Val* v) const for ( unsigned int i = 0; i < vv->Size(); ++i ) { - if ( Val* elt = vv->Lookup(i) ) - result->Assign(i, FoldSingleVal(elt, t)); + if ( const auto& elt = vv->At(i) ) + result->Assign(i, FoldSingleVal(elt.get(), t)); else result->Assign(i, nullptr); } @@ -3992,7 +3983,7 @@ IntrusivePtr InExpr::Fold(Val* v1, Val* v2) const bool res; if ( is_vector(v2) ) - res = (bool)v2->AsVectorVal()->Lookup(v1); + res = (bool)v2->AsVectorVal()->At(v1->AsListVal()->Idx(0)->CoerceToUnsigned()); else res = (bool)v2->AsTableVal()->Find({NewRef{}, v1}); diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index fe0d9876ab..bfbad2284b 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -103,7 +103,7 @@ BroSubstring::Vec* BroSubstring::VecFromPolicy(VectorVal* vec) // VectorVals start at index 1! for ( unsigned int i = 1; i <= vec->Size(); ++i ) { - Val* v = vec->Lookup(i); // get the RecordVal + const auto& v = vec->At(i); // get the RecordVal if ( ! v ) continue; @@ -113,7 +113,7 @@ BroSubstring::Vec* BroSubstring::VecFromPolicy(VectorVal* vec) const VectorVal* aligns = v->AsRecordVal()->GetField(1)->AsVectorVal(); for ( unsigned int j = 1; j <= aligns->Size(); ++j ) { - const RecordVal* align = aligns->AsVectorVal()->Lookup(j)->AsRecordVal(); + const RecordVal* align = aligns->AsVectorVal()->At(j)->AsRecordVal(); const BroString* str = align->GetField(0)->AsString(); int index = align->GetField(1)->AsCount(); substr->AddAlignment(str, index); diff --git a/src/Stmt.cc b/src/Stmt.cc index 3dcd4374b4..ba0a95968f 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1225,7 +1225,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const for ( auto i = 0u; i <= vv->Size(); ++i ) { // Skip unassigned vector indices. - if ( ! vv->Lookup(i) ) + if ( ! vv->At(i) ) continue; // Set the loop variable to the current index, and make diff --git a/src/Val.cc b/src/Val.cc index 8b150d18b3..e7a006ca67 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -632,7 +632,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* auto* vval = val->AsVectorVal(); size_t size = vval->SizeVal()->AsCount(); for (size_t i = 0; i < size; i++) - BuildJSON(writer, vval->Lookup(i), only_loggable, re); + BuildJSON(writer, vval->At(i).get(), only_loggable, re); writer.EndArray(); break; @@ -3132,17 +3132,19 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const auto last_idx = v->Size(); for ( auto i = 0u; i < Size(); ++i ) - v->Assign(last_idx++, {NewRef{}, Lookup(i)}); + v->Assign(last_idx++, At(i)); return true; } -Val* VectorVal::Lookup(unsigned int index) const +const IntrusivePtr& VectorVal::At(unsigned int index) const { - if ( index >= val.vector_val->size() ) - return nullptr; + static IntrusivePtr nil; - return (*val.vector_val)[index].get(); + if ( index >= val.vector_val->size() ) + return nil; + + return (*val.vector_val)[index]; } unsigned int VectorVal::Resize(unsigned int new_num_elements) diff --git a/src/Val.h b/src/Val.h index b7248f217a..918c307e04 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1285,14 +1285,23 @@ public: // Returns true if succcessful. bool AddTo(Val* v, bool is_first_init) const override; - // Returns nil if no element was at that value. - // Lookup does NOT grow the vector to this size. - // The Val* variant assumes that the index Val* has been type-checked. - Val* Lookup(unsigned int index) const; + /** + * Returns the element at a given index or nullptr if it does not exist. + * @param index The position in the vector of the element to return. + * @return The element at the given index or nullptr if the index + * does not exist (it's greater than or equal to vector's current size). + */ + const IntrusivePtr& At(unsigned int index) const; + + [[deprecated("Remove in v4.1. Use At().")]] + Val* Lookup(unsigned int index) const + { return At(index).get(); } + + [[deprecated("Remove in v4.1. Use At().")]] Val* Lookup(Val* index) { bro_uint_t i = index->AsListVal()->Idx(0)->CoerceToUnsigned(); - return Lookup(static_cast(i)); + return At(static_cast(i)).get(); } unsigned int Size() const { return val.vector_val->size(); } diff --git a/src/analyzer/protocol/ssh/ssh-protocol.pac b/src/analyzer/protocol/ssh/ssh-protocol.pac index 427507a8f6..9b364601b8 100644 --- a/src/analyzer/protocol/ssh/ssh-protocol.pac +++ b/src/analyzer/protocol/ssh/ssh-protocol.pac @@ -400,11 +400,11 @@ refine connection SSH_Conn += { { for ( unsigned int j = 0; j < server_list->Size(); ++j ) { - if ( *(client_list->Lookup(i)->AsStringVal()->AsString()) == *(server_list->Lookup(j)->AsStringVal()->AsString()) ) + if ( *(client_list->At(i)->AsStringVal()->AsString()) == *(server_list->At(j)->AsStringVal()->AsString()) ) { kex_algorithm_.free(); - kex_algorithm_.init((const uint8 *) client_list->Lookup(i)->AsStringVal()->Bytes(), - client_list->Lookup(i)->AsStringVal()->Len()); + kex_algorithm_.init((const uint8 *) client_list->At(i)->AsStringVal()->Bytes(), + client_list->At(i)->AsStringVal()->Len()); // UNTESTED if ( update_kex_state_if_equal("rsa1024-sha1", KEX_RSA) ) diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 26e680d4cb..2a0530a34e 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -947,12 +947,12 @@ broker::expected bro_broker::val_to_data(const Val* v) for ( auto i = 0u; i < vec->Size(); ++i ) { - auto item_val = vec->Lookup(i); + const auto& item_val = vec->At(i); if ( ! item_val ) continue; - auto item = val_to_data(item_val); + auto item = val_to_data(item_val.get()); if ( ! item ) return broker::ec::invalid_data; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 6d185084e6..74e572ff76 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -396,7 +396,7 @@ bool Manager::PublishEvent(string topic, RecordVal* args) for ( auto i = 0u; i < vv->Size(); ++i ) { - const auto& val = vv->Lookup(i)->AsRecordVal()->GetField(0); + const auto& val = vv->At(i)->AsRecordVal()->GetField(0); auto data_val = static_cast(val.get()); xs.emplace_back(data_val->data); } diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index 8b90370358..214c10f24a 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -35,13 +35,13 @@ STACK_OF(X509)* x509_get_untrusted_stack(VectorVal* certs_vec) for ( int i = 1; i < (int) certs_vec->Size(); ++i ) // start at 1 - 0 is host cert { - Val *sv = certs_vec->Lookup(i); + const auto& sv = certs_vec->At(i); if ( ! sv ) continue; // Fixme: check type - X509* x = ((file_analysis::X509Val*) sv)->GetCertificate(); + X509* x = ((file_analysis::X509Val*) sv.get())->GetCertificate(); if ( ! x ) { sk_X509_free(untrusted_certs); @@ -230,14 +230,14 @@ function x509_ocsp_verify%(certs: x509_opaque_vector, ocsp_reply: string, root_c // host certificate unsigned int index = 0; // to prevent overloading to 0pointer - Val *sv = certs_vec->Lookup(index); + const auto& sv = certs_vec->At(index); if ( ! sv ) { builtin_error("undefined value in certificate vector"); return x509_result_record(-1, "undefined value in certificate vector"); } - file_analysis::X509Val* cert_handle = (file_analysis::X509Val*) sv; + file_analysis::X509Val* cert_handle = (file_analysis::X509Val*) sv.get(); X509* cert = cert_handle->GetCertificate(); if ( ! cert ) @@ -516,13 +516,13 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str // host certificate unsigned int index = 0; // to prevent overloading to 0pointer - Val *sv = certs_vec->Lookup(index); + const auto& sv = certs_vec->At(index); if ( !sv ) { builtin_error("undefined value in certificate vector"); return x509_result_record(-1, "undefined value in certificate vector"); } - file_analysis::X509Val* cert_handle = (file_analysis::X509Val*) sv; + file_analysis::X509Val* cert_handle = (file_analysis::X509Val*) sv.get(); X509* cert = cert_handle->GetCertificate(); if ( ! cert ) diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index b5dc099068..5b8982191f 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1033,7 +1033,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) for ( int i = 0; i < lval->val.vector_val.size; i++ ) { lval->val.vector_val.vals[i] = - ValToLogVal(vec->Lookup(i), + ValToLogVal(vec->At(i).get(), vec->GetType()->Yield().get()); } diff --git a/src/strings.bif b/src/strings.bif index b22fb894c6..00160454d1 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -102,7 +102,7 @@ function join_string_vec%(vec: string_vec, sep: string%): string if ( i > 0 ) d.Add(sep->CheckString(), 0); - Val* e = v->Lookup(i); + const auto& e = v->At(i); // If the element is empty, skip it. if ( ! e ) diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 2972291f97..df8aa63026 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1012,7 +1012,7 @@ Supervisor::NodeConfig Supervisor::NodeConfig::FromRecord(const RecordVal* node) for ( auto i = 0u; i < scripts_val->Size(); ++i ) { - auto script = scripts_val->Lookup(i)->AsStringVal()->ToStdString(); + auto script = scripts_val->At(i)->AsStringVal()->ToStdString(); rval.scripts.emplace_back(std::move(script)); } diff --git a/src/zeek.bif b/src/zeek.bif index 37f7af26d2..8079ed8af9 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -815,7 +815,7 @@ function paraglob_init%(v: any%) : opaque of paraglob VectorVal* vv = v->AsVectorVal(); for ( unsigned int i = 0; i < vv->Size(); ++i ) { - const BroString* s = vv->Lookup(i)->AsString(); + const BroString* s = vv->At(i)->AsString(); patterns.push_back(std::string(reinterpret_cast(s->Bytes()), s->Len())); } @@ -1291,7 +1291,7 @@ function any_set%(v: any%) : bool VectorVal* vv = v->AsVectorVal(); for ( unsigned int i = 0; i < vv->Size(); ++i ) - if ( vv->Lookup(i) && vv->Lookup(i)->AsBool() ) + if ( vv->At(i) && vv->At(i)->AsBool() ) return val_mgr->True(); return val_mgr->False(); @@ -1320,7 +1320,7 @@ function all_set%(v: any%) : bool VectorVal* vv = v->AsVectorVal(); for ( unsigned int i = 0; i < vv->Size(); ++i ) - if ( ! vv->Lookup(i) || ! vv->Lookup(i)->AsBool() ) + if ( ! vv->At(i) || ! vv->At(i)->AsBool() ) return val_mgr->False(); return val_mgr->True(); From ea878208ba01858609b580dc1f7a96fe7e56fecd Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 17:22:39 -0700 Subject: [PATCH 109/151] Factor static-local nil IntrusivePtrs to global locations Minor optimization to remove any run-time impact. --- src/EventHandler.cc | 6 ++---- src/Func.h | 7 +++---- src/ID.h | 2 ++ src/Scope.cc | 5 ++--- src/Type.cc | 3 +-- src/Type.h | 4 ++++ src/Val.cc | 15 +++++---------- src/Val.h | 2 ++ 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 051a7f98d2..3be382b561 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -28,8 +28,6 @@ EventHandler::operator bool() const const IntrusivePtr& EventHandler::GetType(bool check_export) { - static IntrusivePtr nil; - if ( type ) return type; @@ -37,10 +35,10 @@ const IntrusivePtr& EventHandler::GetType(bool check_export) check_export); if ( ! id ) - return nil; + return FuncType::nil; if ( id->GetType()->Tag() != TYPE_FUNC ) - return nil; + return FuncType::nil; type = id->GetType(); return type; diff --git a/src/Func.h b/src/Func.h index 6b96373045..1f0665ad54 100644 --- a/src/Func.h +++ b/src/Func.h @@ -30,6 +30,8 @@ class Scope; class Func : public BroObj { public: + static inline const IntrusivePtr nil; + enum Kind { BRO_FUNC, BUILTIN_FUNC }; explicit Func(Kind arg_kind); @@ -99,10 +101,7 @@ public: uint32_t GetUniqueFuncID() const { return unique_id; } static const IntrusivePtr& GetFuncPtrByID(uint32_t id) - { - static IntrusivePtr nil; - return id >= unique_ids.size() ? nil : unique_ids[id]; - } + { return id >= unique_ids.size() ? Func::nil : unique_ids[id]; } protected: Func(); diff --git a/src/ID.h b/src/ID.h index 0cce2e4239..efd3aa655a 100644 --- a/src/ID.h +++ b/src/ID.h @@ -28,6 +28,8 @@ typedef enum { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL } IDScope; class ID final : public BroObj, public notifier::Modifiable { public: + static inline const IntrusivePtr nil; + ID(const char* name, IDScope arg_scope, bool arg_is_export); ~ID() override; diff --git a/src/Scope.cc b/src/Scope.cc index d6c0c343e1..9378b477df 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -14,7 +14,6 @@ typedef PList scope_list; static scope_list scopes; static Scope* top_scope; -static IntrusivePtr nil_id; Scope::Scope(IntrusivePtr id, attr_list* al) : scope_id(std::move(id)) @@ -64,7 +63,7 @@ const IntrusivePtr& Scope::Find(std::string_view name) const if ( entry != local.end() ) return entry->second; - return nil_id; + return ID::nil; } IntrusivePtr Scope::Remove(std::string_view name) @@ -172,7 +171,7 @@ const IntrusivePtr& lookup_ID(const char* name, const char* curr_module, return global_scope()->Find(globalname); } - return nil_id; + return ID::nil; } IntrusivePtr install_ID(const char* name, const char* module_name, diff --git a/src/Type.cc b/src/Type.cc index 02956ed517..411ee79450 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -111,8 +111,7 @@ int BroType::MatchesIndex(ListExpr* const index) const const IntrusivePtr& BroType::Yield() const { - static IntrusivePtr nil; - return nil; + return BroType::nil; } bool BroType::HasField(const char* /* field */) const diff --git a/src/Type.h b/src/Type.h index 1bb81822d5..f23ed24e6f 100644 --- a/src/Type.h +++ b/src/Type.h @@ -141,6 +141,8 @@ const int MATCHES_INDEX_VECTOR = 2; class BroType : public BroObj { public: + static inline const IntrusivePtr nil; + explicit BroType(TypeTag tag, bool base_type = false); // Performs a shallow clone operation of the Bro type. @@ -456,6 +458,8 @@ protected: class FuncType final : public BroType { public: + static inline const IntrusivePtr nil; + /** * Prototype is only currently used for events and hooks which declare * multiple signature prototypes that allow users to have handlers diff --git a/src/Val.cc b/src/Val.cc index e7a006ca67..5437122493 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1897,9 +1897,6 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) { - static IntrusivePtr nil; - static IntrusivePtr exists = val_mgr->True(); - if ( subnets ) { TableEntryVal* v = (TableEntryVal*) subnets->Lookup(index.get()); @@ -1911,10 +1908,10 @@ const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) if ( v->GetVal() ) return v->GetVal(); - return exists; + return val_mgr->True(); } - return nil; + return Val::nil; } const PDict* tbl = AsTable(); @@ -1935,12 +1932,12 @@ const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) if ( v->GetVal() ) return v->GetVal(); - return exists; + return val_mgr->True(); } } } - return nil; + return Val::nil; } IntrusivePtr TableVal::FindOrDefault(const IntrusivePtr& index) @@ -3139,10 +3136,8 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const const IntrusivePtr& VectorVal::At(unsigned int index) const { - static IntrusivePtr nil; - if ( index >= val.vector_val->size() ) - return nil; + return Val::nil; return (*val.vector_val)[index]; } diff --git a/src/Val.h b/src/Val.h index 918c307e04..d1960822b0 100644 --- a/src/Val.h +++ b/src/Val.h @@ -118,6 +118,8 @@ union BroValUnion { class Val : public BroObj { public: + static inline const IntrusivePtr nil; + Val(double d, TypeTag t) : val(d), type(base_type(t)) {} From 4e77df3c28ca92545a2d774107a4b3e598f719d9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 17:49:47 -0700 Subject: [PATCH 110/151] Add is_vector() methods taking const-ref IntrusivePtr --- src/Expr.cc | 64 ++++++++++++++++++++++++++--------------------------- src/Expr.h | 3 ++- src/Val.h | 8 +++---- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index c828b1dd93..6c5410c047 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -352,7 +352,7 @@ IntrusivePtr UnaryExpr::Eval(Frame* f) const if ( ! v ) return nullptr; - if ( is_vector(v.get()) && Tag() != EXPR_IS && Tag() != EXPR_CAST ) + if ( is_vector(v) && Tag() != EXPR_IS && Tag() != EXPR_CAST ) { VectorVal* v_op = v->AsVectorVal(); IntrusivePtr out_t; @@ -439,8 +439,8 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const if ( ! v2 ) return nullptr; - bool is_vec1 = is_vector(v1.get()); - bool is_vec2 = is_vector(v2.get()); + bool is_vec1 = is_vector(v1); + bool is_vec2 = is_vector(v2); if ( is_vec1 && is_vec2 ) { // fold pairs of elements @@ -965,7 +965,7 @@ IntrusivePtr IncrExpr::Eval(Frame* f) const if ( ! v ) return nullptr; - if ( is_vector(v.get()) ) + if ( is_vector(v) ) { IntrusivePtr v_vec{NewRef{}, v->AsVectorVal()}; @@ -1053,7 +1053,7 @@ PosExpr::PosExpr(IntrusivePtr arg_op) else ExprError("requires an integral or double operand"); - if ( is_vector(op.get()) ) + if ( is_vector(op) ) SetType(make_intrusive(std::move(base_result_type))); else SetType(std::move(base_result_type)); @@ -1088,7 +1088,7 @@ NegExpr::NegExpr(IntrusivePtr arg_op) else ExprError("requires an integral or double operand"); - if ( is_vector(op.get()) ) + if ( is_vector(op) ) SetType(make_intrusive(std::move(base_result_type))); else SetType(std::move(base_result_type)); @@ -1154,7 +1154,7 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) else if ( bt2 == TYPE_TIME && bt1 == TYPE_INTERVAL ) base_result_type = base_type(bt2); else if ( BothArithmetic(bt1, bt2) ) - PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); + PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); else if ( BothString(bt1, bt2) ) base_result_type = base_type(bt1); else @@ -1162,7 +1162,7 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( base_result_type ) { - if ( is_vector(op1.get()) || is_vector(op2.get()) ) + if ( is_vector(op1) || is_vector(op2) ) SetType(make_intrusive(std::move(base_result_type))); else SetType(std::move(base_result_type)); @@ -1179,7 +1179,7 @@ void AddExpr::Canonicize() } AddToExpr::AddToExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) - : BinaryExpr(EXPR_ADD_TO, is_vector(arg_op1.get()) ? + : BinaryExpr(EXPR_ADD_TO, is_vector(arg_op1) ? std::move(arg_op1) : arg_op1->MakeLvalue(), std::move(arg_op2)) { @@ -1190,7 +1190,7 @@ AddToExpr::AddToExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) TypeTag bt2 = op2->GetType()->Tag(); if ( BothArithmetic(bt1, bt2) ) - PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); + PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); else if ( BothString(bt1, bt2) || BothInterval(bt1, bt2) ) SetType(base_type(bt1)); @@ -1236,7 +1236,7 @@ IntrusivePtr AddToExpr::Eval(Frame* f) const if ( ! v2 ) return nullptr; - if ( is_vector(v1.get()) ) + if ( is_vector(v1) ) { VectorVal* vv = v1->AsVectorVal(); @@ -1289,14 +1289,14 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) } else if ( BothArithmetic(bt1, bt2) ) - PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); + PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); else ExprError("requires arithmetic operands"); if ( base_result_type ) { - if ( is_vector(op1.get()) || is_vector(op2.get()) ) + if ( is_vector(op1) || is_vector(op2) ) SetType(make_intrusive(std::move(base_result_type))); else SetType(std::move(base_result_type)); @@ -1314,7 +1314,7 @@ RemoveFromExpr::RemoveFromExpr(IntrusivePtr arg_op1, TypeTag bt2 = op2->GetType()->Tag(); if ( BothArithmetic(bt1, bt2) ) - PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); + PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); else if ( BothInterval(bt1, bt2) ) SetType(base_type(bt1)); else @@ -1363,12 +1363,12 @@ TimesExpr::TimesExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) { if ( IsArithmetic(bt1) || IsArithmetic(bt2) ) - PromoteType(TYPE_INTERVAL, is_vector(op1.get()) || is_vector(op2.get()) ); + PromoteType(TYPE_INTERVAL, is_vector(op1) || is_vector(op2) ); else ExprError("multiplication with interval requires arithmetic operand"); } else if ( BothArithmetic(bt1, bt2) ) - PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); + PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); else ExprError("requires arithmetic operands"); } @@ -1400,10 +1400,10 @@ DivideExpr::DivideExpr(IntrusivePtr arg_op1, if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) { if ( IsArithmetic(bt1) || IsArithmetic(bt2) ) - PromoteType(TYPE_INTERVAL, is_vector(op1.get()) || is_vector(op2.get())); + PromoteType(TYPE_INTERVAL, is_vector(op1) || is_vector(op2)); else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL ) { - if ( is_vector(op1.get()) || is_vector(op2.get()) ) + if ( is_vector(op1) || is_vector(op2) ) SetType(make_intrusive(base_type(TYPE_DOUBLE))); else SetType(base_type(TYPE_DOUBLE)); @@ -1413,9 +1413,9 @@ DivideExpr::DivideExpr(IntrusivePtr arg_op1, } else if ( BothArithmetic(bt1, bt2) ) - PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); + PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); - else if ( bt1 == TYPE_ADDR && ! is_vector(op2.get()) && + else if ( bt1 == TYPE_ADDR && ! is_vector(op2) && (bt2 == TYPE_COUNT || bt2 == TYPE_INT) ) SetType(base_type(TYPE_SUBNET)); @@ -1465,7 +1465,7 @@ ModExpr::ModExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); if ( BothIntegral(bt1, bt2) ) - PromoteType(max_type(bt1, bt2), is_vector(op1.get()) || is_vector(op2.get())); + PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); else ExprError("requires integral operands"); } @@ -1489,9 +1489,9 @@ BoolExpr::BoolExpr(BroExprTag arg_tag, if ( BothBool(bt1, bt2) ) { - if ( is_vector(op1.get()) || is_vector(op2.get()) ) + if ( is_vector(op1) || is_vector(op2) ) { - if ( ! (is_vector(op1.get()) && is_vector(op2.get())) ) + if ( ! (is_vector(op1) && is_vector(op2)) ) reporter->Warning("mixing vector and scalar operands is deprecated"); SetType(make_intrusive(base_type(TYPE_BOOL))); } @@ -1534,8 +1534,8 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const if ( ! v1 ) return nullptr; - bool is_vec1 = is_vector(op1.get()); - bool is_vec2 = is_vector(op2.get()); + bool is_vec1 = is_vector(op1); + bool is_vec2 = is_vector(op2); // Handle scalar op scalar if ( ! is_vec1 && ! is_vec2 ) @@ -1642,7 +1642,7 @@ BitExpr::BitExpr(BroExprTag arg_tag, { if ( bt1 == TYPE_COUNTER && bt2 == TYPE_COUNTER ) ExprError("cannot apply a bitwise operator to two \"counter\" operands"); - else if ( is_vector(op1.get()) || is_vector(op2.get()) ) + else if ( is_vector(op1) || is_vector(op2) ) SetType(make_intrusive(base_type(TYPE_COUNT))); else SetType(base_type(TYPE_COUNT)); @@ -1690,7 +1690,7 @@ EqExpr::EqExpr(BroExprTag arg_tag, if ( IsVector(bt2) ) bt2 = t2->AsVectorType()->Yield()->Tag(); - if ( is_vector(op1.get()) || is_vector(op2.get()) ) + if ( is_vector(op1) || is_vector(op2) ) SetType(make_intrusive(base_type(TYPE_BOOL))); else SetType(base_type(TYPE_BOOL)); @@ -1792,7 +1792,7 @@ RelExpr::RelExpr(BroExprTag arg_tag, if ( IsVector(bt2) ) bt2 = t2->AsVectorType()->Yield()->Tag(); - if ( is_vector(op1.get()) || is_vector(op2.get()) ) + if ( is_vector(op1) || is_vector(op2) ) SetType(make_intrusive(base_type(TYPE_BOOL))); else SetType(base_type(TYPE_BOOL)); @@ -1850,7 +1850,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, { TypeTag bt2 = op2->GetType()->Tag(); - if ( is_vector(op2.get()) ) + if ( is_vector(op2) ) bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); TypeTag bt3 = op3->GetType()->Tag(); @@ -1858,7 +1858,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, if ( IsVector(bt3) ) bt3 = op3->GetType()->AsVectorType()->Yield()->Tag(); - if ( is_vector(op1.get()) && ! (is_vector(op2.get()) && is_vector(op3.get())) ) + if ( is_vector(op1) && ! (is_vector(op2) && is_vector(op3)) ) { ExprError("vector conditional requires vector alternatives"); return; @@ -1872,7 +1872,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, if ( bt3 != t ) op3 = make_intrusive(std::move(op3), t); - if ( is_vector(op2.get()) ) + if ( is_vector(op2) ) SetType(make_intrusive(base_type(t))); else SetType(base_type(t)); @@ -1894,7 +1894,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, IntrusivePtr CondExpr::Eval(Frame* f) const { - if ( ! is_vector(op1.get()) ) + if ( ! is_vector(op1) ) { // Scalar case auto false_eval = op1->Eval(f)->IsZero(); diff --git a/src/Expr.h b/src/Expr.h index 79ee9d9bd1..28c7d909fe 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -941,5 +941,6 @@ std::optional>> eval_list(Frame* f, const ListExpr // a canonical form. extern bool expr_greater(const Expr* e1, const Expr* e2); -// True if the given Val* has a vector type +// True if the given Expr* has a vector type inline bool is_vector(Expr* e) { return e->GetType()->Tag() == TYPE_VECTOR; } +inline bool is_vector(const IntrusivePtr& e) { return is_vector(e.get()); } diff --git a/src/Val.h b/src/Val.h index d1960822b0..70baef9aa7 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1340,10 +1340,9 @@ protected: }; // Checks the given value for consistency with the given type. If an -// exact match, returns it. If promotable, returns the promoted version, -// Unref()'ing the original. If not a match, generates an error message -// and returns nil, also Unref()'ing v. If is_init is true, then -// the checking is done in the context of an initialization. +// exact match, returns it. If promotable, returns the promoted version. +// If not a match, generates an error message and return nil. If is_init is +// true, then the checking is done in the context of an initialization. extern IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, bool is_init, const Location* expr_location = nullptr); @@ -1358,6 +1357,7 @@ extern void delete_vals(val_list* vals); // True if the given Val* has a vector type. inline bool is_vector(Val* v) { return v->GetType()->Tag() == TYPE_VECTOR; } +inline bool is_vector(const IntrusivePtr& v) { return is_vector(v.get()); } // Returns v casted to type T if the type supports that. Returns null if not. // From 4b17929b6bb7d289d3934c690765cf264f85b60d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 19:46:57 -0700 Subject: [PATCH 111/151] Deprecate IndexType::Indices(), replace with GetIndices() --- src/CompHash.cc | 2 +- src/Expr.cc | 21 ++++++++++----------- src/Type.cc | 15 ++++++++------- src/Type.h | 4 ++++ src/Val.cc | 14 ++++++-------- src/broker/Data.cc | 8 ++++---- src/input/Manager.cc | 6 +++--- src/input/readers/config/Config.cc | 2 +- src/logging/Manager.cc | 2 +- src/threading/SerialTypes.cc | 2 +- 10 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/CompHash.cc b/src/CompHash.cc index 4331603b5d..a826df8fbf 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -948,7 +948,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, for ( int i = 0; i < n; ++i ) { IntrusivePtr key; - kp1 = RecoverOneVal(k, kp1, k_end, tt->Indices(), &key, false); + kp1 = RecoverOneVal(k, kp1, k_end, tt->GetIndices().get(), &key, false); if ( t->IsSet() ) tv->Assign(std::move(key), nullptr); diff --git a/src/Expr.cc b/src/Expr.cc index 6c5410c047..04bf4d640a 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2384,7 +2384,7 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) const TableType* tt = tv->GetType()->AsTableType(); const auto& yt = tv->GetType()->Yield(); - auto index = op1->InitVal(tt->Indices(), nullptr); + auto index = op1->InitVal(tt->GetIndices().get(), nullptr); auto v = op2->InitVal(yt.get(), nullptr); if ( ! index || ! v ) @@ -3084,7 +3084,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; - const auto& indices = type->AsTableType()->Indices()->Types(); + const auto& indices = type->AsTableType()->GetIndices()->Types(); const expr_list& cle = op->AsListExpr()->Exprs(); // check and promote all index expressions in ctor list @@ -3203,7 +3203,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; - const auto& indices = type->AsTableType()->Indices()->Types(); + const auto& indices = type->AsTableType()->GetIndices()->Types(); expr_list& cle = op->AsListExpr()->Exprs(); if ( indices.size() == 1 ) @@ -3222,7 +3222,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, ListExpr* le = ce->AsListExpr(); if ( ce->Tag() == EXPR_LIST && - check_and_promote_exprs(le, type->AsTableType()->Indices()) ) + check_and_promote_exprs(le, type->AsTableType()->GetIndices().get()) ) { if ( le != cle[i] ) cle.replace(i, le); @@ -3258,7 +3258,7 @@ IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtrAsTableType()->Indices(); + const auto& index_type = t->AsTableType()->GetIndices(); auto tt = GetType(); auto tval = aggr ? IntrusivePtr{AdoptRef{}, aggr.release()->AsTableVal()} : @@ -3267,7 +3267,7 @@ IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtrEval(nullptr), index_type, true); + auto element = check_and_promote(e->Eval(nullptr), index_type.get(), true); if ( ! element || ! tval->Assign(std::move(element), nullptr) ) { @@ -3906,10 +3906,9 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) else { const auto& t1 = op1->GetType(); - const TypeList* it = - op2->GetType()->AsTableType()->Indices(); + const auto& it = op2->GetType()->AsTableType()->GetIndices(); - if ( ! same_type(t1.get(), it) ) + if ( ! same_type(t1.get(), it.get()) ) { t1->Error("indexing mismatch", op2->GetType().get()); SetError(); @@ -4462,7 +4461,7 @@ IntrusivePtr ListExpr::InitType() const if ( ti->IsSet() || ti->Tag() == TYPE_LIST ) { TypeList* til = ti->IsSet() ? - ti->AsSetType()->Indices() : + ti->AsSetType()->GetIndices().get() : ti->AsTypeList(); if ( ! til->IsPure() || @@ -4630,7 +4629,7 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) TableVal* tv = aggr->AsTableVal(); const TableType* tt = tv->GetType()->AsTableType(); - const TypeList* it = tt->Indices(); + const TypeList* it = tt->GetIndices().get(); for ( const auto& expr : exprs ) { diff --git a/src/Type.cc b/src/Type.cc index 411ee79450..297349ecb3 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -230,7 +230,7 @@ int IndexType::MatchesIndex(ListExpr* const index) const exprs.length() == 1 && exprs[0]->GetType()->Tag() == TYPE_ADDR ) return MATCHES_INDEX_SCALAR; - return check_and_promote_exprs(index, Indices()) ? + return check_and_promote_exprs(index, GetIndices().get()) ? MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX; } @@ -1416,7 +1416,7 @@ static bool is_init_compat(const BroType* t1, const BroType* t2) } if ( t1->IsSet() ) - return same_type(t1->AsSetType()->Indices(), t2, true); + return same_type(t1->AsSetType()->GetIndices().get(), t2, true); return false; } @@ -1472,12 +1472,12 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re const IndexType* it1 = (const IndexType*) t1; const IndexType* it2 = (const IndexType*) t2; - TypeList* tl1 = it1->Indices(); - TypeList* tl2 = it2->Indices(); + const auto& tl1 = it1->GetIndices(); + const auto& tl2 = it2->GetIndices(); if ( tl1 || tl2 ) { - if ( ! tl1 || ! tl2 || ! same_type(tl1, tl2, is_init, match_record_field_names) ) + if ( ! tl1 || ! tl2 || ! same_type(tl1.get(), tl2.get(), is_init, match_record_field_names) ) return false; } @@ -1981,11 +1981,12 @@ static BroType* reduce_type(BroType* t) else if ( t->IsSet() ) { - TypeList* tl = t->AsTableType()->Indices(); + const auto& tl = t->AsTableType()->GetIndices(); + if ( tl->Types().size() == 1 ) return tl->Types()[0].get(); else - return tl; + return tl.get(); } else diff --git a/src/Type.h b/src/Type.h index f23ed24e6f..c4d6989863 100644 --- a/src/Type.h +++ b/src/Type.h @@ -400,6 +400,10 @@ class IndexType : public BroType { public: int MatchesIndex(ListExpr* index) const override; + const IntrusivePtr& GetIndices() const + { return indices; } + + [[deprecated("Remove in v4.1. Use GetIndices().")]] TypeList* Indices() const { return indices.get(); } const std::vector>& IndexTypes() const diff --git a/src/Val.cc b/src/Val.cc index 5437122493..b609436cb2 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1358,7 +1358,7 @@ static void find_nested_record_types(BroType* t, std::set* found) } return; case TYPE_TABLE: - find_nested_record_types(t->AsTableType()->Indices(), found); + find_nested_record_types(t->AsTableType()->GetIndices().get(), found); find_nested_record_types(t->AsTableType()->Yield().get(), found); return; case TYPE_LIST: @@ -1416,8 +1416,7 @@ void TableVal::Init(IntrusivePtr t) else subnets = nullptr; - table_hash = new CompositeHash(IntrusivePtr(NewRef{}, - table_type->Indices())); + table_hash = new CompositeHash(table_type->GetIndices()); val.table_val = new PDict; val.table_val->SetDeleteFunc(table_entry_val_delete_func); } @@ -1520,7 +1519,7 @@ bool TableVal::Assign(IntrusivePtr index, IntrusivePtr new_val) if ( ! k ) { - index->Error("index type doesn't match table", table_type->Indices()); + index->Error("index type doesn't match table", table_type->GetIndices().get()); return false; } @@ -1777,7 +1776,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) ListVal* iv = index->AsListVal(); if ( iv->BaseTag() != TYPE_ANY ) { - if ( table_type->Indices()->Types().size() != 1 ) + if ( table_type->GetIndices()->Types().size() != 1 ) reporter->InternalError("bad singleton list index"); for ( int i = 0; i < iv->Length(); ++i ) @@ -2185,7 +2184,7 @@ ListVal* TableVal::ConvertToList(TypeTag t) const IntrusivePtr TableVal::ToPureListVal() const { - const auto& tl = table_type->Indices()->Types(); + const auto& tl = table_type->GetIndices()->Types(); if ( tl.size() != 1 ) { InternalWarning("bad index type in TableVal::ToPureListVal"); @@ -2680,8 +2679,7 @@ TableVal::ParseTimeTableState TableVal::DumpTableState() void TableVal::RebuildTable(ParseTimeTableState ptts) { delete table_hash; - table_hash = new CompositeHash(IntrusivePtr(NewRef{}, - table_type->Indices())); + table_hash = new CompositeHash(table_type->GetIndices()); for ( auto& [key, val] : ptts ) Assign(std::move(key), std::move(val)); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 2a0530a34e..42fe19d41d 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -213,7 +213,7 @@ struct val_converter { for ( auto& item : a ) { - const auto& expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->GetIndices()->Types(); broker::vector composite_key; auto indices = caf::get_if(&item); @@ -272,7 +272,7 @@ struct val_converter { for ( auto& item : a ) { - const auto& expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->GetIndices()->Types(); broker::vector composite_key; auto indices = caf::get_if(&item.first); @@ -560,7 +560,7 @@ struct type_checker { for ( const auto& item : a ) { - const auto& expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->GetIndices()->Types(); auto indices = caf::get_if(&item); vector indices_to_check; @@ -619,7 +619,7 @@ struct type_checker { for ( auto& item : a ) { - const auto& expected_index_types = tt->Indices()->Types(); + const auto& expected_index_types = tt->GetIndices()->Types(); auto indices = caf::get_if(&item.first); vector indices_to_check; diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 2871b42ba8..8d9d82fb42 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -808,7 +808,7 @@ bool Manager::IsCompatibleType(BroType* t, bool atomic_only) if ( ! t->IsSet() ) return false; - return IsCompatibleType(t->AsSetType()->Indices()->GetPureType().get(), true); + return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true); } case TYPE_VECTOR: @@ -937,7 +937,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, bool optional = false; if ( ty == TYPE_TABLE ) - st = rec->GetFieldType(i)->AsSetType()->Indices()->GetPureType()->Tag(); + st = rec->GetFieldType(i)->AsSetType()->GetIndices()->GetPureType()->Tag(); else if ( ty == TYPE_VECTOR ) st = rec->GetFieldType(i)->AsVectorType()->Yield()->Tag(); @@ -2252,7 +2252,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ case TYPE_TABLE: { // all entries have to have the same type... - const auto& type = request_type->AsTableType()->Indices()->GetPureType(); + const auto& type = request_type->AsTableType()->GetIndices()->GetPureType(); auto set_index = make_intrusive(type); set_index->Append(type); auto s = make_intrusive(std::move(set_index), nullptr); diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 9ed946ba9b..2416ff7af0 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -45,7 +45,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) TypeTag primary = id->GetType()->Tag(); TypeTag secondary = TYPE_VOID; if ( primary == TYPE_TABLE ) - secondary = id->GetType()->AsSetType()->Indices()->GetPureType()->Tag(); + secondary = id->GetType()->AsSetType()->GetIndices()->GetPureType()->Tag(); else if ( primary == TYPE_VECTOR ) secondary = id->GetType()->AsVectorType()->Yield()->Tag(); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 5b8982191f..3499382b88 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -513,7 +513,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, TypeTag st = TYPE_VOID; if ( t->Tag() == TYPE_TABLE ) - st = t->AsSetType()->Indices()->GetPureType()->Tag(); + st = t->AsSetType()->GetIndices()->GetPureType()->Tag(); else if ( t->Tag() == TYPE_VECTOR ) st = t->AsVectorType()->Yield()->Tag(); diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index 1f6e6acd34..dbea04ef3a 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -154,7 +154,7 @@ bool Value::IsCompatibleType(BroType* t, bool atomic_only) if ( ! t->IsSet() ) return false; - return IsCompatibleType(t->AsSetType()->Indices()->GetPureType().get(), true); + return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true); } case TYPE_VECTOR: From 2c4cc95e7c0308fdce9bb0dd8a3899e73e281781 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 19:57:07 -0700 Subject: [PATCH 112/151] Change merge_types() to take IntrusivePtrs --- src/Type.cc | 42 ++++++++++++++++++++++++------------------ src/Type.h | 3 ++- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/Type.cc b/src/Type.cc index 297349ecb3..d29ecc05b0 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -383,10 +383,10 @@ SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements else { - auto t = merge_types(tl[0].get(), tl[1].get()); + auto t = merge_types(tl[0], tl[1]); for ( size_t i = 2; t && i < tl.size(); ++i ) - t = merge_types(t.get(), tl[i].get()); + t = merge_types(t, tl[i]); if ( ! t ) { @@ -1711,8 +1711,11 @@ TypeTag max_type(TypeTag t1, TypeTag t2) } } -IntrusivePtr merge_types(const BroType* t1, const BroType* t2) +IntrusivePtr merge_types(const IntrusivePtr& arg_t1, + const IntrusivePtr& arg_t2) { + auto t1 = arg_t1.get(); + auto t2 = arg_t2.get(); t1 = flatten_type(t1); t2 = flatten_type(t2); @@ -1794,15 +1797,15 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) for ( auto i = 0u; i < tl1.size(); ++i ) { - auto tl3_i = merge_types(tl1[i].get(), tl2[i].get()); + auto tl3_i = merge_types(tl1[i], tl2[i]); if ( ! tl3_i ) return nullptr; tl3->Append(std::move(tl3_i)); } - const BroType* y1 = t1->Yield().get(); - const BroType* y2 = t2->Yield().get(); + const auto& y1 = t1->Yield(); + const auto& y2 = t2->Yield(); IntrusivePtr y3; if ( y1 || y2 ) @@ -1834,10 +1837,10 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) const FuncType* ft1 = (const FuncType*) t1; const FuncType* ft2 = (const FuncType*) t1; - auto args = cast_intrusive(merge_types(ft1->Params().get(), - ft2->Params().get())); + auto args = cast_intrusive(merge_types(ft1->Params(), + ft2->Params())); auto yield = t1->Yield() ? - merge_types(t1->Yield().get(), t2->Yield().get()) : nullptr; + merge_types(t1->Yield(), t2->Yield()) : nullptr; return make_intrusive(std::move(args), std::move(yield), ft1->Flavor()); @@ -1857,7 +1860,7 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) { const TypeDecl* td1 = rt1->FieldDecl(i); const TypeDecl* td2 = rt2->FieldDecl(i); - auto tdl3_i = merge_types(td1->type.get(), td2->type.get()); + auto tdl3_i = merge_types(td1->type, td2->type); if ( ! streq(td1->id, td2->id) || ! tdl3_i ) { @@ -1901,7 +1904,7 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) // the initialization expression into a set of values. // So the merge type of the list is the type of one // of the elements, providing they're consistent. - return merge_types(l1[0].get(), l2[0].get()); + return merge_types(l1[0], l2[0]); } // Impure lists - must have the same size and match element @@ -1915,7 +1918,7 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) auto tl3 = make_intrusive(); for ( auto i = 0u; i < l1.size(); ++i ) - tl3->Append(merge_types(l1[i].get(), l2[i].get())); + tl3->Append(merge_types(l1[i], l2[i])); return tl3; } @@ -1927,7 +1930,7 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) return nullptr; } - return make_intrusive(merge_types(t1->Yield().get(), t2->Yield().get())); + return make_intrusive(merge_types(t1->Yield(), t2->Yield())); case TYPE_FILE: if ( ! same_type(t1->Yield().get(), t2->Yield().get()) ) @@ -1936,7 +1939,7 @@ IntrusivePtr merge_types(const BroType* t1, const BroType* t2) return nullptr; } - return make_intrusive(merge_types(t1->Yield().get(), t2->Yield().get())); + return make_intrusive(merge_types(t1->Yield(), t2->Yield())); case TYPE_UNION: reporter->InternalError("union type in merge_types()"); @@ -1965,7 +1968,7 @@ IntrusivePtr merge_type_list(ListExpr* elements) return t; for ( size_t i = 1; t && i < tl.size(); ++i ) - t = merge_types(t.get(), tl[i].get()); + t = merge_types(t, tl[i]); if ( ! t ) reporter->Error("inconsistent types in list"); @@ -2040,15 +2043,18 @@ IntrusivePtr init_type(Expr* init) for ( int i = 1; t && i < el.length(); ++i ) { auto el_t = el[i]->InitType(); - BroType* ti = el_t ? reduce_type(el_t.get()) : nullptr; + IntrusivePtr ti; + + if ( el_t ) + ti = {NewRef{}, reduce_type(el_t.get())}; if ( ! ti ) return nullptr; - if ( same_type(t.get(), ti) ) + if ( same_type(t.get(), ti.get()) ) continue; - t = merge_types(t.get(), ti); + t = merge_types(t, ti); } if ( ! t ) diff --git a/src/Type.h b/src/Type.h index c4d6989863..38be9b8c31 100644 --- a/src/Type.h +++ b/src/Type.h @@ -832,7 +832,8 @@ extern TypeTag max_type(TypeTag t1, TypeTag t2); // Given two types, returns the "merge", in which promotable types // are promoted to the maximum of the two. Returns nil (and generates // an error message) if the types are incompatible. -IntrusivePtr merge_types(const BroType* t1, const BroType* t2); +IntrusivePtr merge_types(const IntrusivePtr& t1, + const IntrusivePtr& t2); // Given a list of expressions, returns a (ref'd) type reflecting // a merged type consistent across all of them, or nil if this From 6a1c3124516c562b0165acef4a994723f04b5f42 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 21:33:02 -0700 Subject: [PATCH 113/151] Add same_type() overloads for IntrusivePtr args --- src/Attr.cc | 20 ++++---- src/CompHash.cc | 2 +- src/Expr.cc | 50 +++++++++--------- src/OpaqueVal.cc | 2 +- src/Stmt.cc | 6 +-- src/Type.cc | 62 ++++++++++++----------- src/Type.h | 18 ++++++- src/Val.cc | 34 ++++++------- src/Var.cc | 4 +- src/broker/Manager.cc | 4 +- src/input/Manager.cc | 45 ++++++++-------- src/logging/Manager.cc | 10 ++-- src/option.bif | 8 +-- src/probabilistic/Topk.cc | 4 +- src/probabilistic/bloom-filter.bif | 6 +-- src/probabilistic/cardinality-counter.bif | 4 +- src/threading/Manager.cc | 2 +- 17 files changed, 145 insertions(+), 136 deletions(-) diff --git a/src/Attr.cc b/src/Attr.cc index 251b1c595c..093e2d7f28 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -273,7 +273,7 @@ void Attributes::CheckAttr(Attr* a) } FuncType* aft = at->AsFuncType(); - if ( ! same_type(aft->Yield().get(), type.get()) ) + if ( ! same_type(aft->Yield(), type) ) { a->AttrExpr()->Error( is_add ? @@ -294,11 +294,11 @@ void Attributes::CheckAttr(Attr* a) break; } - BroType* atype = a->AttrExpr()->GetType().get(); + const auto& atype = a->AttrExpr()->GetType(); if ( type->Tag() != TYPE_TABLE || (type->IsSet() && ! in_record) ) { - if ( same_type(atype, type.get()) ) + if ( same_type(atype, type) ) // Ok. break; @@ -328,7 +328,7 @@ void Attributes::CheckAttr(Attr* a) } TableType* tt = type->AsTableType(); - BroType* ytype = tt->Yield().get(); + const auto& ytype = tt->Yield(); if ( ! in_record ) { @@ -340,7 +340,7 @@ void Attributes::CheckAttr(Attr* a) { FuncType* f = atype->AsFuncType(); if ( ! f->CheckArgs(tt->IndexTypes()) || - ! same_type(f->Yield().get(), ytype) ) + ! same_type(f->Yield(), ytype) ) Error("&default function type clash"); // Ok. @@ -354,7 +354,7 @@ void Attributes::CheckAttr(Attr* a) // Ok. break; - auto e = check_and_promote_expr(a->AttrExpr(), ytype); + auto e = check_and_promote_expr(a->AttrExpr(), ytype.get()); if ( e ) { @@ -374,7 +374,7 @@ void Attributes::CheckAttr(Attr* a) { // &default applies to record field. - if ( same_type(atype, type.get()) ) + if ( same_type(atype, type) ) // Ok. break; @@ -519,7 +519,7 @@ void Attributes::CheckAttr(Attr* a) break; } - if ( ! same_type(args[0].get(), the_table->AsTableType()) ) + if ( ! same_type(args[0], the_table->AsTableType()) ) { Error("&on_change: first argument must be of same type as table"); break; @@ -534,7 +534,7 @@ void Attributes::CheckAttr(Attr* a) for ( size_t i = 0; i < t_indexes.size(); i++ ) { - if ( ! same_type(args[2+i].get(), t_indexes[i].get()) ) + if ( ! same_type(args[2+i], t_indexes[i]) ) { Error("&on_change: index types do not match table"); break; @@ -542,7 +542,7 @@ void Attributes::CheckAttr(Attr* a) } if ( ! type->IsSet() ) - if ( ! same_type(args[2+t_indexes.size()].get(), the_table->Yield().get()) ) + if ( ! same_type(args[2+t_indexes.size()], the_table->Yield()) ) { Error("&on_change: value type does not match table"); break; diff --git a/src/CompHash.cc b/src/CompHash.cc index a826df8fbf..1804f24900 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -855,7 +855,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, if ( ! pvt ) reporter->InternalError("bad aggregate Val in CompositeHash::RecoverOneVal()"); - else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt.get(), t) ) + else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt, t) ) // ### Maybe fix later, but may be fundamentally // un-checkable --US reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); diff --git a/src/Expr.cc b/src/Expr.cc index 04bf4d640a..e652a3d09a 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -1282,7 +1282,7 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) else if ( t1->IsSet() && t2->IsSet() ) { - if ( same_type(t1.get(), t2.get()) ) + if ( same_type(t1, t2) ) SetType(op1->GetType()); else ExprError("incompatible \"set\" operands"); @@ -1660,7 +1660,7 @@ BitExpr::BitExpr(BroExprTag arg_tag, else if ( t1->IsSet() && t2->IsSet() ) { - if ( same_type(t1.get(), t2.get()) ) + if ( same_type(t1, t2) ) SetType(op1->GetType()); else ExprError("incompatible \"set\" operands"); @@ -1718,14 +1718,14 @@ EqExpr::EqExpr(BroExprTag arg_tag, break; case TYPE_ENUM: - if ( ! same_type(t1.get(), t2.get()) ) + if ( ! same_type(t1, t2) ) ExprError("illegal enum comparison"); break; case TYPE_TABLE: if ( t1->IsSet() && t2->IsSet() ) { - if ( ! same_type(t1.get(), t2.get()) ) + if ( ! same_type(t1, t2) ) ExprError("incompatible sets in comparison"); break; } @@ -1802,7 +1802,7 @@ RelExpr::RelExpr(BroExprTag arg_tag, else if ( t1->IsSet() && t2->IsSet() ) { - if ( ! same_type(t1.get(), t2.get()) ) + if ( ! same_type(t1, t2) ) ExprError("incompatible sets in comparison"); } @@ -1884,7 +1884,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, else { if ( IsRecord(bt2) && IsRecord(bt3) && - ! same_type(op2->GetType().get(), op3->GetType().get()) ) + ! same_type(op2->GetType(), op3->GetType()) ) ExprError("operands must be of the same type"); else SetType(op2->GetType()); @@ -2086,7 +2086,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs) op2 = make_intrusive( IntrusivePtr{NewRef{}, op2->AsListExpr()}, attr_copy); - if ( ! empty_list_assignment && ! same_type(op1->GetType().get(), op2->GetType().get()) ) + if ( ! empty_list_assignment && ! same_type(op1->GetType(), op2->GetType()) ) { if ( op1->GetType()->IsSet() ) ExprError("set type mismatch in assignment"); @@ -2119,7 +2119,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs) if ( op1->GetType()->Tag() == TYPE_RECORD && op2->GetType()->Tag() == TYPE_RECORD ) { - if ( same_type(op1->GetType().get(), op2->GetType().get()) ) + if ( same_type(op1->GetType(), op2->GetType()) ) { RecordType* rt1 = op1->GetType()->AsRecordType(); RecordType* rt2 = op2->GetType()->AsRecordType(); @@ -2141,7 +2141,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs) return true; } - if ( ! same_type(op1->GetType().get(), op2->GetType().get()) ) + if ( ! same_type(op1->GetType(), op2->GetType()) ) { if ( bt1 == TYPE_TABLE && bt2 == TYPE_TABLE ) { @@ -3547,8 +3547,8 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, break; } - BroType* sub_t_i = sub_r->GetFieldType(i).get(); - BroType* sup_t_i = t_r->GetFieldType(t_i).get(); + const auto& sub_t_i = sub_r->GetFieldType(i); + const auto& sup_t_i = t_r->GetFieldType(t_i); if ( ! same_type(sup_t_i, sub_t_i) ) { @@ -3581,12 +3581,12 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, sub->AsRecordType()); }; - if ( ! is_arithmetic_promotable(sup_t_i, sub_t_i) && - ! is_record_promotable(sup_t_i, sub_t_i) ) + if ( ! is_arithmetic_promotable(sup_t_i.get(), sub_t_i.get()) && + ! is_record_promotable(sup_t_i.get(), sub_t_i.get()) ) { std::string error_msg = fmt( "type clash for field \"%s\"", sub_r->FieldName(i)); - Error(error_msg.c_str(), sub_t_i); + Error(error_msg.c_str(), sub_t_i.get()); SetError(); break; } @@ -3670,18 +3670,18 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const continue; } - BroType* rhs_type = rhs->GetType().get(); + const auto& rhs_type = rhs->GetType(); const auto& field_type = val_type->GetFieldType(i); if ( rhs_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && - ! same_type(rhs_type, field_type.get()) ) + ! same_type(rhs_type, field_type) ) { if ( auto new_val = rhs->AsRecordVal()->CoerceTo(cast_intrusive(field_type)) ) rhs = std::move(new_val); } else if ( BothArithmetic(rhs_type->Tag(), field_type->Tag()) && - ! same_type(rhs_type, field_type.get()) ) + ! same_type(rhs_type, field_type) ) { if ( auto new_val = check_and_promote(rhs, field_type.get(), false, op->GetLocationInfo()) ) rhs = std::move(new_val); @@ -3701,7 +3701,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const if ( def_type->Tag() == TYPE_RECORD && field_type->Tag() == TYPE_RECORD && - ! same_type(def_type.get(), field_type.get()) ) + ! same_type(def_type, field_type) ) { auto tmp = def_val->AsRecordVal()->CoerceTo( cast_intrusive(field_type)); @@ -3908,7 +3908,7 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) const auto& t1 = op1->GetType(); const auto& it = op2->GetType()->AsTableType()->GetIndices(); - if ( ! same_type(t1.get(), it.get()) ) + if ( ! same_type(t1, it) ) { t1->Error("indexing mismatch", op2->GetType().get()); SetError(); @@ -4608,7 +4608,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co auto v = e->Eval(nullptr); - if ( ! same_type(v->GetType().get(), t) ) + if ( ! same_type(v->GetType(), t) ) { v->GetType()->Error("type clash in table initializer", t); return nullptr; @@ -4648,7 +4648,7 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) if ( element->GetType()->IsSet() ) { - if ( ! same_type(element->GetType().get(), t) ) + if ( ! same_type(element->GetType(), t) ) { element->Error("type clash in set initializer", t); return nullptr; @@ -4747,7 +4747,7 @@ RecordAssignExpr::RecordAssignExpr(const IntrusivePtr& record, int field = lhs->FieldOffset(field_name); if ( field >= 0 && - same_type(lhs->GetFieldType(field).get(), t->GetFieldType(j).get()) ) + same_type(lhs->GetFieldType(field), t->GetFieldType(j)) ) { auto fe_lhs = make_intrusive(record, field_name); auto fe_rhs = make_intrusive(IntrusivePtr{NewRef{}, init}, field_name); @@ -4818,7 +4818,7 @@ IntrusivePtr CastExpr::Eval(Frame* f) const GetType()->Describe(&d); d.Add("'"); - if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) && + if ( same_type(v->GetType(), bro_broker::DataVal::ScriptDataType()) && ! v->AsRecordVal()->GetField(0) ) d.Add(" (nil $data field)"); @@ -4906,7 +4906,7 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) RecordType* t_r = t->AsRecordType(); RecordType* et_r = et->AsRecordType(); - if ( same_type(t, et.get()) ) + if ( same_type(t, et) ) { // Make sure the attributes match as well. for ( int i = 0; i < t_r->NumFields(); ++i ) @@ -4929,7 +4929,7 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) } - if ( ! same_type(t, et.get()) ) + if ( ! same_type(t, et) ) { if ( t->Tag() == TYPE_TABLE && et->Tag() == TYPE_TABLE && et->AsTableType()->IsUnspecifiedTable() ) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 80d8462949..351d00fa19 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -770,7 +770,7 @@ IntrusivePtr BloomFilterVal::Merge(const BloomFilterVal* x, { if ( x->Type() && // any one 0 is ok here y->Type() && - ! same_type(x->Type().get(), y->Type().get()) ) + ! same_type(x->Type(), y->Type()) ) { reporter->Error("cannot merge Bloom filters with different types"); return nullptr; diff --git a/src/Stmt.cc b/src/Stmt.cc index ba0a95968f..f2de940c12 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -741,7 +741,7 @@ bool SwitchStmt::AddCaseLabelTypeMapping(ID* t, int idx) { for ( auto i : case_label_type_list ) { - if ( same_type(i.first->GetType().get(), t->GetType().get()) ) + if ( same_type(i.first->GetType(), t->GetType()) ) return false; } @@ -1080,7 +1080,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) if ( lvt ) { - if ( ! same_type(lvt.get(), ind_type.get()) ) + if ( ! same_type(lvt, ind_type) ) lvt->Error("type clash in iteration", ind_type.get()); } @@ -1151,7 +1151,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, // Verify value_vars type if its already been defined if ( value_var->GetType() ) { - if ( ! same_type(value_var->GetType().get(), yield_type.get()) ) + if ( ! same_type(value_var->GetType(), yield_type) ) value_var->GetType()->Error("type clash in iteration", yield_type.get()); } else diff --git a/src/Type.cc b/src/Type.cc index d29ecc05b0..3ab5bfee3e 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -156,14 +156,14 @@ unsigned int BroType::MemoryAllocation() const bool TypeList::AllMatch(const BroType* t, bool is_init) const { for ( const auto& type : types ) - if ( ! same_type(type.get(), t, is_init) ) + if ( ! same_type(type, t, is_init) ) return false; return true; } void TypeList::Append(IntrusivePtr t) { - if ( pure_type && ! same_type(t.get(), pure_type.get()) ) + if ( pure_type && ! same_type(t, pure_type) ) reporter->InternalError("pure type-list violation"); types.emplace_back(std::move(t)); @@ -171,7 +171,7 @@ void TypeList::Append(IntrusivePtr t) void TypeList::AppendEvenIfNotPure(IntrusivePtr t) { - if ( pure_type && ! same_type(t.get(), pure_type.get()) ) + if ( pure_type && ! same_type(t, pure_type) ) pure_type = nullptr; types.emplace_back(std::move(t)); @@ -503,7 +503,7 @@ bool FuncType::CheckArgs(const std::vector>& args, bool success = true; for ( size_t i = 0; i < my_args.size(); ++i ) - if ( ! same_type(args[i].get(), my_args[i].get(), is_init) ) + if ( ! same_type(args[i], my_args[i], is_init) ) { Warn(fmt("Type mismatch in function argument #%zu. Expected %s, got %s.", i, type_name(args[i]->Tag()), type_name(my_args[i]->Tag()))); @@ -592,7 +592,7 @@ std::optional FuncType::FindPrototype(const RecordType& arg const auto& ptype = p.args->GetFieldType(i); const auto& desired_type = args.GetFieldType(i); - if ( ! same_type(ptype.get(), desired_type.get()) || + if ( ! same_type(ptype, desired_type) || ! streq(args.FieldName(i), p.args->FieldName(i)) ) { matched = false; @@ -1405,38 +1405,40 @@ const IntrusivePtr& base_type(TypeTag tag) // false otherwise. Assumes that t1's tag is different from t2's. Note // that the test is in only one direction - we don't check whether t2 is // initialization-compatible with t1. -static bool is_init_compat(const BroType* t1, const BroType* t2) +static bool is_init_compat(const BroType& t1, const BroType& t2) { - if ( t1->Tag() == TYPE_LIST ) + if ( t1.Tag() == TYPE_LIST ) { - if ( t2->Tag() == TYPE_RECORD ) + if ( t2.Tag() == TYPE_RECORD ) return true; else - return t1->AsTypeList()->AllMatch(t2, true); + return t1.AsTypeList()->AllMatch(&t2, true); } - if ( t1->IsSet() ) - return same_type(t1->AsSetType()->GetIndices().get(), t2, true); + if ( t1.IsSet() ) + return same_type(*t1.AsSetType()->GetIndices(), t2, true); return false; } -bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_record_field_names) +bool same_type(const BroType& arg_t1, const BroType& arg_t2, + bool is_init, bool match_record_field_names) { - if ( t1 == t2 || - t1->Tag() == TYPE_ANY || - t2->Tag() == TYPE_ANY ) + if ( &arg_t1 == &arg_t2 || + arg_t1.Tag() == TYPE_ANY || + arg_t2.Tag() == TYPE_ANY ) return true; - t1 = flatten_type(t1); - t2 = flatten_type(t2); + auto t1 = flatten_type(&arg_t1); + auto t2 = flatten_type(&arg_t2); + if ( t1 == t2 ) return true; if ( t1->Tag() != t2->Tag() ) { if ( is_init ) - return is_init_compat(t1, t2) || is_init_compat(t2, t1); + return is_init_compat(*t1, *t2) || is_init_compat(*t2, *t1); return false; } @@ -1477,12 +1479,12 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re if ( tl1 || tl2 ) { - if ( ! tl1 || ! tl2 || ! same_type(tl1.get(), tl2.get(), is_init, match_record_field_names) ) + if ( ! tl1 || ! tl2 || ! same_type(tl1, tl2, is_init, match_record_field_names) ) return false; } - const BroType* y1 = t1->Yield().get(); - const BroType* y2 = t2->Yield().get(); + const auto& y1 = t1->Yield(); + const auto& y2 = t2->Yield(); if ( y1 || y2 ) { @@ -1504,7 +1506,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re if ( t1->Yield() || t2->Yield() ) { if ( ! t1->Yield() || ! t2->Yield() || - ! same_type(t1->Yield().get(), t2->Yield().get(), is_init, match_record_field_names) ) + ! same_type(t1->Yield(), t2->Yield(), is_init, match_record_field_names) ) return false; } @@ -1525,7 +1527,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re const TypeDecl* td2 = rt2->FieldDecl(i); if ( (match_record_field_names && ! streq(td1->id, td2->id)) || - ! same_type(td1->type.get(), td2->type.get(), is_init, match_record_field_names) ) + ! same_type(td1->type, td2->type, is_init, match_record_field_names) ) return false; } @@ -1541,7 +1543,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re return false; for ( auto i = 0u; i < tl1.size(); ++i ) - if ( ! same_type(tl1[i].get(), tl2[i].get(), is_init, match_record_field_names) ) + if ( ! same_type(tl1[i], tl2[i], is_init, match_record_field_names) ) return false; return true; @@ -1549,7 +1551,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re case TYPE_VECTOR: case TYPE_FILE: - return same_type(t1->Yield().get(), t2->Yield().get(), is_init, match_record_field_names); + return same_type(t1->Yield(), t2->Yield(), is_init, match_record_field_names); case TYPE_OPAQUE: { @@ -1562,7 +1564,7 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re { auto tt1 = t1->AsTypeType(); auto tt2 = t2->AsTypeType(); - return same_type(tt1->Type(), tt1->Type(), + return same_type(tt1->GetType(), tt1->GetType(), is_init, match_record_field_names); } @@ -1597,7 +1599,7 @@ bool record_promotion_compatible(const RecordType* super_rec, const auto& sub_field_type = sub_rec->GetFieldType(i); const auto& super_field_type = super_rec->GetFieldType(o); - if ( same_type(sub_field_type.get(), super_field_type.get()) ) + if ( same_type(sub_field_type, super_field_type) ) continue; if ( sub_field_type->Tag() != TYPE_RECORD ) @@ -1924,7 +1926,7 @@ IntrusivePtr merge_types(const IntrusivePtr& arg_t1, } case TYPE_VECTOR: - if ( ! same_type(t1->Yield().get(), t2->Yield().get()) ) + if ( ! same_type(t1->Yield(), t2->Yield()) ) { t1->Error("incompatible types", t2); return nullptr; @@ -1933,7 +1935,7 @@ IntrusivePtr merge_types(const IntrusivePtr& arg_t1, return make_intrusive(merge_types(t1->Yield(), t2->Yield())); case TYPE_FILE: - if ( ! same_type(t1->Yield().get(), t2->Yield().get()) ) + if ( ! same_type(t1->Yield(), t2->Yield()) ) { t1->Error("incompatible types", t2); return nullptr; @@ -2051,7 +2053,7 @@ IntrusivePtr init_type(Expr* init) if ( ! ti ) return nullptr; - if ( same_type(t.get(), ti.get()) ) + if ( same_type(t, ti) ) continue; t = merge_types(t, ti); diff --git a/src/Type.h b/src/Type.h index 38be9b8c31..efda5f6e17 100644 --- a/src/Type.h +++ b/src/Type.h @@ -544,6 +544,9 @@ public: explicit TypeType(IntrusivePtr t) : BroType(TYPE_TYPE), type(std::move(t)) {} IntrusivePtr ShallowClone() override { return make_intrusive(type); } + const IntrusivePtr& GetType() const + { return type; } + BroType* Type() { return type.get(); } const BroType* Type() const { return type.get(); } @@ -811,7 +814,20 @@ inline const IntrusivePtr& error_type() { return base_type(TYPE_ERROR); // True if the two types are equivalent. If is_init is true then the test is // done in the context of an initialization. If match_record_field_names is // true then for record types the field names have to match, too. -extern bool same_type(const BroType* t1, const BroType* t2, bool is_init=false, bool match_record_field_names=true); +extern bool same_type(const BroType& t1, const BroType& t2, + bool is_init=false, bool match_record_field_names=true); +inline bool same_type(const IntrusivePtr& t1, const IntrusivePtr& t2, + bool is_init=false, bool match_record_field_names=true) + { return same_type(*t1, *t2, is_init, match_record_field_names); } +inline bool same_type(const BroType* t1, const BroType* t2, + bool is_init=false, bool match_record_field_names=true) + { return same_type(*t1, *t2, is_init, match_record_field_names); } +inline bool same_type(const IntrusivePtr& t1, const BroType* t2, + bool is_init=false, bool match_record_field_names=true) + { return same_type(*t1, *t2, is_init, match_record_field_names); } +inline bool same_type(const BroType* t1, const IntrusivePtr& t2, + bool is_init=false, bool match_record_field_names=true) + { return same_type(*t1, *t2, is_init, match_record_field_names); } // True if the two attribute lists are equivalent. extern bool same_attrs(const Attributes* a1, const Attributes* a2); diff --git a/src/Val.cc b/src/Val.cc index b609436cb2..ce5f0d06bd 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1602,7 +1602,7 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const TableVal* t = val->AsTableVal(); - if ( ! same_type(type.get(), t->GetType().get()) ) + if ( ! same_type(type, t->GetType()) ) { type->Error("table type clash", t->GetType().get()); return false; @@ -1650,7 +1650,7 @@ bool TableVal::RemoveFrom(Val* val) const TableVal* t = val->AsTableVal(); - if ( ! same_type(type.get(), t->GetType().get()) ) + if ( ! same_type(type, t->GetType()) ) { type->Error("table type clash", t->GetType().get()); return false; @@ -1824,7 +1824,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) const auto& dtype = def_attr->AttrExpr()->GetType(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype.get(), ytype.get()) && + ! same_type(dtype, ytype) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) { @@ -1845,7 +1845,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) } if ( def_val->GetType()->Tag() != TYPE_FUNC || - same_type(def_val->GetType().get(), GetType()->Yield().get()) ) + same_type(def_val->GetType(), GetType()->Yield()) ) { if ( def_attr->AttrExpr()->IsConst() ) return def_val; @@ -2348,7 +2348,7 @@ void TableVal::InitDefaultFunc(Frame* f) const auto& dtype = def_attr->AttrExpr()->GetType(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && - ! same_type(dtype.get(), ytype.get()) && + ! same_type(dtype, ytype) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) return; // TableVal::Default will handle this. @@ -2720,7 +2720,7 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo if ( def && type->Tag() == TYPE_RECORD && def->GetType()->Tag() == TYPE_RECORD && - ! same_type(def->GetType().get(), type.get()) ) + ! same_type(def->GetType(), type) ) { auto tmp = def->AsRecordVal()->CoerceTo(cast_intrusive(type)); @@ -2867,7 +2867,7 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, const auto& ft = ar_t->GetFieldType(t_i); - if ( ft->Tag() == TYPE_RECORD && ! same_type(ft.get(), v->GetType().get()) ) + if ( ft->Tag() == TYPE_RECORD && ! same_type(ft, v->GetType()) ) { auto rhs = make_intrusive(v); auto e = make_intrusive(std::move(rhs), @@ -2895,7 +2895,7 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, bool allow_orphaning) { - if ( same_type(GetType().get(), t.get()) ) + if ( same_type(GetType(), t) ) return {NewRef{}, this}; return CoerceTo(std::move(t), nullptr, allow_orphaning); @@ -3051,7 +3051,7 @@ IntrusivePtr VectorVal::SizeVal() const bool VectorVal::Assign(unsigned int index, IntrusivePtr element) { if ( element && - ! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) ) + ! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) ) return false; if ( index >= val.vector_val->size() ) @@ -3078,7 +3078,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, bool VectorVal::Insert(unsigned int index, IntrusivePtr element) { if ( element && - ! same_type(element->GetType().get(), GetType()->AsVectorType()->Yield().get(), false) ) + ! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) ) { return false; } @@ -3118,7 +3118,7 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const VectorVal* v = val->AsVectorVal(); - if ( ! same_type(type.get(), v->GetType().get()) ) + if ( ! same_type(type, v->GetType()) ) { type->Error("vector type clash", v->GetType().get()); return false; @@ -3198,9 +3198,7 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, if ( ! v ) return nullptr; - BroType* vt = v->GetType().get(); - - vt = flatten_type(vt); + BroType* vt = flatten_type(v->GetType().get()); t = flatten_type(t); TypeTag t_tag = t->Tag(); @@ -3394,10 +3392,10 @@ IntrusivePtr cast_value_to_type(Val* v, BroType* t) // Always allow casting to same type. This also covers casting 'any' // to the actual type. - if ( same_type(v->GetType().get(), t) ) + if ( same_type(v->GetType(), t) ) return {NewRef{}, v}; - if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(v->GetType(), bro_broker::DataVal::ScriptDataType()) ) { const auto& dv = v->AsRecordVal()->GetField(0); @@ -3420,10 +3418,10 @@ bool can_cast_value_to_type(const Val* v, BroType* t) // Always allow casting to same type. This also covers casting 'any' // to the actual type. - if ( same_type(v->GetType().get(), t) ) + if ( same_type(v->GetType(), t) ) return true; - if ( same_type(v->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(v->GetType(), bro_broker::DataVal::ScriptDataType()) ) { const auto& dv = v->AsRecordVal()->GetField(0); diff --git a/src/Var.cc b/src/Var.cc index 33895f5def..590823587e 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -153,7 +153,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, } // Allow redeclaration in order to initialize. - if ( ! same_type(t.get(), id->GetType().get()) ) + if ( ! same_type(t, id->GetType()) ) { id->Error("redefinition changes type", init.get()); return; @@ -449,7 +449,7 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl return false; for ( auto i = 0; i < canon_args->NumFields(); ++i ) - if ( ! same_type(canon_args->GetFieldType(i).get(), impl_args->GetFieldType(i).get()) ) + if ( ! same_type(canon_args->GetFieldType(i), impl_args->GetFieldType(i)) ) return false; return true; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 74e572ff76..98f9651d41 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -743,7 +743,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) const auto& got_type = (*args)[i]->GetType(); const auto& expected_type = func->GetType()->ParamList()->Types()[i - 1]; - if ( ! same_type(got_type.get(), expected_type.get()) ) + if ( ! same_type(got_type, expected_type) ) { rval->Assign(0, nullptr); Error("event parameter #%d type mismatch, got %s, expect %s", i, @@ -754,7 +754,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) IntrusivePtr data_val; - if ( same_type(got_type.get(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(got_type, bro_broker::DataVal::ScriptDataType()) ) data_val = {NewRef{}, (*args)[i]->AsRecordVal()}; else data_val = make_data_val((*args)[i]); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 8d9d82fb42..06931636c8 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -217,9 +217,9 @@ ReaderBackend* Manager::CreateBackend(ReaderFrontend* frontend, EnumVal* tag) bool Manager::CreateStream(Stream* info, RecordVal* description) { RecordType* rtype = description->GetType()->AsRecordType(); - if ( ! ( same_type(rtype, zeek::BifType::Record::Input::TableDescription.get(), false) - || same_type(rtype, zeek::BifType::Record::Input::EventDescription.get(), false) - || same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription.get(), false) ) ) + if ( ! ( same_type(rtype, zeek::BifType::Record::Input::TableDescription, false) + || same_type(rtype, zeek::BifType::Record::Input::EventDescription, false) + || same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription, false) ) ) { reporter->Error("Stream description argument not of right type for new input stream"); return false; @@ -305,7 +305,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) bool Manager::CreateEventStream(RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, zeek::BifType::Record::Input::EventDescription.get(), false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Input::EventDescription, false) ) { reporter->Error("EventDescription argument not of right type"); return false; @@ -339,13 +339,13 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - if ( ! same_type(args[1].get(), zeek::BifType::Enum::Input::Event.get(), false) ) + if ( ! same_type(args[1], zeek::BifType::Enum::Input::Event, false) ) { reporter->Error("Input stream %s: Event's second attribute must be of type Input::Event", stream_name.c_str()); return false; } - if ( ! same_type(args[0].get(), zeek::BifType::Record::Input::EventDescription.get(), false) ) + if ( ! same_type(args[0], zeek::BifType::Record::Input::EventDescription, false) ) { reporter->Error("Input stream %s: Event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; @@ -361,7 +361,7 @@ bool Manager::CreateEventStream(RecordVal* fval) for ( int i = 0; i < fields->NumFields(); i++ ) { - if ( ! same_type(args[i + 2].get(), fields->GetFieldType(i).get() ) ) + if ( ! same_type(args[i + 2], fields->GetFieldType(i) ) ) { ODesc desc1; ODesc desc2; @@ -387,7 +387,7 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - if ( ! same_type(args[2].get(), fields ) ) + if ( ! same_type(args[2], fields ) ) { ODesc desc1; ODesc desc2; @@ -459,7 +459,7 @@ bool Manager::CreateEventStream(RecordVal* fval) bool Manager::CreateTableStream(RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, zeek::BifType::Record::Input::TableDescription.get(), false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Input::TableDescription, false) ) { reporter->Error("TableDescription argument not of right type"); return false; @@ -492,7 +492,7 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( ! same_type(idx->GetFieldType(j).get(), tl[j].get()) ) + if ( ! same_type(idx->GetFieldType(j), tl[j]) ) { ODesc desc1; ODesc desc2; @@ -518,12 +518,9 @@ bool Manager::CreateTableStream(RecordVal* fval) if ( val ) { const auto& table_yield = dst->GetType()->AsTableType()->Yield(); - const BroType* compare_type = val.get(); + const auto& compare_type = want_record->InternalInt() == 0 ? val->GetFieldType(0) : val; - if ( want_record->InternalInt() == 0 ) - compare_type = val->GetFieldType(0).get(); - - if ( ! same_type(table_yield.get(), compare_type) ) + if ( ! same_type(table_yield, compare_type) ) { ODesc desc1; ODesc desc2; @@ -567,19 +564,19 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( ! same_type(args[0].get(), zeek::BifType::Record::Input::TableDescription.get(), false) ) + if ( ! same_type(args[0], zeek::BifType::Record::Input::TableDescription, false) ) { reporter->Error("Input stream %s: Table event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! same_type(args[1].get(), zeek::BifType::Enum::Input::Event.get(), false) ) + if ( ! same_type(args[1], zeek::BifType::Enum::Input::Event, false) ) { reporter->Error("Input stream %s: Table event's second attribute must be of type Input::Event", stream_name.c_str()); return false; } - if ( ! same_type(args[2].get(), idx) ) + if ( ! same_type(args[2], idx) ) { ODesc desc1; ODesc desc2; @@ -590,7 +587,7 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( want_record->InternalInt() == 1 && val && ! same_type(args[3].get(), val.get()) ) + if ( want_record->InternalInt() == 1 && val && ! same_type(args[3], val) ) { ODesc desc1; ODesc desc2; @@ -601,7 +598,7 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } else if ( want_record->InternalInt() == 0 - && val && !same_type(args[3].get(), val->GetFieldType(0).get() ) ) + && val && !same_type(args[3], val->GetFieldType(0) ) ) { ODesc desc1; ODesc desc2; @@ -714,13 +711,13 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - if ( table && ! same_type(args[0].get(), zeek::BifType::Record::Input::TableDescription.get(), false) ) + if ( table && ! same_type(args[0], zeek::BifType::Record::Input::TableDescription, false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! table && ! same_type(args[0].get(), zeek::BifType::Record::Input::EventDescription.get(), false) ) + if ( ! table && ! same_type(args[0], zeek::BifType::Record::Input::EventDescription, false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; @@ -732,7 +729,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - if ( ! same_type(args[2].get(), zeek::BifType::Enum::Reporter::Level.get(), false) ) + if ( ! same_type(args[2], zeek::BifType::Enum::Reporter::Level, false) ) { reporter->Error("Input stream %s: Error event's third attribute must be of type Reporter::Level", stream_name.c_str()); return false; @@ -745,7 +742,7 @@ bool Manager::CreateAnalysisStream(RecordVal* fval) { RecordType* rtype = fval->GetType()->AsRecordType(); - if ( ! same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription.get(), false) ) + if ( ! same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription, false) ) { reporter->Error("AnalysisDescription argument not of right type"); return false; diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 3499382b88..fa86027ed2 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -229,9 +229,7 @@ void Manager::RemoveDisabledWriters(Stream* stream) bool Manager::CreateStream(EnumVal* id, RecordVal* sval) { - RecordType* rtype = sval->GetType()->AsRecordType(); - - if ( ! same_type(rtype, zeek::BifType::Record::Log::Stream.get(), false) ) + if ( ! same_type(sval->GetType(), zeek::BifType::Record::Log::Stream, false) ) { reporter->Error("sval argument not of right type"); return false; @@ -286,7 +284,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) return false; } - if ( ! same_type(args[0].get(), columns) ) + if ( ! same_type(args[0], columns) ) { reporter->Error("stream event's argument type does not match column record type"); return false; @@ -528,9 +526,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, bool Manager::AddFilter(EnumVal* id, RecordVal* fval) { - RecordType* rtype = fval->GetType()->AsRecordType(); - - if ( ! same_type(rtype, zeek::BifType::Record::Log::Filter.get(), false) ) + if ( ! same_type(fval->GetType(), zeek::BifType::Record::Log::Filter, false) ) { reporter->Error("filter argument not of right type"); return false; diff --git a/src/option.bif b/src/option.bif index fd118ca5cc..14c65c1d50 100644 --- a/src/option.bif +++ b/src/option.bif @@ -79,7 +79,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool return val_mgr->False(); } - if ( same_type(val->GetType().get(), bro_broker::DataVal::ScriptDataType()) ) + if ( same_type(val->GetType(), bro_broker::DataVal::ScriptDataType()) ) { auto dv = static_cast(val->AsRecordVal()->GetField(0).get()); auto val_from_data = dv->castTo(i->GetType().get()); @@ -95,7 +95,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool return val_mgr->Bool(rval); } - if ( ! same_type(i->GetType().get(), val->GetType().get()) ) + if ( ! same_type(i->GetType(), val->GetType()) ) { if ( i->GetType()->Tag() == TYPE_TABLE && val->GetType()->Tag() == TYPE_TABLE && @@ -185,7 +185,7 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( ! same_type(args[1].get(), i->GetType().get()) ) + if ( ! same_type(args[1], i->GetType()) ) { builtin_error(fmt("Second argument of passed function has to be %s in Option::on_change for ID '%s'; got '%s'", type_name(i->GetType()->Tag()), ID->CheckString(), type_name(args[1]->Tag()))); @@ -199,7 +199,7 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( ! same_type(on_change->GetType()->AsFuncType()->Yield().get(), i->GetType().get()) ) + if ( ! same_type(on_change->GetType()->AsFuncType()->Yield(), i->GetType()) ) { builtin_error(fmt("Passed function needs to return type '%s' for ID '%s'; got '%s'", type_name(i->GetType()->Tag()), ID->CheckString(), type_name(on_change->GetType()->AsFuncType()->Yield()->Tag()))); diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index a6942ddbca..f870619e87 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -86,7 +86,7 @@ void TopkVal::Merge(const TopkVal* value, bool doPrune) else { - if ( ! same_type(type.get(), value->type.get()) ) + if ( ! same_type(type, value->type) ) { reporter->Error("Cannot merge top-k elements of differing types."); return; @@ -278,7 +278,7 @@ void TopkVal::Encountered(IntrusivePtr encountered) if ( numElements == 0 ) Typify(encountered->GetType()); else - if ( ! same_type(type.get(), encountered->GetType().get()) ) + if ( ! same_type(type, encountered->GetType()) ) { reporter->Error("Trying to add element to topk with differing type from other elements"); return; diff --git a/src/probabilistic/bloom-filter.bif b/src/probabilistic/bloom-filter.bif index 21425cd10d..b8c4592c8d 100644 --- a/src/probabilistic/bloom-filter.bif +++ b/src/probabilistic/bloom-filter.bif @@ -149,7 +149,7 @@ function bloomfilter_add%(bf: opaque of bloomfilter, x: any%): any if ( ! bfv->Type() && ! bfv->Typify(x->GetType()) ) reporter->Error("failed to set Bloom filter type"); - else if ( ! same_type(bfv->Type().get(), x->GetType().get()) ) + else if ( ! same_type(bfv->Type(), x->GetType()) ) reporter->Error("incompatible Bloom filter types"); else @@ -176,7 +176,7 @@ function bloomfilter_lookup%(bf: opaque of bloomfilter, x: any%): count if ( ! bfv->Type() ) return val_mgr->Count(0); - else if ( ! same_type(bfv->Type().get(), x->GetType().get()) ) + else if ( ! same_type(bfv->Type(), x->GetType()) ) reporter->Error("incompatible Bloom filter types"); else @@ -227,7 +227,7 @@ function bloomfilter_merge%(bf1: opaque of bloomfilter, if ( bfv1->Type() && // any one 0 is ok here bfv2->Type() && - ! same_type(bfv1->Type().get(), bfv2->Type().get()) ) + ! same_type(bfv1->Type(), bfv2->Type()) ) { reporter->Error("incompatible Bloom filter types"); return nullptr; diff --git a/src/probabilistic/cardinality-counter.bif b/src/probabilistic/cardinality-counter.bif index 45e8ebbe59..370f842a38 100644 --- a/src/probabilistic/cardinality-counter.bif +++ b/src/probabilistic/cardinality-counter.bif @@ -48,7 +48,7 @@ function hll_cardinality_add%(handle: opaque of cardinality, elem: any%): bool return val_mgr->False(); } - else if ( ! same_type(cv->Type().get(), elem->GetType().get()) ) + else if ( ! same_type(cv->Type(), elem->GetType()) ) { reporter->Error("incompatible HLL data type"); return val_mgr->False(); @@ -79,7 +79,7 @@ function hll_cardinality_merge_into%(handle1: opaque of cardinality, handle2: op if ( (v1->Type() != v2->Type()) && // both 0 is ok (v1->Type() != nullptr) && // any one 0 also is ok (v2->Type() != nullptr) && - ! same_type(v1->Type().get(), v2->Type().get()) ) + ! same_type(v1->Type(), v2->Type()) ) { reporter->Error("incompatible HLL types"); return val_mgr->False(); diff --git a/src/threading/Manager.cc b/src/threading/Manager.cc index 2c1491de1a..b4025bc68d 100644 --- a/src/threading/Manager.cc +++ b/src/threading/Manager.cc @@ -166,7 +166,7 @@ bool Manager::SendEvent(MsgThread* thread, const std::string& name, const int nu Val* v = Value::ValueToVal(std::string("thread ") + thread->Name(), vals[j], convert_error); vl.emplace_back(AdoptRef{}, v); - if ( v && ! convert_error && ! same_type(type->GetFieldType(j).get(), v->GetType().get()) ) + if ( v && ! convert_error && ! same_type(type->GetFieldType(j), v->GetType()) ) { convert_error = true; type->GetFieldType(j)->Error("SendEvent types do not match", v->GetType().get()); From 457c08f53131c62787ffadb7a6cea724112e806b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 22:53:10 -0700 Subject: [PATCH 114/151] Add is_atomic_type() overloads for IntrusivePtr --- src/Stmt.cc | 4 ++-- src/Type.cc | 4 ++-- src/Type.h | 6 +++++- src/Val.cc | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Stmt.cc b/src/Stmt.cc index f2de940c12..fde3cdc5fa 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -606,10 +606,10 @@ SwitchStmt::SwitchStmt(IntrusivePtr index, case_list* arg_cases) { have_exprs = true; - if ( ! is_atomic_type(e->GetType().get()) ) + if ( ! is_atomic_type(e->GetType()) ) e->Error("switch expression must be of an atomic type when cases are expressions"); - if ( ! le->GetType()->AsTypeList()->AllMatch(e->GetType().get(), false) ) + if ( ! le->GetType()->AsTypeList()->AllMatch(e->GetType(), false) ) { le->Error("case expression type differs from switch type", e.get()); continue; diff --git a/src/Type.cc b/src/Type.cc index 3ab5bfee3e..158c8b0ccf 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -2082,9 +2082,9 @@ IntrusivePtr init_type(Expr* init) nullptr); } -bool is_atomic_type(const BroType* t) +bool is_atomic_type(const BroType& t) { - switch ( t->InternalType() ) { + switch ( t.InternalType() ) { case TYPE_INTERNAL_INT: case TYPE_INTERNAL_UNSIGNED: case TYPE_INTERNAL_DOUBLE: diff --git a/src/Type.h b/src/Type.h index efda5f6e17..92bd2c5ef2 100644 --- a/src/Type.h +++ b/src/Type.h @@ -860,7 +860,11 @@ IntrusivePtr merge_type_list(ListExpr* elements); IntrusivePtr init_type(Expr* init); // Returns true if argument is an atomic type. -bool is_atomic_type(const BroType* t); +bool is_atomic_type(const BroType& t); +inline bool is_atomic_type(const BroType* t) + { return is_atomic_type(*t); } +inline bool is_atomic_type(const IntrusivePtr& t) + { return is_atomic_type(*t); } // True if the given type tag corresponds to type that can be assigned to. extern bool is_assignable(BroType* t); diff --git a/src/Val.cc b/src/Val.cc index ce5f0d06bd..6251326ef9 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -3305,7 +3305,7 @@ bool same_val(const Val* /* v1 */, const Val* /* v2 */) bool is_atomic_val(const Val* v) { - return is_atomic_type(v->GetType().get()); + return is_atomic_type(v->GetType()); } bool same_atomic_val(const Val* v1, const Val* v2) From 863f02744e74e701c609e529e61a6385a41abfbd Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 23:00:02 -0700 Subject: [PATCH 115/151] Add is_assignable() overload taking TypeTag --- src/Expr.cc | 2 +- src/Type.cc | 4 ++-- src/Type.h | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index e652a3d09a..4aa6bd0f30 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -1984,7 +1984,7 @@ RefExpr::RefExpr(IntrusivePtr arg_op) if ( IsError() ) return; - if ( ! ::is_assignable(op->GetType().get()) ) + if ( ! ::is_assignable(op->GetType()->Tag()) ) ExprError("illegal assignment target"); else SetType(op->GetType()); diff --git a/src/Type.cc b/src/Type.cc index 158c8b0ccf..7260c4194c 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1644,9 +1644,9 @@ BroType* flatten_type(BroType* t) return (BroType*) flatten_type((const BroType*) t); } -bool is_assignable(BroType* t) +bool is_assignable(TypeTag t) { - switch ( t->Tag() ) { + switch ( t ) { case TYPE_BOOL: case TYPE_INT: case TYPE_COUNT: diff --git a/src/Type.h b/src/Type.h index 92bd2c5ef2..8e30e705cb 100644 --- a/src/Type.h +++ b/src/Type.h @@ -867,7 +867,9 @@ inline bool is_atomic_type(const IntrusivePtr& t) { return is_atomic_type(*t); } // True if the given type tag corresponds to type that can be assigned to. -extern bool is_assignable(BroType* t); +extern bool is_assignable(TypeTag t); +inline bool is_assignable(BroType* t) + { return ::is_assignable(t->Tag()); } // True if the given type tag corresponds to an integral type. inline bool IsIntegral(TypeTag t) { return (t == TYPE_INT || t == TYPE_COUNT || t == TYPE_COUNTER); } From a0481c0b2605e08076ad6f5d617688a6fe66781c Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 23:10:21 -0700 Subject: [PATCH 116/151] Deprecate TypeType::Type(), replace with GetType() --- src/Type.h | 6 ++++++ src/Val.cc | 6 +++--- src/input/Manager.cc | 6 +++--- src/logging/Manager.cc | 2 +- src/parse.y | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Type.h b/src/Type.h index 8e30e705cb..b0b114401a 100644 --- a/src/Type.h +++ b/src/Type.h @@ -547,7 +547,13 @@ public: const IntrusivePtr& GetType() const { return type; } + template + IntrusivePtr GetType() const + { return cast_intrusive(type); } + + [[deprecated("Remove in v4.1. Use GetType().")]] BroType* Type() { return type.get(); } + [[deprecated("Remove in v4.1. Use GetType().")]] const BroType* Type() const { return type.get(); } protected: diff --git a/src/Val.cc b/src/Val.cc index 6251326ef9..9dfa57235c 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -347,7 +347,7 @@ void Val::ValDescribe(ODesc* d) const else if ( type->Tag() == TYPE_FILE ) AsFile()->Describe(d); else if ( type->Tag() == TYPE_TYPE ) - d->Add(type->AsTypeType()->Type()->GetName()); + d->Add(type->AsTypeType()->GetType()->GetName()); else d->Add(""); break; @@ -440,7 +440,7 @@ IntrusivePtr Val::GetRecordFields() } else { - t = t->AsTypeType()->Type(); + t = t->AsTypeType()->GetType().get(); if ( t->Tag() != TYPE_RECORD ) { @@ -1375,7 +1375,7 @@ static void find_nested_record_types(BroType* t, std::set* found) find_nested_record_types(t->AsVectorType()->Yield().get(), found); return; case TYPE_TYPE: - find_nested_record_types(t->AsTypeType()->Type(), found); + find_nested_record_types(t->AsTypeType()->GetType().get(), found); return; default: return; diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 06931636c8..d24dd960b3 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -314,7 +314,7 @@ bool Manager::CreateEventStream(RecordVal* fval) string stream_name = fval->GetFieldOrDefault("name")->AsString()->CheckString(); auto fields_val = fval->GetFieldOrDefault("fields"); - RecordType* fields = fields_val->AsType()->AsTypeType()->Type()->AsRecordType(); + RecordType* fields = fields_val->AsType()->AsTypeType()->GetType()->AsRecordType(); auto want_record = fval->GetFieldOrDefault("want_record"); @@ -469,13 +469,13 @@ bool Manager::CreateTableStream(RecordVal* fval) auto pred = fval->GetFieldOrDefault("pred"); auto idx_val = fval->GetFieldOrDefault("idx"); - RecordType* idx = idx_val->AsType()->AsTypeType()->Type()->AsRecordType(); + RecordType* idx = idx_val->AsType()->AsTypeType()->GetType()->AsRecordType(); IntrusivePtr val; auto val_val = fval->GetFieldOrDefault("val"); if ( val_val ) - val = {NewRef{}, val_val->AsType()->AsTypeType()->Type()->AsRecordType()}; + val = val_val->AsType()->AsTypeType()->GetType(); auto dst = fval->GetFieldOrDefault("destination"); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index fa86027ed2..e585aea078 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -236,7 +236,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) } RecordType* columns = sval->GetField("columns") - ->AsType()->AsTypeType()->Type()->AsRecordType(); + ->AsType()->AsTypeType()->GetType()->AsRecordType(); bool log_attr_present = false; diff --git a/src/parse.y b/src/parse.y index fc00faa925..6930c7e5e9 100644 --- a/src/parse.y +++ b/src/parse.y @@ -237,7 +237,7 @@ static bool expr_is_table_type_name(const Expr* expr) return true; if ( type->Tag() == TYPE_TYPE ) - return type->AsTypeType()->Type()->IsTable(); + return type->AsTypeType()->GetType()->IsTable(); return false; } From 0a23b8dff53ad6d371a75bf0868f55e51b533cfd Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 23:21:37 -0700 Subject: [PATCH 117/151] Change find_nested_record_types() to take IntrusivePtr --- src/Val.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index 9dfa57235c..858ee40cdc 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1342,7 +1342,7 @@ static void table_entry_val_delete_func(void* val) delete tv; } -static void find_nested_record_types(BroType* t, std::set* found) +static void find_nested_record_types(const IntrusivePtr& t, std::set* found) { if ( ! t ) return; @@ -1354,28 +1354,28 @@ static void find_nested_record_types(BroType* t, std::set* found) found->emplace(rt); for ( auto i = 0; i < rt->NumFields(); ++i ) - find_nested_record_types(rt->FieldDecl(i)->type.get(), found); + find_nested_record_types(rt->FieldDecl(i)->type, found); } return; case TYPE_TABLE: - find_nested_record_types(t->AsTableType()->GetIndices().get(), found); - find_nested_record_types(t->AsTableType()->Yield().get(), found); + find_nested_record_types(t->AsTableType()->GetIndices(), found); + find_nested_record_types(t->AsTableType()->Yield(), found); return; case TYPE_LIST: { for ( const auto& type : t->AsTypeList()->Types() ) - find_nested_record_types(type.get(), found); + find_nested_record_types(type, found); } return; case TYPE_FUNC: - find_nested_record_types(t->AsFuncType()->Params().get(), found); - find_nested_record_types(t->AsFuncType()->Yield().get(), found); + find_nested_record_types(t->AsFuncType()->Params(), found); + find_nested_record_types(t->AsFuncType()->Yield(), found); return; case TYPE_VECTOR: - find_nested_record_types(t->AsVectorType()->Yield().get(), found); + find_nested_record_types(t->AsVectorType()->Yield(), found); return; case TYPE_TYPE: - find_nested_record_types(t->AsTypeType()->GetType().get(), found); + find_nested_record_types(t->AsTypeType()->GetType(), found); return; default: return; @@ -1395,7 +1395,7 @@ TableVal::TableVal(IntrusivePtr t, IntrusivePtr a) : Val( std::set found; // TODO: this likely doesn't have to be repeated for each new TableVal, // can remember the resulting dependencies per TableType - find_nested_record_types(t.get(), &found); + find_nested_record_types(t, &found); for ( auto rt : found ) parse_time_table_record_dependencies[rt].emplace_back(NewRef{}, this); From 052104d5d2e2e27e137b92e016e9427fa9f361a9 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 21 May 2020 23:31:01 -0700 Subject: [PATCH 118/151] Change bro_broker::DataVal::ScriptDataType() to IntrusivePtr --- src/broker/Data.cc | 8 ++------ src/broker/Data.h | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 42fe19d41d..f317576eb8 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -23,8 +23,6 @@ IntrusivePtr bro_broker::opaque_of_table_iterator; IntrusivePtr bro_broker::opaque_of_vector_iterator; IntrusivePtr bro_broker::opaque_of_record_iterator; -BroType* bro_broker::DataVal::script_data_type = nullptr; - static bool data_type_check(const broker::data& d, BroType* t); static broker::port::protocol to_broker_port_proto(TransportProto tp) @@ -1152,11 +1150,9 @@ IntrusivePtr bro_broker::DataVal::castTo(BroType* t) return data_to_val(data, t); } -BroType* bro_broker::DataVal::ScriptDataType() +const IntrusivePtr& bro_broker::DataVal::ScriptDataType() { - if ( ! script_data_type ) - script_data_type = zeek::id::find_type("Broker::Data").get(); - + static auto script_data_type = zeek::id::find_type("Broker::Data"); return script_data_type; } diff --git a/src/broker/Data.h b/src/broker/Data.h index fbafa49077..d6578ceb99 100644 --- a/src/broker/Data.h +++ b/src/broker/Data.h @@ -110,7 +110,7 @@ public: // Returns the Bro type that scripts use to represent a Broker data // instance. This may be wrapping the opaque value inside another // type. - static BroType* ScriptDataType(); + static const IntrusivePtr& ScriptDataType(); broker::data data; @@ -120,8 +120,6 @@ protected: {} DECLARE_OPAQUE_VALUE(bro_broker::DataVal) - - static BroType* script_data_type; }; /** From 8a3cd4c65b98e5f4a4f95e6dd406381b08decfdd Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 22 May 2020 00:09:14 -0700 Subject: [PATCH 119/151] Fix build: some don't like IntrusivePtr default arg w/ incomplete type --- src/IP.cc | 3 +++ src/IP.h | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/IP.cc b/src/IP.cc index 647461d526..28109b185a 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -298,6 +298,9 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const return rv; } +IntrusivePtr IPv6_Hdr::ToVal() const + { return ToVal(nullptr); } + RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const { return ToVal({AdoptRef{}, chain}).release(); diff --git a/src/IP.h b/src/IP.h index 2959a6dd1a..3bb1a6c897 100644 --- a/src/IP.h +++ b/src/IP.h @@ -136,7 +136,8 @@ public: /** * Returns the script-layer record representation of the header. */ - IntrusivePtr ToVal(IntrusivePtr chain = nullptr) const; + IntrusivePtr ToVal(IntrusivePtr chain) const; + IntrusivePtr ToVal() const; [[deprecated("Remove in v4.1. Use ToVal() instead.")]] RecordVal* BuildRecordVal(VectorVal* chain = nullptr) const; From 27c3c207e4d420b4b574a66c9ae35a165bcf3493 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 22 May 2020 00:22:17 -0700 Subject: [PATCH 120/151] Change file_analysis::File::GetID() to return const-ref --- src/file_analysis/File.h | 2 +- src/file_analysis/Manager.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/file_analysis/File.h b/src/file_analysis/File.h index f4278500a5..5b43549aff 100644 --- a/src/file_analysis/File.h +++ b/src/file_analysis/File.h @@ -74,7 +74,7 @@ public: /** * @return value of the "id" field from #val record. */ - std::string GetID() const { return id; } + const std::string& GetID() const { return id; } /** * @return value of "last_active" field in #val record; diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index cfc61d33ae..3c09498a4b 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -396,10 +396,10 @@ bool Manager::RemoveFile(const string& file_id) DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Remove file", file_id.c_str()); f->EndOfFile(); - delete f; id_map.erase(file_id); ignored.erase(file_id); + delete f; return true; } From faa47388077f406e63bdd3f7a68c8790d0d90458 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 22 May 2020 12:27:37 -0700 Subject: [PATCH 121/151] Deprecate file_analysis::File::GetVal(), replace with ToVal() --- src/Reporter.cc | 2 +- src/file_analysis/File.cc | 21 ++++++----------- src/file_analysis/File.h | 9 ++++++-- .../analyzer/data_event/DataEvent.cc | 4 ++-- src/file_analysis/analyzer/entropy/Entropy.cc | 2 +- src/file_analysis/analyzer/extract/Extract.cc | 2 +- src/file_analysis/analyzer/hash/Hash.cc | 2 +- src/file_analysis/analyzer/pe/pe-analyzer.pac | 10 ++++---- .../analyzer/unified2/unified2-analyzer.pac | 6 ++--- src/file_analysis/analyzer/x509/OCSP.cc | 23 ++++++------------- src/file_analysis/analyzer/x509/X509.cc | 10 ++++---- src/file_analysis/analyzer/x509/X509Common.cc | 5 ++-- .../analyzer/x509/x509-extension.pac | 2 +- src/file_analysis/file_analysis.bif | 6 ++--- 14 files changed, 45 insertions(+), 59 deletions(-) diff --git a/src/Reporter.cc b/src/Reporter.cc index 5cd6161c8c..ddbe58aaa0 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -349,7 +349,7 @@ void Reporter::Weird(file_analysis::File* f, const char* name, const char* addl) return; } - WeirdHelper(file_weird, {f->GetVal()->Ref(), new StringVal(addl)}, + WeirdHelper(file_weird, {f->ToVal()->Ref(), new StringVal(addl)}, "%s", name); } diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 2c8167aaec..52a1b20a1f 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -91,7 +91,7 @@ File::File(const std::string& file_id, const std::string& source_name, Connectio DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Creating new File object", file_id.c_str()); - val = new RecordVal(zeek::id::fa_file); + val = make_intrusive(zeek::id::fa_file); val->Assign(id_idx, make_intrusive(file_id.c_str())); SetSource(source_name); @@ -107,7 +107,6 @@ File::File(const std::string& file_id, const std::string& source_name, Connectio File::~File() { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Destroying File object", id.c_str()); - Unref(val); delete file_reassembler; for ( auto a : done_analyzers ) @@ -152,7 +151,7 @@ void File::RaiseFileOverNewConnection(Connection* conn, bool is_orig) if ( conn && FileEventAvailable(file_over_new_connection) ) { FileEvent(file_over_new_connection, { - IntrusivePtr{NewRef{}, val}, + val, conn->ConnVal(), val_mgr->Bool(is_orig), }); @@ -301,7 +300,7 @@ bool File::SetMime(const std::string& mime_type) meta->Assign(meta_mime_type_idx, make_intrusive(mime_type)); meta->Assign(meta_inferred_idx, val_mgr->False()); - FileEvent(file_sniff, {IntrusivePtr{NewRef{}, val}, std::move(meta)}); + FileEvent(file_sniff, {val, std::move(meta)}); return true; } @@ -340,7 +339,7 @@ void File::InferMetadata() file_analysis::GenMIMEMatchesVal(matches)); } - FileEvent(file_sniff, {IntrusivePtr{NewRef{}, val}, std::move(meta)}); + FileEvent(file_sniff, {val, std::move(meta)}); } bool File::BufferBOF(const u_char* data, uint64_t len) @@ -452,7 +451,7 @@ void File::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset) if ( FileEventAvailable(file_reassembly_overflow) ) { FileEvent(file_reassembly_overflow, { - IntrusivePtr{NewRef{}, val}, + val, val_mgr->Count(current_offset), val_mgr->Count(gap_bytes) }); @@ -595,13 +594,7 @@ void File::Gap(uint64_t offset, uint64_t len) } if ( FileEventAvailable(file_gap) ) - { - FileEvent(file_gap, { - IntrusivePtr{NewRef{}, val}, - val_mgr->Count(offset), - val_mgr->Count(len) - }); - } + FileEvent(file_gap, {val, val_mgr->Count(offset), val_mgr->Count(len)}); analyzers.DrainModifications(); @@ -619,7 +612,7 @@ void File::FileEvent(EventHandlerPtr h) if ( ! FileEventAvailable(h) ) return; - FileEvent(h, zeek::Args{{NewRef{}, val}}); + FileEvent(h, zeek::Args{val}); } void File::FileEvent(EventHandlerPtr h, val_list* vl) diff --git a/src/file_analysis/File.h b/src/file_analysis/File.h index 5b43549aff..d201c416af 100644 --- a/src/file_analysis/File.h +++ b/src/file_analysis/File.h @@ -38,7 +38,12 @@ public: /** * @return the wrapped \c fa_file record value, #val. */ - RecordVal* GetVal() const { return val; } + const IntrusivePtr& ToVal() const + { return val; } + + [[deprecated("Remove in v4.1. Use ToVal().")]] + RecordVal* GetVal() const + { return val.get(); } /** * @return the value of the "source" field from #val record or an empty @@ -333,7 +338,7 @@ protected: protected: std::string id; /**< A pretty hash that likely identifies file */ - RecordVal* val; /**< \c fa_file from script layer. */ + IntrusivePtr val; /**< \c fa_file from script layer. */ FileReassembler* file_reassembler; /**< A reassembler for the file if it's needed. */ uint64_t stream_offset; /**< The offset of the file which has been forwarded. */ uint64_t reassembly_max_buffer; /**< Maximum allowed buffer for reassembly. */ diff --git a/src/file_analysis/analyzer/data_event/DataEvent.cc b/src/file_analysis/analyzer/data_event/DataEvent.cc index 082618c4ec..619605b34a 100644 --- a/src/file_analysis/analyzer/data_event/DataEvent.cc +++ b/src/file_analysis/analyzer/data_event/DataEvent.cc @@ -43,7 +43,7 @@ bool DataEvent::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset) if ( ! chunk_event ) return true; mgr.Enqueue(chunk_event, - IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + GetFile()->ToVal(), make_intrusive(new BroString(data, len, false)), val_mgr->Count(offset) ); @@ -56,7 +56,7 @@ bool DataEvent::DeliverStream(const u_char* data, uint64_t len) if ( ! stream_event ) return true; mgr.Enqueue(stream_event, - IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + GetFile()->ToVal(), make_intrusive(new BroString(data, len, false)) ); diff --git a/src/file_analysis/analyzer/entropy/Entropy.cc b/src/file_analysis/analyzer/entropy/Entropy.cc index 7eb2dc17ec..401a9020d6 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.cc +++ b/src/file_analysis/analyzer/entropy/Entropy.cc @@ -69,7 +69,7 @@ void Entropy::Finalize() ent_result->Assign(4, make_intrusive(scc, TYPE_DOUBLE)); mgr.Enqueue(file_entropy, - IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + GetFile()->ToVal(), std::move(ent_result) ); } diff --git a/src/file_analysis/analyzer/extract/Extract.cc b/src/file_analysis/analyzer/extract/Extract.cc index 68daecab1f..3b4c9ed8b0 100644 --- a/src/file_analysis/analyzer/extract/Extract.cc +++ b/src/file_analysis/analyzer/extract/Extract.cc @@ -92,7 +92,7 @@ bool Extract::DeliverStream(const u_char* data, uint64_t len) { File* f = GetFile(); f->FileEvent(file_extraction_limit, { - IntrusivePtr{NewRef{}, f->GetVal()}, + f->ToVal(), IntrusivePtr{NewRef{}, Args()}, val_mgr->Count(limit), val_mgr->Count(len) diff --git a/src/file_analysis/analyzer/hash/Hash.cc b/src/file_analysis/analyzer/hash/Hash.cc index a4b0a8930d..99187d243d 100644 --- a/src/file_analysis/analyzer/hash/Hash.cc +++ b/src/file_analysis/analyzer/hash/Hash.cc @@ -52,7 +52,7 @@ void Hash::Finalize() return; mgr.Enqueue(file_hash, - IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + GetFile()->ToVal(), make_intrusive(kind), hash->Get() ); diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index a620d1403c..e9da2468d3 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -66,7 +66,7 @@ refine flow File += { dh->Assign(16, val_mgr->Count(${h.AddressOfNewExeHeader})); mgr.Enqueue(pe_dos_header, - IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()}, + connection()->bro_analyzer()->GetFile()->ToVal(), std::move(dh)); } return true; @@ -76,7 +76,7 @@ refine flow File += { %{ if ( pe_dos_code ) mgr.Enqueue(pe_dos_code, - IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()}, + connection()->bro_analyzer()->GetFile()->ToVal(), make_intrusive(code.length(), (const char*) code.data()) ); return true; @@ -105,7 +105,7 @@ refine flow File += { fh->Assign(5, characteristics_to_bro(${h.Characteristics}, 16)); mgr.Enqueue(pe_file_header, - IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()}, + connection()->bro_analyzer()->GetFile()->ToVal(), std::move(fh)); } @@ -156,7 +156,7 @@ refine flow File += { oh->Assign(23, process_rvas(${h.rvas})); mgr.Enqueue(pe_optional_header, - IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()}, + connection()->bro_analyzer()->GetFile()->ToVal(), std::move(oh)); } return true; @@ -188,7 +188,7 @@ refine flow File += { section_header->Assign(9, characteristics_to_bro(${h.characteristics}, 32)); mgr.Enqueue(pe_section_header, - IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()}, + connection()->bro_analyzer()->GetFile()->ToVal(), std::move(section_header) ); } diff --git a/src/file_analysis/analyzer/unified2/unified2-analyzer.pac b/src/file_analysis/analyzer/unified2/unified2-analyzer.pac index f395e919d9..78d32bbac2 100644 --- a/src/file_analysis/analyzer/unified2/unified2-analyzer.pac +++ b/src/file_analysis/analyzer/unified2/unified2-analyzer.pac @@ -87,7 +87,7 @@ refine flow Flow += { ids_event->Assign(17, val_mgr->Count(${ev.packet_action})); mgr.Enqueue(::unified2_event, - IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()}, + connection()->bro_analyzer()->GetFile()->ToVal(), std::move(ids_event)); } return true; @@ -117,7 +117,7 @@ refine flow Flow += { ids_event->Assign(16, val_mgr->Count(${ev.vlan_id})); mgr.Enqueue(::unified2_event, - IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()}, + connection()->bro_analyzer()->GetFile()->ToVal(), std::move(ids_event)); } @@ -137,7 +137,7 @@ refine flow Flow += { packet->Assign(5, to_stringval(${pkt.packet_data})); mgr.Enqueue(::unified2_packet, - IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()}, + connection()->bro_analyzer()->GetFile()->ToVal(), std::move(packet)); } diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index f2dd74883b..91c1535ec6 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -412,7 +412,7 @@ void file_analysis::OCSP::ParseRequest(OCSP_REQUEST* req) if ( ocsp_request ) mgr.Enqueue(ocsp_request, - IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + GetFile()->ToVal(), val_mgr->Count(version) ); @@ -423,7 +423,7 @@ void file_analysis::OCSP::ParseRequest(OCSP_REQUEST* req) { zeek::Args rvl; rvl.reserve(5); - rvl.emplace_back(NewRef{}, GetFile()->GetVal()); + rvl.emplace_back(GetFile()->ToVal()); OCSP_ONEREQ *one_req = OCSP_request_onereq_get0(req, i); OCSP_CERTID *cert_id = OCSP_onereq_get0_id(one_req); @@ -454,13 +454,10 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp) memset(buf, 0, sizeof(buf)); const char *status_str = OCSP_response_status_str(OCSP_response_status(resp)); - StringVal* status_val = new StringVal(strlen(status_str), status_str); + auto status_val = make_intrusive(strlen(status_str), status_str); if ( ocsp_response_status ) - mgr.Enqueue(ocsp_response_status, - IntrusivePtr{NewRef{}, GetFile()->GetVal()}, - IntrusivePtr{NewRef{}, status_val} - ); + mgr.Enqueue(ocsp_response_status, GetFile()->ToVal(), status_val); //if (!resp_bytes) // { @@ -479,22 +476,16 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp) // 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.emplace_back(NewRef{}, GetFile()->GetVal()); - vl.emplace_back(AdoptRef{}, status_val); + vl.emplace_back(GetFile()->ToVal()); + vl.emplace_back(std::move(status_val)); #if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER) vl.emplace_back(val_mgr->Count((uint64_t)ASN1_INTEGER_get(resp_data->version))); @@ -537,7 +528,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp) zeek::Args rvl; rvl.reserve(10); - rvl.emplace_back(NewRef{}, GetFile()->GetVal()); + rvl.emplace_back(GetFile()->ToVal()); // cert id const OCSP_CERTID* cert_id = nullptr; diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index b3bd999dd9..58946c7618 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -61,8 +61,8 @@ bool file_analysis::X509::EndOfFile() return false; // yup, let's call the callback. - cache_hit_callback->operator()(IntrusivePtr{NewRef{}, GetFile()->GetVal()}, - entry, make_intrusive(cert_sha256)); + cache_hit_callback->operator()(GetFile()->ToVal(), entry, + make_intrusive(cert_sha256)); return false; } } @@ -84,7 +84,7 @@ bool file_analysis::X509::EndOfFile() // and send the record on to scriptland if ( x509_certificate ) mgr.Enqueue(x509_certificate, - IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + GetFile()->ToVal(), IntrusivePtr{NewRef{}, cert_val}, cert_record); @@ -294,7 +294,7 @@ void file_analysis::X509::ParseBasicConstraints(X509_EXTENSION* ex) pBasicConstraint->Assign(1, val_mgr->Count((int32_t) ASN1_INTEGER_get(constr->pathlen))); mgr.Enqueue(x509_ext_basic_constraints, - IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + GetFile()->ToVal(), std::move(pBasicConstraint) ); } @@ -435,7 +435,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) sanExt->Assign(4, val_mgr->Bool(otherfields)); mgr.Enqueue(x509_ext_subject_alternative_name, - IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + GetFile()->ToVal(), std::move(sanExt)); GENERAL_NAMES_free(altname); } diff --git a/src/file_analysis/analyzer/x509/X509Common.cc b/src/file_analysis/analyzer/x509/X509Common.cc index 19680f6404..723786f42c 100644 --- a/src/file_analysis/analyzer/x509/X509Common.cc +++ b/src/file_analysis/analyzer/x509/X509Common.cc @@ -287,12 +287,11 @@ void file_analysis::X509Common::ParseExtension(X509_EXTENSION* ex, const EventHa // but I am not sure if there is a better way to do it... if ( h == ocsp_extension ) - mgr.Enqueue(h, IntrusivePtr{NewRef{}, GetFile()->GetVal()}, + mgr.Enqueue(h, GetFile()->ToVal(), std::move(pX509Ext), val_mgr->Bool(global)); else - mgr.Enqueue(h, IntrusivePtr{NewRef{}, GetFile()->GetVal()}, - std::move(pX509Ext)); + mgr.Enqueue(h, GetFile()->ToVal(), std::move(pX509Ext)); // let individual analyzers parse more. ParseExtensionsSpecific(ex, global, ext_asn, oid); diff --git a/src/file_analysis/analyzer/x509/x509-extension.pac b/src/file_analysis/analyzer/x509/x509-extension.pac index ad922a5862..9aaf095b71 100644 --- a/src/file_analysis/analyzer/x509/x509-extension.pac +++ b/src/file_analysis/analyzer/x509/x509-extension.pac @@ -39,7 +39,7 @@ refine connection MockConnection += { return true; mgr.Enqueue(x509_ocsp_ext_signed_certificate_timestamp, - IntrusivePtr{NewRef{}, bro_analyzer()->GetFile()->GetVal()}, + bro_analyzer()->GetFile()->ToVal(), val_mgr->Count(version), make_intrusive(logid.length(), reinterpret_cast(logid.begin())), val_mgr->Count(timestamp), diff --git a/src/file_analysis/file_analysis.bif b/src/file_analysis/file_analysis.bif index 1f74668dd4..909e9ed20f 100644 --- a/src/file_analysis/file_analysis.bif +++ b/src/file_analysis/file_analysis.bif @@ -86,10 +86,8 @@ function Files::__lookup_file%(fuid: string%): fa_file %{ auto f = file_mgr->LookupFile(fuid->CheckString()); if ( f != nullptr ) - { - return IntrusivePtr{NewRef{}, f->GetVal()}; - } - + return f->ToVal(); + reporter->Error("file ID %s not a known file", fuid->CheckString()); return nullptr; %} From ecb7c7c27ed92e4538b95a93e2553f5e6bd7f5b1 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 22 May 2020 12:34:40 -0700 Subject: [PATCH 122/151] Deprecate file_analysis::Analyzer::Args(), replace with GetArgs() --- src/file_analysis/Analyzer.cc | 3 +-- src/file_analysis/Analyzer.h | 9 +++++++-- src/file_analysis/File.cc | 10 +++++----- src/file_analysis/analyzer/extract/Extract.cc | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/file_analysis/Analyzer.cc b/src/file_analysis/Analyzer.cc index 963c4a693d..6ede6a969b 100644 --- a/src/file_analysis/Analyzer.cc +++ b/src/file_analysis/Analyzer.cc @@ -10,7 +10,6 @@ file_analysis::Analyzer::~Analyzer() { DBG_LOG(DBG_FILE_ANALYSIS, "Destroy file analyzer %s", file_mgr->GetComponentName(tag).c_str()); - Unref(args); } void file_analysis::Analyzer::SetAnalyzerTag(const file_analysis::Tag& arg_tag) @@ -21,7 +20,7 @@ void file_analysis::Analyzer::SetAnalyzerTag(const file_analysis::Tag& arg_tag) file_analysis::Analyzer::Analyzer(file_analysis::Tag arg_tag, RecordVal* arg_args, File* arg_file) : tag(arg_tag), - args(arg_args->Ref()->AsRecordVal()), + args({NewRef{}, arg_args}), file(arg_file), got_stream_delivery(false), skip(false) diff --git a/src/file_analysis/Analyzer.h b/src/file_analysis/Analyzer.h index 029a4df082..2426a7f7a1 100644 --- a/src/file_analysis/Analyzer.h +++ b/src/file_analysis/Analyzer.h @@ -95,7 +95,12 @@ public: /** * @return the AnalyzerArgs associated with the analyzer. */ - RecordVal* Args() const { return args; } + const IntrusivePtr& GetArgs() const + { return args; } + + [[deprecated("Remove in v4.1. Use GetArgs().")]] + RecordVal* Args() const + { return args.get(); } /** * @return the file_analysis::File object to which the analyzer is attached. @@ -166,7 +171,7 @@ private: ID id; /**< Unique instance ID. */ file_analysis::Tag tag; /**< The particular type of the analyzer instance. */ - RecordVal* args; /**< \c AnalyzerArgs val gives tunable analyzer params. */ + IntrusivePtr args; /**< \c AnalyzerArgs val gives tunable analyzer params. */ File* file; /**< The file to which the analyzer is attached. */ bool got_stream_delivery; bool skip; diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 52a1b20a1f..fabe76c98d 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -410,7 +410,7 @@ void File::DeliverStream(const u_char* data, uint64_t len) bof_buffer.chunks[i]->Len()) ) { a->SetSkip(true); - analyzers.QueueRemove(a->Tag(), a->Args()); + analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); } } @@ -427,7 +427,7 @@ void File::DeliverStream(const u_char* data, uint64_t len) if ( ! a->DeliverStream(data, len) ) { a->SetSkip(true); - analyzers.QueueRemove(a->Tag(), a->Args()); + analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); } } } @@ -498,7 +498,7 @@ void File::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset) if ( ! a->DeliverChunk(data, len, offset) ) { a->SetSkip(true); - analyzers.QueueRemove(a->Tag(), a->Args()); + analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); } } } @@ -557,7 +557,7 @@ void File::EndOfFile() while ( (a = analyzers.NextEntry(c)) ) { if ( ! a->EndOfFile() ) - analyzers.QueueRemove(a->Tag(), a->Args()); + analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); } FileEvent(file_state_remove); @@ -590,7 +590,7 @@ void File::Gap(uint64_t offset, uint64_t len) while ( (a = analyzers.NextEntry(c)) ) { if ( ! a->Undelivered(offset, len) ) - analyzers.QueueRemove(a->Tag(), a->Args()); + analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); } if ( FileEventAvailable(file_gap) ) diff --git a/src/file_analysis/analyzer/extract/Extract.cc b/src/file_analysis/analyzer/extract/Extract.cc index 3b4c9ed8b0..2ba8e7926d 100644 --- a/src/file_analysis/analyzer/extract/Extract.cc +++ b/src/file_analysis/analyzer/extract/Extract.cc @@ -93,7 +93,7 @@ bool Extract::DeliverStream(const u_char* data, uint64_t len) File* f = GetFile(); f->FileEvent(file_extraction_limit, { f->ToVal(), - IntrusivePtr{NewRef{}, Args()}, + GetArgs(), val_mgr->Count(limit), val_mgr->Count(len) }); From 57a6069cd1c2861b687e75aacf16e79bc99f6511 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 22 May 2020 16:13:15 -0700 Subject: [PATCH 123/151] Deprecate file analyzer construction methods taking raw RecordVal* Replaced with versions that instead take IntrusivePtr --- NEWS | 4 +++ src/file_analysis/Analyzer.cc | 20 +++++++++++-- src/file_analysis/Analyzer.h | 12 +++++--- src/file_analysis/AnalyzerSet.cc | 2 +- src/file_analysis/Component.cc | 9 ++++++ src/file_analysis/Component.h | 14 ++++++++- src/file_analysis/Manager.cc | 23 ++++++++++----- src/file_analysis/Manager.h | 4 +++ .../analyzer/data_event/DataEvent.cc | 9 +++--- .../analyzer/data_event/DataEvent.h | 5 ++-- src/file_analysis/analyzer/entropy/Entropy.cc | 10 ++++--- src/file_analysis/analyzer/entropy/Entropy.h | 5 ++-- src/file_analysis/analyzer/extract/Extract.cc | 14 +++++---- src/file_analysis/analyzer/extract/Extract.h | 7 +++-- src/file_analysis/analyzer/hash/Hash.cc | 6 ++-- src/file_analysis/analyzer/hash/Hash.h | 29 ++++++++++--------- src/file_analysis/analyzer/pe/PE.cc | 5 ++-- src/file_analysis/analyzer/pe/PE.h | 7 +++-- .../analyzer/unified2/Unified2.cc | 8 ++--- .../analyzer/unified2/Unified2.h | 5 ++-- src/file_analysis/analyzer/x509/OCSP.cc | 17 +++++++---- src/file_analysis/analyzer/x509/OCSP.h | 8 +++-- src/file_analysis/analyzer/x509/X509.cc | 5 ++-- src/file_analysis/analyzer/x509/X509.h | 7 +++-- src/file_analysis/analyzer/x509/X509Common.cc | 5 ++-- src/file_analysis/analyzer/x509/X509Common.h | 3 +- 26 files changed, 164 insertions(+), 79 deletions(-) diff --git a/NEWS b/NEWS index bda8f5718e..bb8e6e3ebf 100644 --- a/NEWS +++ b/NEWS @@ -218,6 +218,10 @@ Deprecated Functionality - ``VectorVal::Lookup()`` is deprecated, use ``VectorVal::At()``. +- The file analysis/analyzer API has deprecated methods taking raw + ``RecordVal*`` for analyzer arguments and replaced those with methods + taking ``IntrusivePtr``. + Zeek 3.1.0 ========== diff --git a/src/file_analysis/Analyzer.cc b/src/file_analysis/Analyzer.cc index 6ede6a969b..27066ba826 100644 --- a/src/file_analysis/Analyzer.cc +++ b/src/file_analysis/Analyzer.cc @@ -18,12 +18,28 @@ void file_analysis::Analyzer::SetAnalyzerTag(const file_analysis::Tag& arg_tag) tag = arg_tag; } -file_analysis::Analyzer::Analyzer(file_analysis::Tag arg_tag, RecordVal* arg_args, File* arg_file) +file_analysis::Analyzer::Analyzer(file_analysis::Tag arg_tag, + IntrusivePtr arg_args, + File* arg_file) : tag(arg_tag), - args({NewRef{}, arg_args}), + args(std::move(arg_args)), file(arg_file), got_stream_delivery(false), skip(false) { id = ++id_counter; } + +file_analysis::Analyzer::Analyzer(IntrusivePtr arg_args, File* arg_file) + : Analyzer({}, std::move(arg_args), arg_file) + {} + +file_analysis::Analyzer::Analyzer(file_analysis::Tag arg_tag, + RecordVal* arg_args, + File* arg_file) + : Analyzer(arg_tag, {NewRef{}, arg_args}, arg_file) + {} + +file_analysis::Analyzer::Analyzer(RecordVal* arg_args, File* arg_file) + : Analyzer({}, {NewRef{}, arg_args}, arg_file) + {} diff --git a/src/file_analysis/Analyzer.h b/src/file_analysis/Analyzer.h index 2426a7f7a1..fe0b2bf521 100644 --- a/src/file_analysis/Analyzer.h +++ b/src/file_analysis/Analyzer.h @@ -151,6 +151,10 @@ protected: * tunable options, if any, related to a particular analyzer type. * @param arg_file the file to which the the analyzer is being attached. */ + Analyzer(file_analysis::Tag arg_tag, IntrusivePtr arg_args, + File* arg_file); + + [[deprecated("Remove in v4.1.. Construct using IntrusivePtr instead.")]] Analyzer(file_analysis::Tag arg_tag, RecordVal* arg_args, File* arg_file); /** @@ -162,10 +166,10 @@ protected: * tunable options, if any, related to a particular analyzer type. * @param arg_file the file to which the the analyzer is being attached. */ - Analyzer(RecordVal* arg_args, File* arg_file) - : Analyzer({}, arg_args, arg_file) - { - } + Analyzer(IntrusivePtr arg_args, File* arg_file); + + [[deprecated("Remove in v4.1.. Construct using IntrusivePtr instead.")]] + Analyzer(RecordVal* arg_args, File* arg_file); private: diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index d196a2515e..a5abef9437 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -177,7 +177,7 @@ HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(const Tag& tag, RecordVal* args) const { - file_analysis::Analyzer* a = file_mgr->InstantiateAnalyzer(tag, args, file); + auto a = file_mgr->InstantiateAnalyzer(tag, {NewRef{}, args}, file); if ( ! a ) { diff --git a/src/file_analysis/Component.cc b/src/file_analysis/Component.cc index 3ed707313e..b2a55ce53d 100644 --- a/src/file_analysis/Component.cc +++ b/src/file_analysis/Component.cc @@ -13,6 +13,15 @@ Component::Component(const std::string& name, factory_callback arg_factory, Tag: plugin::TaggedComponent(subtype) { factory = arg_factory; + factory_func = nullptr; + } + +Component::Component(const std::string& name, factory_function arg_factory, Tag::subtype_t subtype) + : plugin::Component(plugin::component::FILE_ANALYZER, name), + plugin::TaggedComponent(subtype) + { + factory = nullptr; + factory_func = arg_factory; } void Component::Initialize() diff --git a/src/file_analysis/Component.h b/src/file_analysis/Component.h index e63a4db248..1bf5efe7ff 100644 --- a/src/file_analysis/Component.h +++ b/src/file_analysis/Component.h @@ -14,6 +14,7 @@ namespace file_analysis { class File; class Analyzer; +class Manager; /** * Component description for plugins providing file analyzers. @@ -25,6 +26,7 @@ class Component : public plugin::Component, public plugin::TaggedComponent { public: typedef Analyzer* (*factory_callback)(RecordVal* args, File* file); + using factory_function = Analyzer* (*)(IntrusivePtr args, File* file); /** * Constructor. @@ -45,6 +47,9 @@ public: * analyzer instances can accordingly access it via analyzer::Tag(). * If not used, leave at zero. */ + Component(const std::string& name, factory_function factory, Tag::subtype_t subtype = 0); + + [[deprecated("Remove in v4.1. Use factory_function w/ IntrusivePtr args")]] Component(const std::string& name, factory_callback factory, Tag::subtype_t subtype = 0); /** @@ -62,6 +67,10 @@ public: /** * Returns the analyzer's factory function. */ + factory_function FactoryFunction() const + { return factory_func; } + + [[deprecated("Remove in v4.1. Use FactoryFunction().")]] factory_callback Factory() const { return factory; } protected: @@ -71,7 +80,10 @@ protected: void DoDescribe(ODesc* d) const override; private: - factory_callback factory; // The analyzer's factory callback. + friend class file_analysis::Manager; + + factory_callback factory; // The analyzer's factory callback (deprecated). + factory_function factory_func; // The analyzer's factory callback. }; } diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index 3c09498a4b..b8c643809e 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -443,6 +443,11 @@ bool Manager::IsDisabled(const analyzer::Tag& tag) } Analyzer* Manager::InstantiateAnalyzer(const Tag& tag, RecordVal* args, File* f) const + { return InstantiateAnalyzer(tag, {NewRef{}, args}, f); } + +Analyzer* Manager::InstantiateAnalyzer(const Tag& tag, + IntrusivePtr args, + File* f) const { Component* c = Lookup(tag); @@ -454,18 +459,22 @@ Analyzer* Manager::InstantiateAnalyzer(const Tag& tag, RecordVal* args, File* f) return nullptr; } - if ( ! c->Factory() ) + DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Instantiate analyzer %s", + f->id.c_str(), GetComponentName(tag).c_str()); + + Analyzer* a; + + if ( c->factory_func ) + a = c->factory_func(std::move(args), f); + else if ( c->factory ) + a = c->factory(args.get(), f); + else { reporter->InternalWarning("file analyzer %s cannot be instantiated " - "dynamically", c->CanonicalName().c_str()); + "dynamically", c->CanonicalName().c_str()); return nullptr; } - DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Instantiate analyzer %s", - f->id.c_str(), GetComponentName(tag).c_str()); - - Analyzer* a = c->Factory()(args, f); - if ( ! a ) reporter->InternalError("file analyzer instantiation failed"); diff --git a/src/file_analysis/Manager.h b/src/file_analysis/Manager.h index 8d619d04bd..5086ab6e39 100644 --- a/src/file_analysis/Manager.h +++ b/src/file_analysis/Manager.h @@ -300,6 +300,10 @@ public: * @param f The file analzer is to be associated with. * @return The new analyzer instance or null if tag is invalid. */ + Analyzer* InstantiateAnalyzer(const Tag& tag, IntrusivePtr args, + File* f) const; + + [[deprecated("Remove in v4.1. Pass in IntrusivePtr args instead.")]] Analyzer* InstantiateAnalyzer(const Tag& tag, RecordVal* args, File* f) const; /** diff --git a/src/file_analysis/analyzer/data_event/DataEvent.cc b/src/file_analysis/analyzer/data_event/DataEvent.cc index 619605b34a..04175723af 100644 --- a/src/file_analysis/analyzer/data_event/DataEvent.cc +++ b/src/file_analysis/analyzer/data_event/DataEvent.cc @@ -11,15 +11,16 @@ using namespace file_analysis; -DataEvent::DataEvent(RecordVal* args, File* file, +DataEvent::DataEvent(IntrusivePtr args, File* file, EventHandlerPtr ce, EventHandlerPtr se) : file_analysis::Analyzer(file_mgr->GetComponentTag("DATA_EVENT"), - args, file), + std::move(args), file), chunk_event(ce), stream_event(se) { } -file_analysis::Analyzer* DataEvent::Instantiate(RecordVal* args, File* file) +file_analysis::Analyzer* DataEvent::Instantiate(IntrusivePtr args, + File* file) { const auto& chunk_val = args->GetField("chunk_event"); const auto& stream_val = args->GetField("stream_event"); @@ -35,7 +36,7 @@ file_analysis::Analyzer* DataEvent::Instantiate(RecordVal* args, File* file) if ( stream_val ) stream = event_registry->Lookup(stream_val->AsFunc()->Name()); - return new DataEvent(args, file, chunk, stream); + return new DataEvent(std::move(args), file, chunk, stream); } bool DataEvent::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset) diff --git a/src/file_analysis/analyzer/data_event/DataEvent.h b/src/file_analysis/analyzer/data_event/DataEvent.h index 5027fd78ed..c1dd1ab64b 100644 --- a/src/file_analysis/analyzer/data_event/DataEvent.h +++ b/src/file_analysis/analyzer/data_event/DataEvent.h @@ -43,7 +43,8 @@ public: * @return the new DataEvent analyzer instance or a null pointer if * no "chunk_event" or "stream_event" field was specfied in \a args. */ - static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file); + static file_analysis::Analyzer* Instantiate(IntrusivePtr args, + File* file); protected: @@ -56,7 +57,7 @@ protected: * @param se pointer to event handler which will be called to receive * sequential file data. */ - DataEvent(RecordVal* args, File* file, + DataEvent(IntrusivePtr args, File* file, EventHandlerPtr ce, EventHandlerPtr se); private: diff --git a/src/file_analysis/analyzer/entropy/Entropy.cc b/src/file_analysis/analyzer/entropy/Entropy.cc index 401a9020d6..443a97b729 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.cc +++ b/src/file_analysis/analyzer/entropy/Entropy.cc @@ -9,8 +9,9 @@ using namespace file_analysis; -Entropy::Entropy(RecordVal* args, File* file) - : file_analysis::Analyzer(file_mgr->GetComponentTag("ENTROPY"), args, file) +Entropy::Entropy(IntrusivePtr args, File* file) + : file_analysis::Analyzer(file_mgr->GetComponentTag("ENTROPY"), + std::move(args), file) { //entropy->Init(); entropy = new EntropyVal; @@ -22,9 +23,10 @@ Entropy::~Entropy() Unref(entropy); } -file_analysis::Analyzer* Entropy::Instantiate(RecordVal* args, File* file) +file_analysis::Analyzer* Entropy::Instantiate(IntrusivePtr args, + File* file) { - return new Entropy(args, file); + return new Entropy(std::move(args), file); } bool Entropy::DeliverStream(const u_char* data, uint64_t len) diff --git a/src/file_analysis/analyzer/entropy/Entropy.h b/src/file_analysis/analyzer/entropy/Entropy.h index d316291a5f..2f65f1aa56 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.h +++ b/src/file_analysis/analyzer/entropy/Entropy.h @@ -31,7 +31,8 @@ public: * @return the new Entropy analyzer instance or a null pointer if the * the "extraction_file" field of \a args wasn't set. */ - static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file); + static file_analysis::Analyzer* Instantiate(IntrusivePtr args, + File* file); /** * Calculate entropy of next chunk of file contents. @@ -65,7 +66,7 @@ protected: * @param hv specific hash calculator object. * @param kind human readable name of the hash algorithm to use. */ - Entropy(RecordVal* args, File* file); + Entropy(IntrusivePtr args, File* file); /** * If some file contents have been seen, finalizes the entropy of them and diff --git a/src/file_analysis/analyzer/extract/Extract.cc b/src/file_analysis/analyzer/extract/Extract.cc index 2ba8e7926d..869c8e8724 100644 --- a/src/file_analysis/analyzer/extract/Extract.cc +++ b/src/file_analysis/analyzer/extract/Extract.cc @@ -10,9 +10,10 @@ using namespace file_analysis; -Extract::Extract(RecordVal* args, File* file, const std::string& arg_filename, - uint64_t arg_limit) - : file_analysis::Analyzer(file_mgr->GetComponentTag("EXTRACT"), args, file), +Extract::Extract(IntrusivePtr args, File* file, + const std::string& arg_filename, uint64_t arg_limit) + : file_analysis::Analyzer(file_mgr->GetComponentTag("EXTRACT"), + std::move(args), file), filename(arg_filename), limit(arg_limit), depth(0) { fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0666); @@ -32,7 +33,8 @@ Extract::~Extract() safe_close(fd); } -static const IntrusivePtr& get_extract_field_val(RecordVal* args, const char* name) +static const IntrusivePtr& get_extract_field_val(const IntrusivePtr& args, + const char* name) { const auto& rval = args->GetField(name); @@ -42,7 +44,7 @@ static const IntrusivePtr& get_extract_field_val(RecordVal* args, const cha return rval; } -file_analysis::Analyzer* Extract::Instantiate(RecordVal* args, File* file) +file_analysis::Analyzer* Extract::Instantiate(IntrusivePtr args, File* file) { const auto& fname = get_extract_field_val(args, "extract_filename"); const auto& limit = get_extract_field_val(args, "extract_limit"); @@ -50,7 +52,7 @@ file_analysis::Analyzer* Extract::Instantiate(RecordVal* args, File* file) if ( ! fname || ! limit ) return nullptr; - return new Extract(args, file, fname->AsString()->CheckString(), + return new Extract(std::move(args), file, fname->AsString()->CheckString(), limit->AsCount()); } diff --git a/src/file_analysis/analyzer/extract/Extract.h b/src/file_analysis/analyzer/extract/Extract.h index 5d2cd5b10b..c51e2e1a80 100644 --- a/src/file_analysis/analyzer/extract/Extract.h +++ b/src/file_analysis/analyzer/extract/Extract.h @@ -47,7 +47,8 @@ public: * @return the new Extract analyzer instance or a null pointer if the * the "extraction_file" field of \a args wasn't set. */ - static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file); + static file_analysis::Analyzer* Instantiate(IntrusivePtr args, + File* file); /** * Sets the maximum allowed extracted file size. A value of zero means @@ -66,8 +67,8 @@ protected: * to which the contents of the file will be extracted/written. * @param arg_limit the maximum allowed file size. */ - Extract(RecordVal* args, File* file, const std::string& arg_filename, - uint64_t arg_limit); + Extract(IntrusivePtr args, File* file, + const std::string& arg_filename, uint64_t arg_limit); private: std::string filename; diff --git a/src/file_analysis/analyzer/hash/Hash.cc b/src/file_analysis/analyzer/hash/Hash.cc index 99187d243d..011b6ef443 100644 --- a/src/file_analysis/analyzer/hash/Hash.cc +++ b/src/file_analysis/analyzer/hash/Hash.cc @@ -9,8 +9,10 @@ using namespace file_analysis; -Hash::Hash(RecordVal* args, File* file, HashVal* hv, const char* arg_kind) - : file_analysis::Analyzer(file_mgr->GetComponentTag(to_upper(arg_kind).c_str()), args, file), hash(hv), fed(false), kind(arg_kind) +Hash::Hash(IntrusivePtr args, File* file, HashVal* hv, const char* arg_kind) + : file_analysis::Analyzer(file_mgr->GetComponentTag(to_upper(arg_kind).c_str()), + std::move(args), file), + hash(hv), fed(false), kind(arg_kind) { hash->Init(); } diff --git a/src/file_analysis/analyzer/hash/Hash.h b/src/file_analysis/analyzer/hash/Hash.h index 903fc7d6f7..190152d1c3 100644 --- a/src/file_analysis/analyzer/hash/Hash.h +++ b/src/file_analysis/analyzer/hash/Hash.h @@ -56,7 +56,7 @@ protected: * @param hv specific hash calculator object. * @param kind human readable name of the hash algorithm to use. */ - Hash(RecordVal* args, File* file, HashVal* hv, const char* kind); + Hash(IntrusivePtr args, File* file, HashVal* hv, const char* kind); /** * If some file contents have been seen, finalizes the hash of them and @@ -83,8 +83,9 @@ public: * @return the new MD5 analyzer instance or a null pointer if there's no * handler for the "file_hash" event. */ - static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file) - { return file_hash ? new MD5(args, file) : nullptr; } + static file_analysis::Analyzer* Instantiate(IntrusivePtr args, + File* file) + { return file_hash ? new MD5(std::move(args), file) : nullptr; } protected: @@ -93,8 +94,8 @@ protected: * @param args the \c AnalyzerArgs value which represents the analyzer. * @param file the file to which the analyzer will be attached. */ - MD5(RecordVal* args, File* file) - : Hash(args, file, new MD5Val(), "md5") + MD5(IntrusivePtr args, File* file) + : Hash(std::move(args), file, new MD5Val(), "md5") {} }; @@ -111,8 +112,9 @@ public: * @return the new MD5 analyzer instance or a null pointer if there's no * handler for the "file_hash" event. */ - static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file) - { return file_hash ? new SHA1(args, file) : nullptr; } + static file_analysis::Analyzer* Instantiate(IntrusivePtr args, + File* file) + { return file_hash ? new SHA1(std::move(args), file) : nullptr; } protected: @@ -121,8 +123,8 @@ protected: * @param args the \c AnalyzerArgs value which represents the analyzer. * @param file the file to which the analyzer will be attached. */ - SHA1(RecordVal* args, File* file) - : Hash(args, file, new SHA1Val(), "sha1") + SHA1(IntrusivePtr args, File* file) + : Hash(std::move(args), file, new SHA1Val(), "sha1") {} }; @@ -139,8 +141,9 @@ public: * @return the new MD5 analyzer instance or a null pointer if there's no * handler for the "file_hash" event. */ - static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file) - { return file_hash ? new SHA256(args, file) : nullptr; } + static file_analysis::Analyzer* Instantiate(IntrusivePtr args, + File* file) + { return file_hash ? new SHA256(std::move(args), file) : nullptr; } protected: @@ -149,8 +152,8 @@ protected: * @param args the \c AnalyzerArgs value which represents the analyzer. * @param file the file to which the analyzer will be attached. */ - SHA256(RecordVal* args, File* file) - : Hash(args, file, new SHA256Val(), "sha256") + SHA256(IntrusivePtr args, File* file) + : Hash(std::move(args), file, new SHA256Val(), "sha256") {} }; diff --git a/src/file_analysis/analyzer/pe/PE.cc b/src/file_analysis/analyzer/pe/PE.cc index 20ecadc3bf..0962f51dfa 100644 --- a/src/file_analysis/analyzer/pe/PE.cc +++ b/src/file_analysis/analyzer/pe/PE.cc @@ -3,8 +3,9 @@ using namespace file_analysis; -PE::PE(RecordVal* args, File* file) - : file_analysis::Analyzer(file_mgr->GetComponentTag("PE"), args, file) +PE::PE(IntrusivePtr args, File* file) + : file_analysis::Analyzer(file_mgr->GetComponentTag("PE"), std::move(args), + file) { conn = new binpac::PE::MockConnection(this); interp = new binpac::PE::File(conn); diff --git a/src/file_analysis/analyzer/pe/PE.h b/src/file_analysis/analyzer/pe/PE.h index 3a1c9befc0..87a82825f4 100644 --- a/src/file_analysis/analyzer/pe/PE.h +++ b/src/file_analysis/analyzer/pe/PE.h @@ -15,15 +15,16 @@ class PE : public file_analysis::Analyzer { public: ~PE(); - static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file) - { return new PE(args, file); } + static file_analysis::Analyzer* Instantiate(IntrusivePtr args, + File* file) + { return new PE(std::move(args), file); } virtual bool DeliverStream(const u_char* data, uint64_t len); virtual bool EndOfFile(); protected: - PE(RecordVal* args, File* file); + PE(IntrusivePtr args, File* file); binpac::PE::File* interp; binpac::PE::MockConnection* conn; bool done; diff --git a/src/file_analysis/analyzer/unified2/Unified2.cc b/src/file_analysis/analyzer/unified2/Unified2.cc index d14ee340e9..e9b14373c6 100644 --- a/src/file_analysis/analyzer/unified2/Unified2.cc +++ b/src/file_analysis/analyzer/unified2/Unified2.cc @@ -5,8 +5,8 @@ using namespace file_analysis; -Unified2::Unified2(RecordVal* args, File* file) - : file_analysis::Analyzer(file_mgr->GetComponentTag("UNIFIED2"), args, file) +Unified2::Unified2(IntrusivePtr args, File* file) + : file_analysis::Analyzer(file_mgr->GetComponentTag("UNIFIED2"), std::move(args), file) { interp = new binpac::Unified2::Unified2_Analyzer(this); } @@ -16,9 +16,9 @@ Unified2::~Unified2() delete interp; } -file_analysis::Analyzer* Unified2::Instantiate(RecordVal* args, File* file) +file_analysis::Analyzer* Unified2::Instantiate(IntrusivePtr args, File* file) { - return new Unified2(args, file); + return new Unified2(std::move(args), file); } bool Unified2::DeliverStream(const u_char* data, uint64_t len) diff --git a/src/file_analysis/analyzer/unified2/Unified2.h b/src/file_analysis/analyzer/unified2/Unified2.h index 8184861b22..b65c25e0a1 100644 --- a/src/file_analysis/analyzer/unified2/Unified2.h +++ b/src/file_analysis/analyzer/unified2/Unified2.h @@ -20,10 +20,11 @@ public: bool DeliverStream(const u_char* data, uint64_t len) override; - static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file); + static file_analysis::Analyzer* Instantiate(IntrusivePtr args, + File* file); protected: - Unified2(RecordVal* args, File* file); + Unified2(IntrusivePtr args, File* file); private: binpac::Unified2::Unified2_Analyzer* interp; diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index 91c1535ec6..b11d7c6970 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -112,18 +112,23 @@ static bool ocsp_add_cert_id(const OCSP_CERTID* cert_id, zeek::Args* vl, BIO* bi return true; } -file_analysis::Analyzer* OCSP::InstantiateRequest(RecordVal* args, File* file) +file_analysis::Analyzer* OCSP::InstantiateRequest(IntrusivePtr args, + File* file) { - return new OCSP(args, file, true); + return new OCSP(std::move(args), file, true); } -file_analysis::Analyzer* OCSP::InstantiateReply(RecordVal* args, File* file) +file_analysis::Analyzer* OCSP::InstantiateReply(IntrusivePtr args, + File* file) { - return new OCSP(args, file, false); + return new OCSP(std::move(args), file, false); } -file_analysis::OCSP::OCSP(RecordVal* args, file_analysis::File* file, bool arg_request) - : file_analysis::X509Common::X509Common(file_mgr->GetComponentTag("OCSP"), args, file), request(arg_request) +file_analysis::OCSP::OCSP(IntrusivePtr args, file_analysis::File* file, + bool arg_request) + : file_analysis::X509Common::X509Common(file_mgr->GetComponentTag("OCSP"), + std::move(args), file), + request(arg_request) { } diff --git a/src/file_analysis/analyzer/x509/OCSP.h b/src/file_analysis/analyzer/x509/OCSP.h index 06ea1dd25a..c3cec77cec 100644 --- a/src/file_analysis/analyzer/x509/OCSP.h +++ b/src/file_analysis/analyzer/x509/OCSP.h @@ -18,11 +18,13 @@ public: bool Undelivered(uint64_t offset, uint64_t len) override; bool EndOfFile() override; - static file_analysis::Analyzer* InstantiateRequest(RecordVal* args, File* file); - static file_analysis::Analyzer* InstantiateReply(RecordVal* args, File* file); + static file_analysis::Analyzer* InstantiateRequest(IntrusivePtr args, + File* file); + static file_analysis::Analyzer* InstantiateReply(IntrusivePtr args, + File* file); protected: - OCSP(RecordVal* args, File* file, bool request); + OCSP(IntrusivePtr args, File* file, bool request); private: void ParseResponse(OCSP_RESPONSE*); diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 58946c7618..8ad24921ef 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -21,8 +21,9 @@ using namespace file_analysis; -file_analysis::X509::X509(RecordVal* args, file_analysis::File* file) - : file_analysis::X509Common::X509Common(file_mgr->GetComponentTag("X509"), args, file) +file_analysis::X509::X509(IntrusivePtr args, file_analysis::File* file) + : file_analysis::X509Common::X509Common(file_mgr->GetComponentTag("X509"), + std::move(args), file) { cert_data.clear(); } diff --git a/src/file_analysis/analyzer/x509/X509.h b/src/file_analysis/analyzer/x509/X509.h index 98370977c4..092ac9aa94 100644 --- a/src/file_analysis/analyzer/x509/X509.h +++ b/src/file_analysis/analyzer/x509/X509.h @@ -88,8 +88,9 @@ public: */ static IntrusivePtr ParseCertificate(X509Val* cert_val, File* file = nullptr); - static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file) - { return new X509(args, file); } + static file_analysis::Analyzer* Instantiate(IntrusivePtr args, + File* file) + { return new X509(std::move(args), file); } /** * Retrieves OpenSSL's representation of an X509 certificate store @@ -126,7 +127,7 @@ public: { cache_hit_callback = std::move(func); } protected: - X509(RecordVal* args, File* file); + X509(IntrusivePtr args, File* file); private: void ParseBasicConstraints(X509_EXTENSION* ex); diff --git a/src/file_analysis/analyzer/x509/X509Common.cc b/src/file_analysis/analyzer/x509/X509Common.cc index 723786f42c..e30ac06f7c 100644 --- a/src/file_analysis/analyzer/x509/X509Common.cc +++ b/src/file_analysis/analyzer/x509/X509Common.cc @@ -16,8 +16,9 @@ using namespace file_analysis; -X509Common::X509Common(const file_analysis::Tag& arg_tag, RecordVal* arg_args, File* arg_file) - : file_analysis::Analyzer(arg_tag, arg_args, arg_file) +X509Common::X509Common(const file_analysis::Tag& arg_tag, + IntrusivePtr arg_args, File* arg_file) + : file_analysis::Analyzer(arg_tag, std::move(arg_args), arg_file) { } diff --git a/src/file_analysis/analyzer/x509/X509Common.h b/src/file_analysis/analyzer/x509/X509Common.h index 5276329e55..a7c9254d0b 100644 --- a/src/file_analysis/analyzer/x509/X509Common.h +++ b/src/file_analysis/analyzer/x509/X509Common.h @@ -40,7 +40,8 @@ public: static double GetTimeFromAsn1(const ASN1_TIME* atime, File* f, Reporter* reporter); protected: - X509Common(const file_analysis::Tag& arg_tag, RecordVal* arg_args, File* arg_file); + X509Common(const file_analysis::Tag& arg_tag, + IntrusivePtr arg_args, File* arg_file); void ParseExtension(X509_EXTENSION* ex, const EventHandlerPtr& h, bool global); void ParseSignedCertificateTimestamps(X509_EXTENSION* ext); From b1042e282494f2d02ab68752f95305bea1ca2856 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 22 May 2020 16:32:40 -0700 Subject: [PATCH 124/151] Port remaining file analysis API to use IntrusivePtr --- src/file_analysis/AnalyzerSet.cc | 83 +++++++++---------- src/file_analysis/AnalyzerSet.h | 35 ++++---- src/file_analysis/File.cc | 26 ++++-- src/file_analysis/File.h | 9 ++ src/file_analysis/Manager.cc | 18 +++- src/file_analysis/Manager.h | 12 +++ .../analyzer/extract/functions.bif | 3 +- src/file_analysis/file_analysis.bif | 6 +- 8 files changed, 117 insertions(+), 75 deletions(-) diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index a5abef9437..8d1397e6d6 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -40,60 +40,54 @@ AnalyzerSet::~AnalyzerSet() delete analyzer_hash; } -Analyzer* AnalyzerSet::Find(const file_analysis::Tag& tag, RecordVal* args) +Analyzer* AnalyzerSet::Find(const file_analysis::Tag& tag, + IntrusivePtr args) { - HashKey* key = GetKey(tag, args); - Analyzer* rval = analyzer_map.Lookup(key); - delete key; + auto key = GetKey(tag, std::move(args)); + Analyzer* rval = analyzer_map.Lookup(key.get()); return rval; } -bool AnalyzerSet::Add(const file_analysis::Tag& tag, RecordVal* args) +bool AnalyzerSet::Add(const file_analysis::Tag& tag, IntrusivePtr args) { - HashKey* key = GetKey(tag, args); + auto key = GetKey(tag, args); - if ( analyzer_map.Lookup(key) ) + if ( analyzer_map.Lookup(key.get()) ) { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Instantiate analyzer %s skipped: already exists", file->GetID().c_str(), file_mgr->GetComponentName(tag).c_str()); - delete key; return true; } - file_analysis::Analyzer* a = InstantiateAnalyzer(tag, args); + file_analysis::Analyzer* a = InstantiateAnalyzer(tag, std::move(args)); if ( ! a ) - { - delete key; return false; - } - Insert(a, key); + Insert(a, std::move(key)); return true; } -Analyzer* AnalyzerSet::QueueAdd(const file_analysis::Tag& tag, RecordVal* args) +Analyzer* AnalyzerSet::QueueAdd(const file_analysis::Tag& tag, + IntrusivePtr args) { - HashKey* key = GetKey(tag, args); - file_analysis::Analyzer* a = InstantiateAnalyzer(tag, args); + auto key = GetKey(tag, args); + file_analysis::Analyzer* a = InstantiateAnalyzer(tag, std::move(args)); if ( ! a ) - { - delete key; return nullptr; - } - mod_queue.push(new AddMod(a, key)); + mod_queue.push(new AddMod(a, std::move(key))); return a; } bool AnalyzerSet::AddMod::Perform(AnalyzerSet* set) { - if ( set->analyzer_map.Lookup(key) ) + if ( set->analyzer_map.Lookup(key.get()) ) { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Add analyzer %s skipped: already exists", a->GetFile()->GetID().c_str(), @@ -103,7 +97,7 @@ bool AnalyzerSet::AddMod::Perform(AnalyzerSet* set) return true; } - set->Insert(a, key); + set->Insert(a, std::move(key)); return true; } @@ -111,20 +105,18 @@ bool AnalyzerSet::AddMod::Perform(AnalyzerSet* set) void AnalyzerSet::AddMod::Abort() { delete a; - delete key; } -bool AnalyzerSet::Remove(const file_analysis::Tag& tag, RecordVal* args) +bool AnalyzerSet::Remove(const file_analysis::Tag& tag, + IntrusivePtr args) { - return Remove(tag, GetKey(tag, args)); + return Remove(tag, GetKey(tag, std::move(args))); } -bool AnalyzerSet::Remove(const file_analysis::Tag& tag, HashKey* key) +bool AnalyzerSet::Remove(const file_analysis::Tag& tag, + std::unique_ptr key) { - file_analysis::Analyzer* a = - (file_analysis::Analyzer*) analyzer_map.Remove(key); - - delete key; + auto a = (file_analysis::Analyzer*) analyzer_map.Remove(key.get()); if ( ! a ) { @@ -147,37 +139,38 @@ bool AnalyzerSet::Remove(const file_analysis::Tag& tag, HashKey* key) return true; } -bool AnalyzerSet::QueueRemove(const file_analysis::Tag& tag, RecordVal* args) +bool AnalyzerSet::QueueRemove(const file_analysis::Tag& tag, + IntrusivePtr args) { - HashKey* key = GetKey(tag, args); - - mod_queue.push(new RemoveMod(tag, key)); - - return analyzer_map.Lookup(key); + auto key = GetKey(tag, std::move(args)); + auto rval = analyzer_map.Lookup(key.get()); + mod_queue.push(new RemoveMod(tag, std::move(key))); + return rval; } bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set) { - return set->Remove(tag, key); + return set->Remove(tag, std::move(key)); } -HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const +std::unique_ptr AnalyzerSet::GetKey(const file_analysis::Tag& t, + IntrusivePtr args) const { auto lv = make_intrusive(TYPE_ANY); lv->Append(t.AsVal()); - lv->Append({NewRef{}, args}); + lv->Append(std::move(args)); auto key = analyzer_hash->MakeHashKey(*lv, true); if ( ! key ) reporter->InternalError("AnalyzerArgs type mismatch"); - return key.release(); + return key; } file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(const Tag& tag, - RecordVal* args) const + IntrusivePtr args) const { - auto a = file_mgr->InstantiateAnalyzer(tag, {NewRef{}, args}, file); + auto a = file_mgr->InstantiateAnalyzer(tag, std::move(args), file); if ( ! a ) { @@ -190,12 +183,12 @@ file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(const Tag& tag, return a; } -void AnalyzerSet::Insert(file_analysis::Analyzer* a, HashKey* key) +void AnalyzerSet::Insert(file_analysis::Analyzer* a, + std::unique_ptr key) { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Add analyzer %s", file->GetID().c_str(), file_mgr->GetComponentName(a->Tag()).c_str()); - analyzer_map.Insert(key, a); - delete key; + analyzer_map.Insert(key.get(), a); a->Init(); } diff --git a/src/file_analysis/AnalyzerSet.h b/src/file_analysis/AnalyzerSet.h index 4605371eef..c0ef1d6fc0 100644 --- a/src/file_analysis/AnalyzerSet.h +++ b/src/file_analysis/AnalyzerSet.h @@ -3,6 +3,7 @@ #pragma once #include +#include #include "Dict.h" #include "Tag.h" @@ -42,7 +43,7 @@ public: * @param args an \c AnalyzerArgs record. * @return pointer to an analyzer instance, or a null pointer if not found. */ - Analyzer* Find(const file_analysis::Tag& tag, RecordVal* args); + Analyzer* Find(const file_analysis::Tag& tag, IntrusivePtr args); /** * Attach an analyzer to #file immediately. @@ -50,7 +51,7 @@ public: * @param args an \c AnalyzerArgs value which specifies an analyzer. * @return true if analyzer was instantiated/attached, else false. */ - bool Add(const file_analysis::Tag& tag, RecordVal* args); + bool Add(const file_analysis::Tag& tag, IntrusivePtr args); /** * Queue the attachment of an analyzer to #file. @@ -59,7 +60,8 @@ public: * @return if successful, a pointer to a newly instantiated analyzer else * a null pointer. The caller does *not* take ownership of the memory. */ - file_analysis::Analyzer* QueueAdd(const file_analysis::Tag& tag, RecordVal* args); + file_analysis::Analyzer* QueueAdd(const file_analysis::Tag& tag, + IntrusivePtr args); /** * Remove an analyzer from #file immediately. @@ -67,7 +69,7 @@ public: * @param args an \c AnalyzerArgs value which specifies an analyzer. * @return false if analyzer didn't exist and so wasn't removed, else true. */ - bool Remove(const file_analysis::Tag& tag, RecordVal* args); + bool Remove(const file_analysis::Tag& tag, IntrusivePtr args); /** * Queue the removal of an analyzer from #file. @@ -75,7 +77,7 @@ public: * @param args an \c AnalyzerArgs value which specifies an analyzer. * @return true if analyzer exists at time of call, else false; */ - bool QueueRemove(const file_analysis::Tag& tag, RecordVal* args); + bool QueueRemove(const file_analysis::Tag& tag, IntrusivePtr args); /** * Perform all queued modifications to the current analyzer set. @@ -108,7 +110,8 @@ protected: * @param args an \c AnalyzerArgs value which specifies an analyzer. * @return the hash key calculated from \a args */ - HashKey* GetKey(const file_analysis::Tag& tag, RecordVal* args) const; + std::unique_ptr GetKey(const file_analysis::Tag& tag, + IntrusivePtr args) const; /** * Create an instance of a file analyzer. @@ -117,14 +120,14 @@ protected: * @return a new file analyzer instance. */ file_analysis::Analyzer* InstantiateAnalyzer(const file_analysis::Tag& tag, - RecordVal* args) const; + IntrusivePtr args) const; /** * Insert an analyzer instance in to the set. * @param a an analyzer instance. * @param key the hash key which represents the analyzer's \c AnalyzerArgs. */ - void Insert(file_analysis::Analyzer* a, HashKey* key); + void Insert(file_analysis::Analyzer* a, std::unique_ptr key); /** * Remove an analyzer instance from the set. @@ -132,7 +135,7 @@ protected: * just used for debugging messages. * @param key the hash key which represents the analyzer's \c AnalyzerArgs. */ - bool Remove(const file_analysis::Tag& tag, HashKey* key); + bool Remove(const file_analysis::Tag& tag, std::unique_ptr key); private: @@ -170,15 +173,15 @@ private: * @param arg_a an analyzer instance to add to an analyzer set. * @param arg_key hash key representing the analyzer's \c AnalyzerArgs. */ - AddMod(file_analysis::Analyzer* arg_a, HashKey* arg_key) - : Modification(), a(arg_a), key(arg_key) {} + AddMod(file_analysis::Analyzer* arg_a, std::unique_ptr arg_key) + : Modification(), a(arg_a), key(std::move(arg_key)) {} ~AddMod() override {} bool Perform(AnalyzerSet* set) override; void Abort() override; protected: file_analysis::Analyzer* a; - HashKey* key; + std::unique_ptr key; }; /** @@ -191,15 +194,15 @@ private: * @param arg_a an analyzer instance to add to an analyzer set. * @param arg_key hash key representing the analyzer's \c AnalyzerArgs. */ - RemoveMod(const file_analysis::Tag& arg_tag, HashKey* arg_key) - : Modification(), tag(arg_tag), key(arg_key) {} + RemoveMod(const file_analysis::Tag& arg_tag, std::unique_ptr arg_key) + : Modification(), tag(arg_tag), key(std::move(arg_key)) {} ~RemoveMod() override {} bool Perform(AnalyzerSet* set) override; - void Abort() override { delete key; } + void Abort() override {} protected: file_analysis::Tag tag; - HashKey* key; + std::unique_ptr key; }; using ModQueue = std::queue; diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index fabe76c98d..4146bf9dd3 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -204,8 +204,12 @@ void File::SetTimeoutInterval(double interval) } bool File::SetExtractionLimit(RecordVal* args, uint64_t bytes) + { return SetExtractionLimit({NewRef{}, args}, bytes); } + +bool File::SetExtractionLimit(IntrusivePtr args, uint64_t bytes) { - Analyzer* a = analyzers.Find(file_mgr->GetComponentTag("EXTRACT"), args); + Analyzer* a = analyzers.Find(file_mgr->GetComponentTag("EXTRACT"), + std::move(args)); if ( ! a ) return false; @@ -250,6 +254,9 @@ void File::ScheduleInactivityTimer() const } bool File::AddAnalyzer(file_analysis::Tag tag, RecordVal* args) + { return AddAnalyzer(tag, {NewRef{}, args}); } + +bool File::AddAnalyzer(file_analysis::Tag tag, IntrusivePtr args) { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Queuing addition of %s analyzer", id.c_str(), file_mgr->GetComponentName(tag).c_str()); @@ -257,15 +264,18 @@ bool File::AddAnalyzer(file_analysis::Tag tag, RecordVal* args) if ( done ) return false; - return analyzers.QueueAdd(tag, args) != nullptr; + return analyzers.QueueAdd(tag, std::move(args)) != nullptr; } bool File::RemoveAnalyzer(file_analysis::Tag tag, RecordVal* args) + { return RemoveAnalyzer(tag, {NewRef{}, args}); } + +bool File::RemoveAnalyzer(file_analysis::Tag tag, IntrusivePtr args) { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Queuing remove of %s analyzer", id.c_str(), file_mgr->GetComponentName(tag).c_str()); - return done ? false : analyzers.QueueRemove(tag, args); + return done ? false : analyzers.QueueRemove(tag, std::move(args)); } void File::EnableReassembly() @@ -410,7 +420,7 @@ void File::DeliverStream(const u_char* data, uint64_t len) bof_buffer.chunks[i]->Len()) ) { a->SetSkip(true); - analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); + analyzers.QueueRemove(a->Tag(), a->GetArgs()); } } @@ -427,7 +437,7 @@ void File::DeliverStream(const u_char* data, uint64_t len) if ( ! a->DeliverStream(data, len) ) { a->SetSkip(true); - analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); + analyzers.QueueRemove(a->Tag(), a->GetArgs()); } } } @@ -498,7 +508,7 @@ void File::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset) if ( ! a->DeliverChunk(data, len, offset) ) { a->SetSkip(true); - analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); + analyzers.QueueRemove(a->Tag(), a->GetArgs()); } } } @@ -557,7 +567,7 @@ void File::EndOfFile() while ( (a = analyzers.NextEntry(c)) ) { if ( ! a->EndOfFile() ) - analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); + analyzers.QueueRemove(a->Tag(), a->GetArgs()); } FileEvent(file_state_remove); @@ -590,7 +600,7 @@ void File::Gap(uint64_t offset, uint64_t len) while ( (a = analyzers.NextEntry(c)) ) { if ( ! a->Undelivered(offset, len) ) - analyzers.QueueRemove(a->Tag(), a->GetArgs().get()); + analyzers.QueueRemove(a->Tag(), a->GetArgs()); } if ( FileEventAvailable(file_gap) ) diff --git a/src/file_analysis/File.h b/src/file_analysis/File.h index d201c416af..f7afe45b77 100644 --- a/src/file_analysis/File.h +++ b/src/file_analysis/File.h @@ -74,6 +74,9 @@ public: * @param bytes new limit. * @return false if no extraction analyzer is active, else true. */ + bool SetExtractionLimit(IntrusivePtr args, uint64_t bytes); + + [[deprecated("Remove in v4.1. Pass an IntrusivePtr instead.")]] bool SetExtractionLimit(RecordVal* args, uint64_t bytes); /** @@ -119,6 +122,9 @@ public: * @param args an \c AnalyzerArgs value representing a file analyzer. * @return false if analyzer can't be instantiated, else true. */ + bool AddAnalyzer(file_analysis::Tag tag, IntrusivePtr args); + + [[deprecated("Remove in v4.1. Pass an IntrusivePtr instead.")]] bool AddAnalyzer(file_analysis::Tag tag, RecordVal* args); /** @@ -127,6 +133,9 @@ public: * @param args an \c AnalyzerArgs value representing a file analyzer. * @return true if analyzer was active at time of call, else false. */ + bool RemoveAnalyzer(file_analysis::Tag tag, IntrusivePtr args); + + [[deprecated("Remove in v4.1. Pass an IntrusivePtr instead.")]] bool RemoveAnalyzer(file_analysis::Tag tag, RecordVal* args); /** diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index b8c643809e..1c2465c415 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -260,35 +260,47 @@ bool Manager::SetReassemblyBuffer(const string& file_id, uint64_t max) bool Manager::SetExtractionLimit(const string& file_id, RecordVal* args, uint64_t n) const + { return SetExtractionLimit(file_id, {NewRef{}, args}, n); } + +bool Manager::SetExtractionLimit(const string& file_id, + IntrusivePtr args, uint64_t n) const { File* file = LookupFile(file_id); if ( ! file ) return false; - return file->SetExtractionLimit(args, n); + return file->SetExtractionLimit(std::move(args), n); } bool Manager::AddAnalyzer(const string& file_id, const file_analysis::Tag& tag, RecordVal* args) const + { return AddAnalyzer(file_id, tag, {NewRef{}, args}); } + +bool Manager::AddAnalyzer(const string& file_id, const file_analysis::Tag& tag, + IntrusivePtr args) const { File* file = LookupFile(file_id); if ( ! file ) return false; - return file->AddAnalyzer(tag, args); + return file->AddAnalyzer(tag, std::move(args)); } bool Manager::RemoveAnalyzer(const string& file_id, const file_analysis::Tag& tag, RecordVal* args) const + { return RemoveAnalyzer(file_id, tag, {NewRef{}, args}); } + +bool Manager::RemoveAnalyzer(const string& file_id, const file_analysis::Tag& tag, + IntrusivePtr args) const { File* file = LookupFile(file_id); if ( ! file ) return false; - return file->RemoveAnalyzer(tag, args); + return file->RemoveAnalyzer(tag, std::move(args)); } File* Manager::GetFile(const string& file_id, Connection* conn, diff --git a/src/file_analysis/Manager.h b/src/file_analysis/Manager.h index 5086ab6e39..4f8874a0a1 100644 --- a/src/file_analysis/Manager.h +++ b/src/file_analysis/Manager.h @@ -253,6 +253,10 @@ public: * @return false if file identifier and analyzer did not map to anything, * else true. */ + bool SetExtractionLimit(const std::string& file_id, + IntrusivePtr args, uint64_t n) const; + + [[deprecated("Remove in v4.1. Pass IntrusivePtr args param instead.")]] bool SetExtractionLimit(const std::string& file_id, RecordVal* args, uint64_t n) const; @@ -273,6 +277,10 @@ public: * @param args a \c AnalyzerArgs value which describes a file analyzer. * @return false if the analyzer failed to be instantiated, else true. */ + bool AddAnalyzer(const std::string& file_id, const file_analysis::Tag& tag, + IntrusivePtr args) const; + + [[deprecated("Remove in v4.1. Pass IntrusivePtr args param instead.")]] bool AddAnalyzer(const std::string& file_id, const file_analysis::Tag& tag, RecordVal* args) const; @@ -283,6 +291,10 @@ public: * @param args a \c AnalyzerArgs value which describes a file analyzer. * @return true if the analyzer is active at the time of call, else false. */ + bool RemoveAnalyzer(const std::string& file_id, const file_analysis::Tag& tag, + IntrusivePtr args) const; + + [[deprecated("Remove in v4.1. Pass IntrusivePtr args param instead.")]] bool RemoveAnalyzer(const std::string& file_id, const file_analysis::Tag& tag, RecordVal* args) const; diff --git a/src/file_analysis/analyzer/extract/functions.bif b/src/file_analysis/analyzer/extract/functions.bif index 13cc904c4f..9d76849f23 100644 --- a/src/file_analysis/analyzer/extract/functions.bif +++ b/src/file_analysis/analyzer/extract/functions.bif @@ -12,7 +12,8 @@ function FileExtract::__set_limit%(file_id: string, args: any, n: count%): bool %{ using zeek::BifType::Record::Files::AnalyzerArgs; auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs); - bool result = file_mgr->SetExtractionLimit(file_id->CheckString(), rv.get(), n); + bool result = file_mgr->SetExtractionLimit(file_id->CheckString(), + std::move(rv), n); return val_mgr->Bool(result); %} diff --git a/src/file_analysis/file_analysis.bif b/src/file_analysis/file_analysis.bif index 909e9ed20f..7f60bc2845 100644 --- a/src/file_analysis/file_analysis.bif +++ b/src/file_analysis/file_analysis.bif @@ -44,7 +44,8 @@ function Files::__add_analyzer%(file_id: string, tag: Files::Tag, args: any%): b using zeek::BifType::Record::Files::AnalyzerArgs; auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs); bool result = file_mgr->AddAnalyzer(file_id->CheckString(), - file_mgr->GetComponentTag(tag), rv.get()); + file_mgr->GetComponentTag(tag), + std::move(rv)); return val_mgr->Bool(result); %} @@ -54,7 +55,8 @@ function Files::__remove_analyzer%(file_id: string, tag: Files::Tag, args: any%) using zeek::BifType::Record::Files::AnalyzerArgs; auto rv = args->AsRecordVal()->CoerceTo(AnalyzerArgs); bool result = file_mgr->RemoveAnalyzer(file_id->CheckString(), - file_mgr->GetComponentTag(tag) , rv.get()); + file_mgr->GetComponentTag(tag), + std::move(rv)); return val_mgr->Bool(result); %} From 46c5dea7332b710510328bb91f0b7da8d77d25e7 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 22 May 2020 17:48:35 -0700 Subject: [PATCH 125/151] Switch plugin::Manager::HookCallFunction() to return IntrusivePtr The plugin::Plugin side of things is not (yet) changed. --- src/Func.cc | 52 ++++++++++++++++++++++++------------------- src/Func.h | 5 +++-- src/plugin/Manager.cc | 15 ++++++++----- src/plugin/Manager.h | 13 ++++++----- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/Func.cc b/src/Func.cc index 99ec67496c..d391310ac3 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -59,7 +59,7 @@ extern RETSIGTYPE sig_handler(int signo); std::vector call_stack; bool did_builtin_init = false; -static const std::pair empty_hook_result(false, NULL); +static const std::pair> empty_hook_result(false, nullptr); std::string render_call_stack() { @@ -214,31 +214,34 @@ void Func::CopyStateInto(Func* other) const other->unique_id = unique_id; } -std::pair Func::HandlePluginResult(std::pair plugin_result, function_flavor flavor) const +void Func::CheckPluginResult(bool hooked, const IntrusivePtr& hook_result, + function_flavor flavor) const { // Helper function factoring out this code from BroFunc:Call() for // better readability. - if( ! plugin_result.first ) + if ( ! hooked ) { - if( plugin_result.second ) + if ( hook_result ) reporter->InternalError("plugin set processed flag to false but actually returned a value"); // The plugin result hasn't been processed yet (read: fall // into ::Call method). - return plugin_result; + return; } switch ( flavor ) { case FUNC_FLAVOR_EVENT: - if( plugin_result.second ) - reporter->InternalError("plugin returned non-void result for event %s", this->Name()); + if ( hook_result ) + reporter->InternalError("plugin returned non-void result for event %s", + this->Name()); break; case FUNC_FLAVOR_HOOK: - if ( plugin_result.second->GetType()->Tag() != TYPE_BOOL ) - reporter->InternalError("plugin returned non-bool for hook %s", this->Name()); + if ( hook_result->GetType()->Tag() != TYPE_BOOL ) + reporter->InternalError("plugin returned non-bool for hook %s", + this->Name()); break; @@ -248,21 +251,20 @@ std::pair Func::HandlePluginResult(std::pair plugin_resu if ( (! yt) || yt->Tag() == TYPE_VOID ) { - if( plugin_result.second ) - reporter->InternalError("plugin returned non-void result for void method %s", this->Name()); + if ( hook_result ) + reporter->InternalError("plugin returned non-void result for void method %s", + this->Name()); } - else if ( plugin_result.second && plugin_result.second->GetType()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY) + else if ( hook_result && hook_result->GetType()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY ) { reporter->InternalError("plugin returned wrong type (got %d, expecting %d) for %s", - plugin_result.second->GetType()->Tag(), yt->Tag(), this->Name()); + hook_result->GetType()->Tag(), yt->Tag(), this->Name()); } break; } } - - return plugin_result; } BroFunc::BroFunc(ID* arg_id, IntrusivePtr arg_body, id_list* aggr_inits, @@ -307,12 +309,14 @@ IntrusivePtr BroFunc::operator()(const zeek::Args& args, Frame* parent) con if ( sample_logger ) sample_logger->FunctionSeen(this); - std::pair plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), empty_hook_result); + auto [hooked, hook_result] = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, + HookCallFunction(this, parent, args), + empty_hook_result); - plugin_result = HandlePluginResult(plugin_result, Flavor()); + CheckPluginResult(hooked, hook_result, Flavor()); - if( plugin_result.first ) - return {AdoptRef{}, plugin_result.second}; + if ( hooked ) + return hook_result; if ( bodies.empty() ) { @@ -613,12 +617,14 @@ IntrusivePtr BuiltinFunc::operator()(const zeek::Args& args, Frame* parent) if ( sample_logger ) sample_logger->FunctionSeen(this); - std::pair plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), empty_hook_result); + auto [hooked, hook_result] = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, + HookCallFunction(this, parent, args), + empty_hook_result); - plugin_result = HandlePluginResult(plugin_result, FUNC_FLAVOR_FUNCTION); + CheckPluginResult(hooked, hook_result, FUNC_FLAVOR_FUNCTION); - if ( plugin_result.first ) - return {AdoptRef{}, plugin_result.second}; + if ( hooked ) + return hook_result; if ( g_trace_state.DoTrace() ) { diff --git a/src/Func.h b/src/Func.h index 1f0665ad54..848b7154bb 100644 --- a/src/Func.h +++ b/src/Func.h @@ -109,8 +109,9 @@ protected: // Copies this function's state into other. void CopyStateInto(Func* other) const; - // Helper function for handling result of plugin hook. - std::pair HandlePluginResult(std::pair plugin_result, function_flavor flavor) const; + // Helper function for checking result of plugin hook. + void CheckPluginResult(bool hooked, const IntrusivePtr& hook_result, + function_flavor flavor) const; std::vector bodies; IntrusivePtr scope; diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 084e421945..481cfcb14f 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -14,6 +14,7 @@ #include "../Reporter.h" #include "../Func.h" #include "../Event.h" +#include "../Val.h" #include "../util.h" #include "../input.h" @@ -621,7 +622,9 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const return rc; } -std::pair Manager::HookCallFunction(const Func* func, Frame* parent, const zeek::Args& vecargs) const +std::pair> +Manager::HookCallFunction(const Func* func, Frame* parent, + const zeek::Args& vecargs) const { HookArgumentList args; std::optional vargs; @@ -641,7 +644,7 @@ std::pair Manager::HookCallFunction(const Func* func, Frame* parent, hook_list* l = hooks[HOOK_CALL_FUNCTION]; - std::pair v = std::pair(false, NULL); + std::pair rval{false, nullptr}; if ( l ) { @@ -657,17 +660,17 @@ std::pair Manager::HookCallFunction(const Func* func, Frame* parent, { Plugin* p = (*i).second; - v = p->HookCallFunction(func, parent, &vargs.value()); + rval = p->HookCallFunction(func, parent, &vargs.value()); - if ( v.first ) + if ( rval.first ) break; } } if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_CALL_FUNCTION, args, HookArgument(v)); + MetaHookPost(HOOK_CALL_FUNCTION, args, HookArgument(rval)); - return v; + return {rval.first, {AdoptRef{}, rval.second}}; } bool Manager::HookQueueEvent(Event* event) const diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index f2e46ca68e..514ec347e0 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -245,15 +245,18 @@ public: * * @param func The function to be called. * + * @param parent The frame in which the function is being called. + * * @param args The function call's arguments; they may be modified by the * method. * - * @return If a plugin handled the call, a Val with a +1 reference count - * containing the result value to pass back to the interpreter (for void - * functions and events, it may be any Val and must be ignored). If no - * plugin handled the call, the method returns null. + * @return If a plugin handled the call, a Val representing the result + * to pass back to the interpreter (for void functions and events, + * it may be any Val and must be ignored). If no plugin handled the call, + * the method returns null. */ - std::pair HookCallFunction(const Func* func, Frame* parent, const zeek::Args& args) const; + std::pair> + HookCallFunction(const Func* func, Frame* parent, const zeek::Args& args) const; /** * Hook that filters the queuing of an event. From 272db640aaf07e99686d178279ef4792d799de34 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 22 May 2020 21:01:38 -0700 Subject: [PATCH 126/151] Deprecate Plugin::HookCallFunction(), replace with HookFunctionCall() This also changes the argument type of Func::operator() to zeek::Args* to allow plugins to be able to alter function arguments in place as was previously documented. --- NEWS | 5 + src/Discard.cc | 8 +- src/Event.cc | 2 +- src/EventHandler.cc | 14 +-- src/EventHandler.h | 4 +- src/Expr.cc | 3 +- src/Func.cc | 51 +++++---- src/Func.h | 13 ++- src/RuleCondition.cc | 2 +- src/Val.cc | 6 +- src/broker/messaging.bif | 4 +- src/input/Manager.cc | 2 +- src/option.bif | 2 +- src/plugin/Manager.cc | 29 ++--- src/plugin/Manager.h | 2 +- src/plugin/Plugin.cc | 31 ++++++ src/plugin/Plugin.h | 28 ++++- .../btest/Baseline/plugins.func-hook/output | 4 + .../Baseline/plugins.legacy-func-hook/output | 4 + .../plugins/func-hook-plugin/.btest-ignore | 0 .../plugins/func-hook-plugin/src/Plugin.cc | 86 ++++++++++++++ .../plugins/func-hook-plugin/src/Plugin.h | 27 +++++ testing/btest/plugins/func-hook.zeek | 17 +++ .../legacy-func-hook-plugin/.btest-ignore | 0 .../legacy-func-hook-plugin/src/Plugin.cc | 105 ++++++++++++++++++ .../legacy-func-hook-plugin/src/Plugin.h | 28 +++++ testing/btest/plugins/legacy-func-hook.zeek | 17 +++ 27 files changed, 417 insertions(+), 77 deletions(-) create mode 100644 testing/btest/Baseline/plugins.func-hook/output create mode 100644 testing/btest/Baseline/plugins.legacy-func-hook/output create mode 100644 testing/btest/plugins/func-hook-plugin/.btest-ignore create mode 100644 testing/btest/plugins/func-hook-plugin/src/Plugin.cc create mode 100644 testing/btest/plugins/func-hook-plugin/src/Plugin.h create mode 100644 testing/btest/plugins/func-hook.zeek create mode 100644 testing/btest/plugins/legacy-func-hook-plugin/.btest-ignore create mode 100644 testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.cc create mode 100644 testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.h create mode 100644 testing/btest/plugins/legacy-func-hook.zeek diff --git a/NEWS b/NEWS index bb8e6e3ebf..297c60ee50 100644 --- a/NEWS +++ b/NEWS @@ -106,6 +106,11 @@ Removed Functionality Deprecated Functionality ------------------------ +- The ``plugin::Plugin::HookCallFunction()`` method is deprecated. Note + that compilers will not emit a deprecation warning, but the replacement + method to now use is called ``HookFunctionCall`` and uses ``IntrusivePtr`` + arguments and return value. + - The ``Func::Call(val_list*, ...)`` method is now deprecated. Use operator() instead which takes a ``zeek::Args`` (``std::vector>``). There's also a variadic template for operator() that forwards all arguments diff --git a/src/Discard.cc b/src/Discard.cc index 1984ced575..c5563f1cd8 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -43,7 +43,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_ip->operator()(args)->AsBool(); + discard_packet = check_ip->operator()(&args)->AsBool(); } catch ( InterpreterException& e ) @@ -98,7 +98,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_tcp->operator()(args)->AsBool(); + discard_packet = check_tcp->operator()(&args)->AsBool(); } catch ( InterpreterException& e ) @@ -122,7 +122,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_udp->operator()(args)->AsBool(); + discard_packet = check_udp->operator()(&args)->AsBool(); } catch ( InterpreterException& e ) @@ -142,7 +142,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_icmp->operator()(args)->AsBool(); + discard_packet = check_icmp->operator()(&args)->AsBool(); } catch ( InterpreterException& e ) diff --git a/src/Event.cc b/src/Event.cc index 11e34b0117..0f8c3b468b 100644 --- a/src/Event.cc +++ b/src/Event.cc @@ -56,7 +56,7 @@ void Event::Dispatch(bool no_remote) try { - handler->Call(args, no_remote); + handler->Call(&args, no_remote); } catch ( InterpreterException& e ) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 3be382b561..5e75fa6731 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -44,7 +44,7 @@ const IntrusivePtr& EventHandler::GetType(bool check_export) return type; } -void EventHandler::Call(const zeek::Args& vl, bool no_remote) +void EventHandler::Call(zeek::Args* vl, bool no_remote) { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Event: %s\n", Name()); @@ -59,12 +59,12 @@ void EventHandler::Call(const zeek::Args& vl, bool no_remote) { // Send event in form [name, xs...] where xs represent the arguments. broker::vector xs; - xs.reserve(vl.size()); + xs.reserve(vl->size()); bool valid_args = true; - for ( auto i = 0u; i < vl.size(); ++i ) + for ( auto i = 0u; i < vl->size(); ++i ) { - auto opt_data = bro_broker::val_to_data(vl[i].get()); + auto opt_data = bro_broker::val_to_data((*vl)[i].get()); if ( opt_data ) xs.emplace_back(std::move(*opt_data)); @@ -101,7 +101,7 @@ void EventHandler::Call(const zeek::Args& vl, bool no_remote) local->operator()(vl); } -void EventHandler::NewEvent(const zeek::Args& vl) +void EventHandler::NewEvent(zeek::Args* vl) { if ( ! new_event ) return; @@ -132,8 +132,8 @@ void EventHandler::NewEvent(const zeek::Args& vl) if ( fdefault ) rec->Assign(2, std::move(fdefault)); - if ( i < static_cast(vl.size()) && vl[i] ) - rec->Assign(3, vl[i]); + if ( i < static_cast(vl->size()) && (*vl)[i] ) + rec->Assign(3, (*vl)[i]); vargs->Assign(i, std::move(rec)); } diff --git a/src/EventHandler.h b/src/EventHandler.h index ccbd90e44b..c2a053cac8 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -45,7 +45,7 @@ public: auto_publish.erase(topic); } - void Call(const zeek::Args& vl, bool no_remote = false); + void Call(zeek::Args* vl, bool no_remote = false); // Returns true if there is at least one local or remote handler. explicit operator bool() const; @@ -66,7 +66,7 @@ public: bool GenerateAlways() { return generate_always; } private: - void NewEvent(const zeek::Args& vl); // Raise new_event() meta event. + void NewEvent(zeek::Args* vl); // Raise new_event() meta event. std::string name; IntrusivePtr local; diff --git a/src/Expr.cc b/src/Expr.cc index 4aa6bd0f30..4c1492e2d1 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4133,7 +4133,8 @@ IntrusivePtr CallExpr::Eval(Frame* f) const if ( f ) f->SetCall(this); - ret = funcv->operator()(*v, f); + auto& args = *v; + ret = funcv->operator()(&args, f); if ( f ) f->SetCall(current_call); diff --git a/src/Func.cc b/src/Func.cc index d391310ac3..ec30fcc2b0 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -214,13 +214,13 @@ void Func::CopyStateInto(Func* other) const other->unique_id = unique_id; } -void Func::CheckPluginResult(bool hooked, const IntrusivePtr& hook_result, +void Func::CheckPluginResult(bool handled, const IntrusivePtr& hook_result, function_flavor flavor) const { // Helper function factoring out this code from BroFunc:Call() for // better readability. - if ( ! hooked ) + if ( ! handled ) { if ( hook_result ) reporter->InternalError("plugin set processed flag to false but actually returned a value"); @@ -297,9 +297,12 @@ bool BroFunc::IsPure() const } Val* Func::Call(val_list* args, Frame* parent) const - { return operator()(zeek::val_list_to_args(*args), parent).release(); }; + { + auto zargs = zeek::val_list_to_args(*args); + return operator()(&zargs, parent).release(); + }; -IntrusivePtr BroFunc::operator()(const zeek::Args& args, Frame* parent) const +IntrusivePtr BroFunc::operator()(zeek::Args* args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -309,13 +312,13 @@ IntrusivePtr BroFunc::operator()(const zeek::Args& args, Frame* parent) con if ( sample_logger ) sample_logger->FunctionSeen(this); - auto [hooked, hook_result] = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, - HookCallFunction(this, parent, args), - empty_hook_result); + auto [handled, hook_result] = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, + HookCallFunction(this, parent, args), + empty_hook_result); - CheckPluginResult(hooked, hook_result, Flavor()); + CheckPluginResult(handled, hook_result, Flavor()); - if ( hooked ) + if ( handled ) return hook_result; if ( bodies.empty() ) @@ -325,7 +328,7 @@ IntrusivePtr BroFunc::operator()(const zeek::Args& args, Frame* parent) con return Flavor() == FUNC_FLAVOR_HOOK ? val_mgr->True() : nullptr; } - auto f = make_intrusive(frame_size, this, &args); + auto f = make_intrusive(frame_size, this, args); if ( closure ) f->CaptureClosure(closure, outer_ids); @@ -339,12 +342,12 @@ IntrusivePtr BroFunc::operator()(const zeek::Args& args, Frame* parent) con g_frame_stack.push_back(f.get()); // used for backtracing const CallExpr* call_expr = parent ? parent->GetCall() : nullptr; - call_stack.emplace_back(CallInfo{call_expr, this, args}); + call_stack.emplace_back(CallInfo{call_expr, this, *args}); if ( g_trace_state.DoTrace() ) { ODesc d; - DescribeDebug(&d, &args); + DescribeDebug(&d, args); g_trace_state.LogTrace("%s called: %s\n", GetType()->FlavorString().c_str(), d.Description()); @@ -360,16 +363,16 @@ IntrusivePtr BroFunc::operator()(const zeek::Args& args, Frame* parent) con body.stmts->GetLocationInfo()); // Fill in the rest of the frame with the function's arguments. - for ( auto j = 0u; j < args.size(); ++j ) + for ( auto j = 0u; j < args->size(); ++j ) { - Val* arg = args[j].get(); + Val* arg = (*args)[j].get(); if ( f->NthElement(j) != arg ) // Either not yet set, or somebody reassigned the frame slot. f->SetElement(j, arg->Ref()); } - f->Reset(args.size()); + f->Reset(args->size()); try { @@ -607,7 +610,7 @@ bool BuiltinFunc::IsPure() const return is_pure; } -IntrusivePtr BuiltinFunc::operator()(const zeek::Args& args, Frame* parent) const +IntrusivePtr BuiltinFunc::operator()(zeek::Args* args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -617,26 +620,26 @@ IntrusivePtr BuiltinFunc::operator()(const zeek::Args& args, Frame* parent) if ( sample_logger ) sample_logger->FunctionSeen(this); - auto [hooked, hook_result] = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, - HookCallFunction(this, parent, args), - empty_hook_result); + auto [handled, hook_result] = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, + HookCallFunction(this, parent, args), + empty_hook_result); - CheckPluginResult(hooked, hook_result, FUNC_FLAVOR_FUNCTION); + CheckPluginResult(handled, hook_result, FUNC_FLAVOR_FUNCTION); - if ( hooked ) + if ( handled ) return hook_result; if ( g_trace_state.DoTrace() ) { ODesc d; - DescribeDebug(&d, &args); + DescribeDebug(&d, args); g_trace_state.LogTrace("\tBuiltin Function called: %s\n", d.Description()); } const CallExpr* call_expr = parent ? parent->GetCall() : nullptr; - call_stack.emplace_back(CallInfo{call_expr, this, args}); - auto result = std::move(func(parent, &args).rval); + call_stack.emplace_back(CallInfo{call_expr, this, *args}); + auto result = std::move(func(parent, args).rval); call_stack.pop_back(); if ( result && g_trace_state.DoTrace() ) diff --git a/src/Func.h b/src/Func.h index 848b7154bb..ef2cf34fab 100644 --- a/src/Func.h +++ b/src/Func.h @@ -60,7 +60,7 @@ public: * @param parent the frame from which the function is being called. * @return the return value of the function call. */ - virtual IntrusivePtr operator()(const zeek::Args& args, + virtual IntrusivePtr operator()(zeek::Args* args, Frame* parent = nullptr) const = 0; /** @@ -72,7 +72,10 @@ public: IntrusivePtr>, IntrusivePtr> operator()(Args&&... args) const - { return operator()(zeek::Args{std::forward(args)...}); } + { + auto zargs = zeek::Args{std::forward(args)...}; + return operator()(&zargs); + } // Add a new event handler to an existing function (event). virtual void AddBody(IntrusivePtr new_body, id_list* new_inits, @@ -110,7 +113,7 @@ protected: void CopyStateInto(Func* other) const; // Helper function for checking result of plugin hook. - void CheckPluginResult(bool hooked, const IntrusivePtr& hook_result, + void CheckPluginResult(bool handled, const IntrusivePtr& hook_result, function_flavor flavor) const; std::vector bodies; @@ -129,7 +132,7 @@ public: ~BroFunc() override; bool IsPure() const override; - IntrusivePtr operator()(const zeek::Args& args, Frame* parent) const override; + IntrusivePtr operator()(zeek::Args* args, Frame* parent) const override; /** * Adds adds a closure to the function. Closures are cloned and @@ -225,7 +228,7 @@ public: ~BuiltinFunc() override; bool IsPure() const override; - IntrusivePtr operator()(const zeek::Args& args, Frame* parent) const override; + IntrusivePtr operator()(zeek::Args* args, Frame* parent) const override; built_in_func TheFunc() const { return func; } void Describe(ODesc* d) const override; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index ed179f1c85..c66d3a3b3f 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -181,7 +181,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, try { - auto val = id->GetVal()->AsFunc()->operator()(args); + auto val = id->GetVal()->AsFunc()->operator()(&args); result = val && val->AsBool(); } diff --git a/src/Val.cc b/src/Val.cc index 858ee40cdc..4fa0733091 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1879,7 +1879,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) try { - result = f->operator()(vl); + result = f->operator()(&vl); } catch ( InterpreterException& e ) @@ -2088,7 +2088,7 @@ void TableVal::CallChangeFunc(const Val* index, vl.emplace_back(old_value); in_change_func = true; - f->operator()(vl); + f->operator()(&vl); } catch ( InterpreterException& e ) { @@ -2545,7 +2545,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) vl.emplace_back(std::move(idx)); } - auto result = f->operator()(vl); + auto result = f->operator()(&vl); if ( result ) secs = result->AsInterval(); diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index 6416fa7d41..14d6c43219 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -188,7 +188,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool topic_func = global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; - auto topic = topic_func->operator()(vl); + auto topic = topic_func->operator()(&vl); if ( ! topic->AsString()->Len() ) return val_mgr->False(); @@ -225,7 +225,7 @@ function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool topic_func = global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; - auto topic = topic_func->operator()(vl); + auto topic = topic_func->operator()(&vl); if ( ! topic->AsString()->Len() ) return val_mgr->False(); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index d24dd960b3..88b30f098f 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1768,7 +1768,7 @@ bool Manager::CallPred(Func* pred_func, const int numvals, ...) const va_end(lP); - auto v = pred_func->operator()(vl); + auto v = pred_func->operator()(&vl); if ( v ) result = v->AsBool(); diff --git a/src/option.bif b/src/option.bif index 14c65c1d50..91d5509c3c 100644 --- a/src/option.bif +++ b/src/option.bif @@ -24,7 +24,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, const IntrusiveP if ( add_loc ) vl.emplace_back(NewRef{}, location); - val = handler_function->operator()(vl); // consumed by next call. + val = handler_function->operator()(&vl); // consumed by next call. if ( ! val ) { diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 481cfcb14f..09a3bb5d9f 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -624,43 +624,35 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const std::pair> Manager::HookCallFunction(const Func* func, Frame* parent, - const zeek::Args& vecargs) const + zeek::Args* vecargs) const { HookArgumentList args; - std::optional vargs; + val_list vargs; if ( HavePluginForHook(META_HOOK_PRE) ) { - vargs = val_list(vecargs.size()); + vargs.resize(vecargs->size()); - for ( const auto& v : vecargs ) - vargs->push_back(v.get()); + for ( const auto& v : *vecargs ) + vargs.push_back(v.get()); args.push_back(HookArgument(func)); args.push_back(HookArgument(parent)); - args.push_back(HookArgument(&vargs.value())); + args.push_back(HookArgument(&vargs)); MetaHookPre(HOOK_CALL_FUNCTION, args); } hook_list* l = hooks[HOOK_CALL_FUNCTION]; - std::pair rval{false, nullptr}; + std::pair> rval{false, nullptr}; if ( l ) { - if ( ! vargs ) - { - vargs = val_list(vecargs.size()); - - for ( const auto& v : vecargs ) - vargs->push_back(v.get()); - } - for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) { Plugin* p = (*i).second; - rval = p->HookCallFunction(func, parent, &vargs.value()); + rval = p->HookFunctionCall(func, parent, vecargs); if ( rval.first ) break; @@ -668,9 +660,10 @@ Manager::HookCallFunction(const Func* func, Frame* parent, } if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_CALL_FUNCTION, args, HookArgument(rval)); + MetaHookPost(HOOK_CALL_FUNCTION, args, + HookArgument(std::make_pair(rval.first, rval.second.get()))); - return {rval.first, {AdoptRef{}, rval.second}}; + return rval; } bool Manager::HookQueueEvent(Event* event) const diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index 514ec347e0..b3080cf733 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -256,7 +256,7 @@ public: * the method returns null. */ std::pair> - HookCallFunction(const Func* func, Frame* parent, const zeek::Args& args) const; + HookCallFunction(const Func* func, Frame* parent, zeek::Args* args) const; /** * Hook that filters the queuing of an event. diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index 5538b87b28..262ee2cc64 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -151,6 +151,17 @@ void HookArgument::Describe(ODesc* d) const d->Add(""); break; + case ARG_LIST: + if ( arg.args) + { + d->Add("("); + describe_vals(*arg.args, d); + d->Add(")"); + } + else + d->Add(""); + break; + case VOID: d->Add(""); break; @@ -364,6 +375,26 @@ int Plugin::HookLoadFile(const LoadType type, const std::string& file, const std return -1; } +std::pair> +Plugin::HookFunctionCall(const Func* func, Frame* parent, + zeek::Args* args) + { + val_list vlargs(args->size()); + + for ( auto& v : *args ) + vlargs.push_back(v.release()); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + auto [handled, result] = HookCallFunction(func, parent, &vlargs); +#pragma GCC diagnostic pop + + for ( auto i = 0u; i < args->size(); ++i ) + (*args)[i] = {AdoptRef{}, vlargs[i]}; + + return {handled, {AdoptRef{}, result}}; + } + std::pair Plugin::HookCallFunction(const Func* func, Frame *parent, val_list* args) { std::pair result(false, NULL); diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index b218c693d7..096b796429 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -8,6 +8,7 @@ #include "zeek-config.h" #include "logging/WriterBackend.h" +#include "ZeekArgs.h" // Increase this when making incompatible changes to the plugin API. Note // that the constant is never used in C code. It's picked up on by CMake. @@ -177,7 +178,8 @@ public: */ enum Type { BOOL, DOUBLE, EVENT, FRAME, FUNC, FUNC_RESULT, INT, STRING, VAL, - VAL_LIST, VOID, VOIDP, WRITER_INFO, CONN, THREAD_FIELDS, LOCATION + VAL_LIST, VOID, VOIDP, WRITER_INFO, CONN, THREAD_FIELDS, LOCATION, + ARG_LIST }; /** @@ -260,6 +262,11 @@ public: */ explicit HookArgument(const Location* location) { type = LOCATION; arg.loc = location; } + /** + * Constructor with a zeek::Args argument. + */ + explicit HookArgument(const zeek::Args* args) { type = ARG_LIST; arg.args = args; } + /** * Returns the value for a boolen argument. The argument's type must * match accordingly. @@ -338,6 +345,11 @@ public: */ const val_list* AsValList() const { assert(type == VAL_LIST); return arg.vals; } + /** + * Returns the value as a zeek::Args. + */ + const zeek::Args* AsArgList() const { assert(type == ARG_LIST); return arg.args; } + /** * Returns the value for a vod pointer argument. The argument's type * must match accordingly. @@ -368,6 +380,7 @@ private: int int_; const Val* val; const val_list* vals; + const zeek::Args* args; const void* voidp; const logging::WriterBackend::WriterInfo* winfo; const Location* loc; @@ -664,12 +677,15 @@ protected: * in place as long as it ensures matching types and correct reference * counting. * - * @return If the plugin handled the call, a std::pair with the - * processed flag set to true, and a value set on the object with - * a+1 reference count containing the result value to pass back to the - * interpreter. If the plugin did not handle the call, it must - * return a pair with the processed flag set to 'false'. + * @return If the plugin handled the call, a pair with the first member + * set to true, and a Val representing the result value to pass back to the + * interpreter. If the plugin did not handle the call, it must return a + * pair with the first member set to 'false' and null result value. */ + virtual std::pair> + HookFunctionCall(const Func* func, Frame* parent, zeek::Args* args); + + [[deprecated("Remove in v4.1. Use HookFunctionCall()")]] virtual std::pair HookCallFunction(const Func* func, Frame *parent, val_list* args); /** diff --git a/testing/btest/Baseline/plugins.func-hook/output b/testing/btest/Baseline/plugins.func-hook/output new file mode 100644 index 0000000000..21e27b43c0 --- /dev/null +++ b/testing/btest/Baseline/plugins.func-hook/output @@ -0,0 +1,4 @@ +1590206064.237264 MetaHookPre CallFunction(foo, , (1, 2, 3, yo)) +1590206064.237264 | HookFunctionCall foo(1, 2, 3, yo) +1590206064.237264 MetaHookPost CallFunction(foo, , (1, 2, 3, yo)) -> +foo, 42, 2, 3, yo diff --git a/testing/btest/Baseline/plugins.legacy-func-hook/output b/testing/btest/Baseline/plugins.legacy-func-hook/output new file mode 100644 index 0000000000..1d00ed4d5d --- /dev/null +++ b/testing/btest/Baseline/plugins.legacy-func-hook/output @@ -0,0 +1,4 @@ +1590205948.002795 MetaHookPre CallFunction(foo, , (1, 2, 3, yo)) +1590205948.002795 | HookCallFunction foo(1, 2, 3, yo) +1590205948.002795 MetaHookPost CallFunction(foo, , (1, 2, 3, yo)) -> +foo, 13, 2, 3, yo diff --git a/testing/btest/plugins/func-hook-plugin/.btest-ignore b/testing/btest/plugins/func-hook-plugin/.btest-ignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testing/btest/plugins/func-hook-plugin/src/Plugin.cc b/testing/btest/plugins/func-hook-plugin/src/Plugin.cc new file mode 100644 index 0000000000..f1b089e65e --- /dev/null +++ b/testing/btest/plugins/func-hook-plugin/src/Plugin.cc @@ -0,0 +1,86 @@ + +#include "Plugin.h" + +#include +#include +#include +#include +#include +#include + +namespace plugin { namespace Demo_Hooks { Plugin plugin; } } + +using namespace plugin::Demo_Hooks; + +plugin::Configuration Plugin::Configure() + { + EnableHook(HOOK_CALL_FUNCTION); + EnableHook(META_HOOK_PRE); + EnableHook(META_HOOK_POST); + + plugin::Configuration config; + config.name = "Demo::Hooks"; + config.description = "Exercises all plugin hooks"; + config.version.major = 1; + config.version.minor = 0; + config.version.patch = 0; + return config; + } + +static void describe_hook_args(const plugin::HookArgumentList& args, ODesc* d) + { + bool first = true; + + for ( plugin::HookArgumentList::const_iterator i = args.begin(); i != args.end(); i++ ) + { + if ( ! first ) + d->Add(", "); + + i->Describe(d); + first = false; + } + } + +std::pair> Plugin::HookFunctionCall(const Func* func, + Frame* frame, + zeek::Args* args) + { + ODesc d; + d.SetShort(); + HookArgument(func).Describe(&d); + HookArgument(args).Describe(&d); + fprintf(stderr, "%.6f %-15s %s\n", network_time, "| HookFunctionCall", + d.Description()); + + if ( streq(func->Name(), "foo") ) + { + auto& vl = *args; + vl[0] = val_mgr->Count(42); + } + + return {}; + } + +void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) + { + ODesc d; + d.SetShort(); + describe_hook_args(args, &d); + fprintf(stderr, "%.6f %-15s %s(%s)\n", network_time, " MetaHookPre", + hook_name(hook), d.Description()); + } + +void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) + { + ODesc d1; + d1.SetShort(); + describe_hook_args(args, &d1); + + ODesc d2; + d2.SetShort(); + result.Describe(&d2); + + fprintf(stderr, "%.6f %-15s %s(%s) -> %s\n", network_time, " MetaHookPost", + hook_name(hook), d1.Description(), + d2.Description()); + } diff --git a/testing/btest/plugins/func-hook-plugin/src/Plugin.h b/testing/btest/plugins/func-hook-plugin/src/Plugin.h new file mode 100644 index 0000000000..c480466e9e --- /dev/null +++ b/testing/btest/plugins/func-hook-plugin/src/Plugin.h @@ -0,0 +1,27 @@ + +#pragma once + +#include + +namespace plugin { +namespace Demo_Hooks { + +class Plugin : public ::plugin::Plugin +{ +protected: + + std::pair> HookFunctionCall(const Func* func, + Frame* frame, + zeek::Args* args) override; + + void MetaHookPre(HookType hook, const HookArgumentList& args) override; + void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) override; + + // Overridden from plugin::Plugin. + plugin::Configuration Configure() override; +}; + +extern Plugin plugin; + +} +} diff --git a/testing/btest/plugins/func-hook.zeek b/testing/btest/plugins/func-hook.zeek new file mode 100644 index 0000000000..5a9d2c6e48 --- /dev/null +++ b/testing/btest/plugins/func-hook.zeek @@ -0,0 +1,17 @@ +# @TEST-EXEC: ${DIST}/aux/zeek-aux/plugin-support/init-plugin -u . Demo Hooks +# @TEST-EXEC: cp -r %DIR/func-hook-plugin/* . +# @TEST-EXEC: ./configure --zeek-dist=${DIST} && make +# @TEST-EXEC: ZEEK_PLUGIN_ACTIVATE="Demo::Hooks" ZEEK_PLUGIN_PATH=`pwd` zeek -b %INPUT 2>&1 | grep foo >output +# @TEST-EXEC: btest-diff output + +@unload base/misc/version + +function foo(a: count, b: count, c: count, s: string) + { + print "foo", a, b, c, s; + } + +event zeek_init() + { + foo(1, 2, 3, "yo"); + } diff --git a/testing/btest/plugins/legacy-func-hook-plugin/.btest-ignore b/testing/btest/plugins/legacy-func-hook-plugin/.btest-ignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.cc b/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.cc new file mode 100644 index 0000000000..c4f06fc651 --- /dev/null +++ b/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.cc @@ -0,0 +1,105 @@ + +#include "Plugin.h" + +#include +#include +#include +#include +#include +#include + +namespace plugin { namespace Demo_Hooks { Plugin plugin; } } + +using namespace plugin::Demo_Hooks; + +plugin::Configuration Plugin::Configure() + { + EnableHook(HOOK_CALL_FUNCTION); + EnableHook(META_HOOK_PRE); + EnableHook(META_HOOK_POST); + + plugin::Configuration config; + config.name = "Demo::Hooks"; + config.description = "Exercises all plugin hooks"; + config.version.major = 1; + config.version.minor = 0; + config.version.patch = 0; + return config; + } + +static void describe_hook_args(const plugin::HookArgumentList& args, ODesc* d) + { + bool first = true; + + for ( plugin::HookArgumentList::const_iterator i = args.begin(); i != args.end(); i++ ) + { + if ( ! first ) + d->Add(", "); + + i->Describe(d); + first = false; + } + } + +std::pair Plugin::HookCallFunction(const Func* func, Frame* frame, val_list* args) + { + ODesc d; + d.SetShort(); + HookArgument(func).Describe(&d); + HookArgument(args).Describe(&d); + fprintf(stderr, "%.6f %-15s %s\n", network_time, "| HookCallFunction", + d.Description()); + + if ( streq(func->Name(), "foo") ) + { + auto& vl = *args; + Unref(vl[0]); + vl[0] = val_mgr->Count(13).release(); + } + + return {}; + } + +/* std::pair> Plugin::HookFunctionCall(const Func* func, */ +/* Frame* frame, */ +/* zeek::Args* args) */ +/* { */ +/* ODesc d; */ +/* d.SetShort(); */ +/* HookArgument(func).Describe(&d); */ +/* HookArgument(args).Describe(&d); */ +/* fprintf(stderr, "%.6f %-15s %s\n", network_time, "| HookFunctionCall", */ +/* d.Description()); */ + +/* if ( streq(func->Name(), "foo") ) */ +/* { */ +/* auto& vl = *args; */ +/* vl[0] = val_mgr->Count(42); */ +/* } */ + +/* return {}; */ +/* } */ + +void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) + { + ODesc d; + d.SetShort(); + describe_hook_args(args, &d); + fprintf(stderr, "%.6f %-15s %s(%s)\n", network_time, " MetaHookPre", + hook_name(hook), d.Description()); + } + +void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) + { + ODesc d1; + d1.SetShort(); + describe_hook_args(args, &d1); + + ODesc d2; + d2.SetShort(); + result.Describe(&d2); + + fprintf(stderr, "%.6f %-15s %s(%s) -> %s\n", network_time, " MetaHookPost", + hook_name(hook), d1.Description(), + d2.Description()); + } diff --git a/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.h b/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.h new file mode 100644 index 0000000000..305192b31e --- /dev/null +++ b/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.h @@ -0,0 +1,28 @@ + +#pragma once + +#include + +namespace plugin { +namespace Demo_Hooks { + +class Plugin : public ::plugin::Plugin +{ +protected: + std::pair HookCallFunction(const Func* func, Frame* frame, val_list* args) override; + + /* std::pair> HookFunctionCall(const Func* func, */ + /* Frame* frame, */ + /* zeek::Args* args) override; */ + + void MetaHookPre(HookType hook, const HookArgumentList& args) override; + void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) override; + + // Overridden from plugin::Plugin. + plugin::Configuration Configure() override; +}; + +extern Plugin plugin; + +} +} diff --git a/testing/btest/plugins/legacy-func-hook.zeek b/testing/btest/plugins/legacy-func-hook.zeek new file mode 100644 index 0000000000..75e6301d6f --- /dev/null +++ b/testing/btest/plugins/legacy-func-hook.zeek @@ -0,0 +1,17 @@ +# @TEST-EXEC: ${DIST}/aux/zeek-aux/plugin-support/init-plugin -u . Demo Hooks +# @TEST-EXEC: cp -r %DIR/legacy-func-hook-plugin/* . +# @TEST-EXEC: ./configure --zeek-dist=${DIST} && make +# @TEST-EXEC: ZEEK_PLUGIN_ACTIVATE="Demo::Hooks" ZEEK_PLUGIN_PATH=`pwd` zeek -b %INPUT 2>&1 | grep foo >output +# @TEST-EXEC: btest-diff output + +@unload base/misc/version + +function foo(a: count, b: count, c: count, s: string) + { + print "foo", a, b, c, s; + } + +event zeek_init() + { + foo(1, 2, 3, "yo"); + } From 1c617c4f7a4498f245d4bbf4c925925707e68e90 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 22 May 2020 23:42:42 -0700 Subject: [PATCH 127/151] Store IntrusivePtrs in Frame --- src/Frame.cc | 48 ++++++++++++++++++++---------------------------- src/Frame.h | 11 +++-------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/Frame.cc b/src/Frame.cc index cecea12385..70eb1118d3 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -17,7 +17,7 @@ std::vector g_frame_stack; Frame::Frame(int arg_size, const BroFunc* func, const zeek::Args* fn_args) { size = arg_size; - frame = new Val*[size]; + frame = std::make_unique[]>(size); function = func; func_args = fn_args; @@ -29,9 +29,6 @@ Frame::Frame(int arg_size, const BroFunc* func, const zeek::Args* fn_args) delayed = false; closure = nullptr; - - for (int i = 0; i < size; ++i) - frame[i] = nullptr; } Frame::~Frame() @@ -51,7 +48,8 @@ Frame::~Frame() for ( auto& i : outer_ids ) Unref(i); - Release(); + for ( int i = 0; i < size; ++i ) + UnrefElement(i); delete [] weak_refs; } @@ -69,7 +67,7 @@ void Frame::AddFunctionWithClosureRef(BroFunc* func) void Frame::SetElement(int n, Val* v, bool weak_ref) { UnrefElement(n); - frame[n] = v; + frame[n] = {AdoptRef{}, v}; if ( weak_ref ) { @@ -132,10 +130,10 @@ Val* Frame::GetElement(const ID* id) const { auto where = offset_map->find(std::string(id->Name())); if ( where != offset_map->end() ) - return frame[where->second]; + return frame[where->second].get(); } - return frame[id->Offset()]; + return frame[id->Offset()].get(); } void Frame::Reset(int startIdx) @@ -147,14 +145,6 @@ void Frame::Reset(int startIdx) } } -void Frame::Release() - { - for ( int i = 0; i < size; ++i ) - UnrefElement(i); - - delete [] frame; - } - void Frame::Describe(ODesc* d) const { if ( ! d->IsBinary() ) @@ -190,13 +180,14 @@ Frame* Frame::Clone() const other->call = call; other->trigger = trigger; - for (int i = 0; i < size; i++) - other->frame[i] = frame[i] ? frame[i]->Clone().release() : nullptr; + for ( int i = 0; i < size; i++ ) + if ( frame[i] ) + other->frame[i] = frame[i]->Clone(); return other; } -static bool val_is_func(Val* v, BroFunc* func) +static bool val_is_func(const IntrusivePtr& v, BroFunc* func) { if ( v->GetType()->Tag() != TYPE_FUNC ) return false; @@ -204,17 +195,18 @@ static bool val_is_func(Val* v, BroFunc* func) return v->AsFunc() == func; } -static void clone_if_not_func(Val** frame, int offset, BroFunc* func, +static void clone_if_not_func(const std::unique_ptr[]>& frame, + int offset, BroFunc* func, Frame* other) { - auto v = frame[offset]; + const auto& v = frame[offset]; if ( ! v ) return; if ( val_is_func(v, func) ) { - other->SetElement(offset, v, true); + other->SetElement(offset, v.get(), true); return; } @@ -355,11 +347,11 @@ broker::expected Frame::Serialize(const Frame* target, const id_li if (where != new_map.end()) location = where->second; - Val* val = target->frame[location]; + const auto& val = target->frame[location]; TypeTag tag = val->GetType()->Tag(); - auto expected = bro_broker::val_to_data(val); + auto expected = bro_broker::val_to_data(val.get()); if ( ! expected ) return broker::ec::invalid_data; @@ -490,7 +482,7 @@ std::pair> Frame::Unserialize(const broker::vector& da if ( ! val ) return std::make_pair(false, nullptr); - rf->frame[i] = val.release(); + rf->frame[i] = std::move(val); } return std::make_pair(true, std::move(rf)); @@ -542,9 +534,9 @@ void Frame::ClearTrigger() void Frame::UnrefElement(int n) { if ( weak_refs && weak_refs[n] ) - return; - - Unref(frame[n]); + frame[n].release(); + else + frame[n] = nullptr; } bool Frame::IsOuterID(const ID* in) const diff --git a/src/Frame.h b/src/Frame.h index 8716022d6e..3880159aec 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,7 @@ public: * @param n the index to get. * @return the value at index *n* of the underlying array. */ - Val* NthElement(int n) const { return frame[n]; } + Val* NthElement(int n) const { return frame[n].get(); } /** * Sets the element at index *n* of the underlying array @@ -81,12 +82,6 @@ public: */ void Reset(int startIdx); - /** - * Resets all of the values in the frame and clears out the - * underlying array. - */ - void Release(); - /** * Describes the frame and all of its values. */ @@ -269,7 +264,7 @@ private: bool delayed; /** Associates ID's offsets with values. */ - Val** frame; + std::unique_ptr[]> frame; /** Values that are weakly referenced by the frame. Used to * prevent circular reference memory leaks in lambda/closures */ From e9e2e388f8eb8354237467a0c36f3b0c3dae2ff4 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 23 May 2020 00:47:52 -0700 Subject: [PATCH 128/151] Switch Frame::SetElement() to use IntrusivePtr --- src/Expr.cc | 2 +- src/Frame.cc | 70 +++++++++++++++++++++++++++------------------------- src/Frame.h | 39 ++++++++++++++++++++--------- src/Func.cc | 4 +-- src/Stmt.cc | 23 ++++++++--------- 5 files changed, 78 insertions(+), 60 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 4c1492e2d1..68e10a9a90 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -273,7 +273,7 @@ void NameExpr::Assign(Frame* f, IntrusivePtr v) if ( id->IsGlobal() ) id->SetVal(std::move(v)); else - f->SetElement(id.get(), v.release()); + f->SetElement(id.get(), std::move(v)); } bool NameExpr::IsPure() const diff --git a/src/Frame.cc b/src/Frame.cc index 70eb1118d3..2217dea187 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -49,7 +49,7 @@ Frame::~Frame() Unref(i); for ( int i = 0; i < size; ++i ) - UnrefElement(i); + ClearElement(i); delete [] weak_refs; } @@ -64,37 +64,41 @@ void Frame::AddFunctionWithClosureRef(BroFunc* func) functions_with_closure_frame_reference->emplace_back(func); } -void Frame::SetElement(int n, Val* v, bool weak_ref) +void Frame::SetElement(int n, Val* v) + { SetElement(n, {AdoptRef{}, v}); } + +void Frame::SetElement(int n, IntrusivePtr v) { - UnrefElement(n); - frame[n] = {AdoptRef{}, v}; + ClearElement(n); + frame[n] = std::move(v); - if ( weak_ref ) - { - if ( ! weak_refs ) - { - weak_refs = new bool[size]; - - for ( auto i = 0; i < size; ++i ) - weak_refs[i] = false; - } - - weak_refs[n] = true; - } - else - { - if ( weak_refs ) - weak_refs[n] = false; - } + if ( weak_refs ) + weak_refs[n] = false; } -void Frame::SetElement(const ID* id, Val* v) +void Frame::SetElementWeak(int n, Val* v) + { + ClearElement(n); + frame[n] = {AdoptRef{}, v}; + + if ( ! weak_refs ) + { + weak_refs = new bool[size]; + + for ( auto i = 0; i < size; ++i ) + weak_refs[i] = false; + } + + weak_refs[n] = true; + } + +void Frame::SetElement(const ID* id, IntrusivePtr v) { if ( closure ) { if ( IsOuterID(id) ) { - closure->SetElement(id, v); + closure->SetElement(id, std::move(v)); return; } } @@ -110,11 +114,11 @@ void Frame::SetElement(const ID* id, Val* v) // id->Offset() below is otherwise responsible for keeping track // of the implied reference count of the passed-in 'v' argument. // i.e. if we end up storing it twice, we need an addition Ref. - SetElement(where->second, v->Ref()); + SetElement(where->second, v); } } - SetElement(id->Offset(), v); + SetElement(id->Offset(), std::move(v)); } Val* Frame::GetElement(const ID* id) const @@ -140,7 +144,7 @@ void Frame::Reset(int startIdx) { for ( int i = startIdx; i < size; ++i ) { - UnrefElement(i); + ClearElement(i); frame[i] = nullptr; } } @@ -195,9 +199,7 @@ static bool val_is_func(const IntrusivePtr& v, BroFunc* func) return v->AsFunc() == func; } -static void clone_if_not_func(const std::unique_ptr[]>& frame, - int offset, BroFunc* func, - Frame* other) +void Frame::CloneNonFuncElement(int offset, BroFunc* func, Frame* other) const { const auto& v = frame[offset]; @@ -206,12 +208,12 @@ static void clone_if_not_func(const std::unique_ptr[]>& frame, if ( val_is_func(v, func) ) { - other->SetElement(offset, v.get(), true); + other->SetElementWeak(offset, v.get()); return; } auto rval = v->Clone(); - other->SetElement(offset, rval.release()); + other->SetElement(offset, std::move(rval)); } Frame* Frame::SelectiveClone(const id_list& selection, BroFunc* func) const @@ -240,7 +242,7 @@ Frame* Frame::SelectiveClone(const id_list& selection, BroFunc* func) const auto where = offset_map->find(std::string(id->Name())); if ( where != offset_map->end() ) { - clone_if_not_func(frame, where->second, func, other); + CloneNonFuncElement(where->second, func, other); continue; } } @@ -248,7 +250,7 @@ Frame* Frame::SelectiveClone(const id_list& selection, BroFunc* func) const if ( ! frame[id->Offset()] ) reporter->InternalError("Attempted to clone an id ('%s') with no associated value.", id->Name()); - clone_if_not_func(frame, id->Offset(), func, other); + CloneNonFuncElement(id->Offset(), func, other); } /** @@ -531,7 +533,7 @@ void Frame::ClearTrigger() trigger = nullptr; } -void Frame::UnrefElement(int n) +void Frame::ClearElement(int n) { if ( weak_refs && weak_refs[n] ) frame[n].release(); diff --git a/src/Frame.h b/src/Frame.h index 3880159aec..57827f1b5b 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -45,16 +45,14 @@ public: Val* NthElement(int n) const { return frame[n].get(); } /** - * Sets the element at index *n* of the underlying array - * to *v*. - * + * Sets the element at index *n* of the underlying array to *v*. * @param n the index to set * @param v the value to set it to - * @param weak_ref whether the frame owns the value and should unref - * it upon destruction. Used to break circular references between - * lambda functions and closure frames. */ - void SetElement(int n, Val* v, bool weak_ref = false); + void SetElement(int n, IntrusivePtr v); + + [[deprecated("Remove in v4.1. Pass IntrusivePtr instead.")]] + void SetElement(int n, Val* v); /** * Associates *id* and *v* in the frame. Future lookups of @@ -63,7 +61,7 @@ public: * @param id the ID to associate * @param v the value to associate it with */ - void SetElement(const ID* id, Val* v); + void SetElement(const ID* id, IntrusivePtr v); /** * Gets the value associated with *id* and returns it. Returns @@ -76,8 +74,7 @@ public: /** * Resets all of the indexes from [*startIdx, frame_size) in - * the Frame. Unrefs all of the values in reset indexes. - * + * the Frame. * @param the first index to unref. */ void Reset(int startIdx); @@ -232,9 +229,27 @@ private: using OffsetMap = std::unordered_map; /** - * Unrefs the value at offset 'n' frame unless it's a weak reference. + * Sets the element at index *n* of the underlying array to *v*, but does + * not take ownership of a reference count to it. This method is used to + * break circular references between lambda functions and closure frames. + * @param n the index to set + * @param v the value to set it to (caller has not Ref'd and Frame will + * not Unref it) */ - void UnrefElement(int n); + void SetElementWeak(int n, Val* v); + + /** + * Clone an element at an offset into other frame if not equal to a given + * function (in that case just assigna weak reference). Used to break + * circular references between lambda functions and closure frames. + */ + void CloneNonFuncElement(int offset, BroFunc* func, Frame* other) const; + + /** + * Resets the value at offset 'n' frame (by decrementing reference + * count if not a weak reference). + */ + void ClearElement(int n); /** Have we captured this id? */ bool IsOuterID(const ID* in) const; diff --git a/src/Func.cc b/src/Func.cc index ec30fcc2b0..8553d9234f 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -365,11 +365,11 @@ IntrusivePtr BroFunc::operator()(zeek::Args* args, Frame* parent) const // Fill in the rest of the frame with the function's arguments. for ( auto j = 0u; j < args->size(); ++j ) { - Val* arg = (*args)[j].get(); + const auto& arg = (*args)[j]; if ( f->NthElement(j) != arg ) // Either not yet set, or somebody reassigned the frame slot. - f->SetElement(j, arg->Ref()); + f->SetElement(j, arg); } f->Reset(args->size()); diff --git a/src/Stmt.cc b/src/Stmt.cc index fde3cdc5fa..0c2e3235d7 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -811,7 +811,7 @@ IntrusivePtr SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) con if ( matching_id ) { auto cv = cast_value_to_type(v, matching_id->GetType().get()); - f->SetElement(matching_id, cv.release()); + f->SetElement(matching_id, std::move(cv)); } flow = FLOW_NEXT; @@ -1191,10 +1191,10 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const delete k; if ( value_var ) - f->SetElement(value_var.get(), current_tev->GetVal()->Ref()); + f->SetElement(value_var.get(), current_tev->GetVal()); for ( int i = 0; i < ind_lv->Length(); i++ ) - f->SetElement((*loop_vars)[i], ind_lv->Idx(i)->Ref()); + f->SetElement((*loop_vars)[i], ind_lv->Idx(i)); flow = FLOW_NEXT; @@ -1230,7 +1230,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const // Set the loop variable to the current index, and make // another pass over the loop body. - f->SetElement((*loop_vars)[0], val_mgr->Count(i).release()); + f->SetElement((*loop_vars)[0], val_mgr->Count(i)); flow = FLOW_NEXT; ret = body->Exec(f, flow); @@ -1244,8 +1244,8 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const for ( int i = 0; i < sval->Len(); ++i ) { - f->SetElement((*loop_vars)[0], - new StringVal(1, (const char*) sval->Bytes() + i)); + auto sv = make_intrusive(1, (const char*) sval->Bytes() + i); + f->SetElement((*loop_vars)[0], std::move(sv)); flow = FLOW_NEXT; ret = body->Exec(f, flow); @@ -1653,23 +1653,24 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const { const auto& t = aggr->GetType(); - Val* v = nullptr; + IntrusivePtr v; switch ( t->Tag() ) { case TYPE_RECORD: - v = new RecordVal(cast_intrusive(t)); + v = make_intrusive(cast_intrusive(t)); break; case TYPE_VECTOR: - v = new VectorVal(cast_intrusive(t)); + v = make_intrusive(cast_intrusive(t)); break; case TYPE_TABLE: - v = new TableVal(cast_intrusive(t), {NewRef{}, aggr->Attrs()}); + v = make_intrusive(cast_intrusive(t), + IntrusivePtr{NewRef{}, aggr->Attrs()}); break; default: break; } - f->SetElement(aggr, v); + f->SetElement(aggr, std::move(v)); } return nullptr; From 1ccbe743d016642f90d6c25549a7a109e4f8f53f Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 23 May 2020 08:52:34 -0700 Subject: [PATCH 129/151] Deprecate Frame::NthElement(), replace with GetElement() --- src/Frame.h | 4 ++++ src/Func.cc | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Frame.h b/src/Frame.h index 57827f1b5b..1003be2ce5 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -42,6 +42,10 @@ public: * @param n the index to get. * @return the value at index *n* of the underlying array. */ + const IntrusivePtr& GetElement(int n) const + { return frame[n]; } + + [[deprecated("Remove in v4.1. Use GetElement(int).")]] Val* NthElement(int n) const { return frame[n].get(); } /** diff --git a/src/Func.cc b/src/Func.cc index 8553d9234f..b35736db92 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -367,7 +367,7 @@ IntrusivePtr BroFunc::operator()(zeek::Args* args, Frame* parent) const { const auto& arg = (*args)[j]; - if ( f->NthElement(j) != arg ) + if ( f->GetElement(j) != arg ) // Either not yet set, or somebody reassigned the frame slot. f->SetElement(j, arg); } From 9f4eca081f97c59eb07b553d5a95f0536145b7b2 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 23 May 2020 09:06:37 -0700 Subject: [PATCH 130/151] Deprecate Frame::GetElement(ID*), replace with GetElementByID() --- src/Expr.cc | 2 +- src/Frame.cc | 8 ++++---- src/Frame.h | 9 ++++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 68e10a9a90..93c5d8f84e 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -239,7 +239,7 @@ IntrusivePtr NameExpr::Eval(Frame* f) const v = id->GetVal(); else if ( f ) - v = {NewRef{}, f->GetElement(id.get())}; + v = f->GetElementByID(id); else // No frame - evaluating for Simplify() purposes diff --git a/src/Frame.cc b/src/Frame.cc index 2217dea187..d4aff1c844 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -121,12 +121,12 @@ void Frame::SetElement(const ID* id, IntrusivePtr v) SetElement(id->Offset(), std::move(v)); } -Val* Frame::GetElement(const ID* id) const +const IntrusivePtr& Frame::GetElementByID(const ID* id) const { if ( closure ) { if ( IsOuterID(id) ) - return closure->GetElement(id); + return closure->GetElementByID(id); } // do we have an offset for it? @@ -134,10 +134,10 @@ Val* Frame::GetElement(const ID* id) const { auto where = offset_map->find(std::string(id->Name())); if ( where != offset_map->end() ) - return frame[where->second].get(); + return frame[where->second]; } - return frame[id->Offset()].get(); + return frame[id->Offset()]; } void Frame::Reset(int startIdx) diff --git a/src/Frame.h b/src/Frame.h index 1003be2ce5..9c517ff65c 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -74,7 +74,12 @@ public: * @param id the id who's value to retreive * @return the value associated with *id* */ - Val* GetElement(const ID* id) const; + const IntrusivePtr& GetElementByID(const IntrusivePtr& id) const + { return GetElementByID(id.get()); } + + [[deprecated("Remove in v4.1. Use GetElementByID().")]] + Val* GetElement(const ID* id) const + { return GetElementByID(id).get(); } /** * Resets all of the indexes from [*startIdx, frame_size) in @@ -232,6 +237,8 @@ private: using OffsetMap = std::unordered_map; + const IntrusivePtr& GetElementByID(const ID* id) const; + /** * Sets the element at index *n* of the underlying array to *v*, but does * not take ownership of a reference count to it. This method is used to From 198d604ddeaee11ebe2c8999292f2ddec1c41217 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 23 May 2020 09:19:50 -0700 Subject: [PATCH 131/151] Store weak ref boolean along with Frame element Vals --- src/Frame.cc | 52 +++++++++++++++++----------------------------------- src/Frame.h | 17 ++++++++++------- 2 files changed, 27 insertions(+), 42 deletions(-) diff --git a/src/Frame.cc b/src/Frame.cc index d4aff1c844..7c1470d2dc 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -17,7 +17,7 @@ std::vector g_frame_stack; Frame::Frame(int arg_size, const BroFunc* func, const zeek::Args* fn_args) { size = arg_size; - frame = std::make_unique[]>(size); + frame = std::make_unique(size); function = func; func_args = fn_args; @@ -50,8 +50,6 @@ Frame::~Frame() for ( int i = 0; i < size; ++i ) ClearElement(i); - - delete [] weak_refs; } void Frame::AddFunctionWithClosureRef(BroFunc* func) @@ -70,26 +68,13 @@ void Frame::SetElement(int n, Val* v) void Frame::SetElement(int n, IntrusivePtr v) { ClearElement(n); - frame[n] = std::move(v); - - if ( weak_refs ) - weak_refs[n] = false; + frame[n] = {std::move(v), false}; } void Frame::SetElementWeak(int n, Val* v) { ClearElement(n); - frame[n] = {AdoptRef{}, v}; - - if ( ! weak_refs ) - { - weak_refs = new bool[size]; - - for ( auto i = 0; i < size; ++i ) - weak_refs[i] = false; - } - - weak_refs[n] = true; + frame[n] = {{AdoptRef{}, v}, true}; } void Frame::SetElement(const ID* id, IntrusivePtr v) @@ -134,19 +119,16 @@ const IntrusivePtr& Frame::GetElementByID(const ID* id) const { auto where = offset_map->find(std::string(id->Name())); if ( where != offset_map->end() ) - return frame[where->second]; + return frame[where->second].val; } - return frame[id->Offset()]; + return frame[id->Offset()].val; } void Frame::Reset(int startIdx) { for ( int i = startIdx; i < size; ++i ) - { ClearElement(i); - frame[i] = nullptr; - } } void Frame::Describe(ODesc* d) const @@ -160,14 +142,14 @@ void Frame::Describe(ODesc* d) const for ( int i = 0; i < size; ++i ) { - d->Add(frame[i] != nullptr); + d->Add(frame[i].val != nullptr); d->SP(); } } for ( int i = 0; i < size; ++i ) - if ( frame[i] ) - frame[i]->Describe(d); + if ( frame[i].val ) + frame[i].val->Describe(d); else if ( d->IsReadable() ) d->Add(""); } @@ -185,8 +167,8 @@ Frame* Frame::Clone() const other->trigger = trigger; for ( int i = 0; i < size; i++ ) - if ( frame[i] ) - other->frame[i] = frame[i]->Clone(); + if ( frame[i].val ) + other->frame[i].val = frame[i].val->Clone(); return other; } @@ -201,7 +183,7 @@ static bool val_is_func(const IntrusivePtr& v, BroFunc* func) void Frame::CloneNonFuncElement(int offset, BroFunc* func, Frame* other) const { - const auto& v = frame[offset]; + const auto& v = frame[offset].val; if ( ! v ) return; @@ -247,7 +229,7 @@ Frame* Frame::SelectiveClone(const id_list& selection, BroFunc* func) const } } - if ( ! frame[id->Offset()] ) + if ( ! frame[id->Offset()].val ) reporter->InternalError("Attempted to clone an id ('%s') with no associated value.", id->Name()); CloneNonFuncElement(id->Offset(), func, other); @@ -349,7 +331,7 @@ broker::expected Frame::Serialize(const Frame* target, const id_li if (where != new_map.end()) location = where->second; - const auto& val = target->frame[location]; + const auto& val = target->frame[location].val; TypeTag tag = val->GetType()->Tag(); @@ -484,7 +466,7 @@ std::pair> Frame::Unserialize(const broker::vector& da if ( ! val ) return std::make_pair(false, nullptr); - rf->frame[i] = std::move(val); + rf->frame[i].val = std::move(val); } return std::make_pair(true, std::move(rf)); @@ -535,10 +517,10 @@ void Frame::ClearTrigger() void Frame::ClearElement(int n) { - if ( weak_refs && weak_refs[n] ) - frame[n].release(); + if ( frame[n].weak_ref ) + frame[n].val.release(); else - frame[n] = nullptr; + frame[n] = {nullptr, false}; } bool Frame::IsOuterID(const ID* in) const diff --git a/src/Frame.h b/src/Frame.h index 9c517ff65c..6dc3a055c5 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -43,10 +43,10 @@ public: * @return the value at index *n* of the underlying array. */ const IntrusivePtr& GetElement(int n) const - { return frame[n]; } + { return frame[n].val; } [[deprecated("Remove in v4.1. Use GetElement(int).")]] - Val* NthElement(int n) const { return frame[n].get(); } + Val* NthElement(int n) const { return frame[n].val.get(); } /** * Sets the element at index *n* of the underlying array to *v*. @@ -237,6 +237,13 @@ private: using OffsetMap = std::unordered_map; + struct Element { + IntrusivePtr val; + // Weak reference is used to prevent circular reference memory leaks + // in lambdas/closures. + bool weak_ref; + }; + const IntrusivePtr& GetElementByID(const ID* id) const; /** @@ -290,11 +297,7 @@ private: bool delayed; /** Associates ID's offsets with values. */ - std::unique_ptr[]> frame; - - /** Values that are weakly referenced by the frame. Used to - * prevent circular reference memory leaks in lambda/closures */ - bool* weak_refs = nullptr; + std::unique_ptr frame; /** The enclosing frame of this frame. */ Frame* closure; From 28b4206519143b50e5c6198d0a38fbc57cff1a30 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 23 May 2020 09:29:27 -0700 Subject: [PATCH 132/151] Remove weak_ref param from ID::SetVal() It was not used anywhere. --- src/ID.cc | 13 ++----------- src/ID.h | 11 +---------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/ID.cc b/src/ID.cc index 95da8e6568..e39de42804 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -114,7 +114,6 @@ ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) offset = 0; infer_return_type = false; - weak_ref = false; SetLocationInfo(&start_location, &end_location); } @@ -122,9 +121,6 @@ ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) ID::~ID() { delete [] name; - - if ( weak_ref ) - val.release(); } std::string ID::ModuleName() const @@ -139,17 +135,12 @@ void ID::SetType(IntrusivePtr t) void ID::ClearVal() { - if ( weak_ref ) - val.release(); + val = nullptr; } -void ID::SetVal(IntrusivePtr v, bool arg_weak_ref) +void ID::SetVal(IntrusivePtr v) { - if ( weak_ref ) - val.release(); - val = std::move(v); - weak_ref = arg_weak_ref; Modified(); #ifdef DEBUG diff --git a/src/ID.h b/src/ID.h index efd3aa655a..a051a9a47c 100644 --- a/src/ID.h +++ b/src/ID.h @@ -67,15 +67,7 @@ public: void MakeType() { is_type = true; } - // If weak_ref is false, the Val is assumed to be already ref'ed - // and will be deref'ed when the ID is deleted. - // - // If weak_ref is true, we store the Val but don't ref/deref it. - // That means that when the ID becomes the only one holding a - // reference to the Val, the Val will be destroyed (naturally, - // you have to take care that it will not be accessed via - // the ID afterwards). - void SetVal(IntrusivePtr v, bool weak_ref = false); + void SetVal(IntrusivePtr v); void SetVal(IntrusivePtr v, init_class c); void SetVal(IntrusivePtr ev, init_class c); @@ -153,7 +145,6 @@ protected: IDScope scope; bool is_export; bool infer_return_type; - bool weak_ref; IntrusivePtr type; bool is_const, is_enum_const, is_type, is_option; int offset; From 2ebc20a16453721e86714bd5355b6957e8da4b83 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 11:34:44 -0700 Subject: [PATCH 133/151] Deprecate ID::Attrs(), replace with GetAttrs() --- src/ID.h | 5 +++++ src/Stmt.cc | 2 +- src/Var.cc | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ID.h b/src/ID.h index a051a9a47c..ba63c46a03 100644 --- a/src/ID.h +++ b/src/ID.h @@ -102,6 +102,11 @@ public: void AddAttrs(IntrusivePtr attr); void RemoveAttr(attr_tag a); void UpdateValAttrs(); + + const IntrusivePtr& GetAttrs() const + { return attrs; } + + [[deprecated("Remove in 4.1. Use GetAttrs().")]] Attributes* Attrs() const { return attrs.get(); } Attr* FindAttr(attr_tag t) const; diff --git a/src/Stmt.cc b/src/Stmt.cc index 0c2e3235d7..a163e6362e 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1664,7 +1664,7 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const break; case TYPE_TABLE: v = make_intrusive(cast_intrusive(t), - IntrusivePtr{NewRef{}, aggr->Attrs()}); + aggr->GetAttrs()); break; default: break; diff --git a/src/Var.cc b/src/Var.cc index 590823587e..0665169abc 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -250,8 +250,8 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, } else if ( t->Tag() == TYPE_TABLE ) - aggr = make_intrusive(IntrusivePtr{NewRef{}, t->AsTableType()}, - IntrusivePtr{NewRef{}, id->Attrs()}); + aggr = make_intrusive(cast_intrusive(t), + id->GetAttrs()); else if ( t->Tag() == TYPE_VECTOR ) aggr = make_intrusive(cast_intrusive(t)); @@ -326,7 +326,7 @@ IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, *init->GetLocationInfo() : no_location; auto name_expr = make_intrusive(id, dt == VAR_CONST); - auto attrs = id->Attrs() ? id->Attrs()->Attrs() : nullptr; + auto attrs = id->GetAttrs() ? id->GetAttrs()->Attrs() : nullptr; auto assign_expr = make_intrusive(std::move(name_expr), std::move(init), 0, nullptr, attrs); From 97636e97a5d55c428d42a0d8cdf7ac7b84819678 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 12:13:56 -0700 Subject: [PATCH 134/151] Deprecate Attr::AttrExpr(), replace with GetExpr() --- src/Attr.cc | 22 +++++++++++----------- src/Attr.h | 5 +++++ src/Expr.cc | 8 ++++---- src/Func.cc | 2 +- src/ID.cc | 4 ++-- src/Type.cc | 4 ++-- src/Val.cc | 24 ++++++++++++------------ src/Var.cc | 2 +- src/input/Manager.cc | 2 +- 9 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/Attr.cc b/src/Attr.cc index 093e2d7f28..9536be2554 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -262,10 +262,10 @@ void Attributes::CheckAttr(Attr* a) { bool is_add = a->Tag() == ATTR_ADD_FUNC; - const auto& at = a->AttrExpr()->GetType(); + const auto& at = a->GetExpr()->GetType(); if ( at->Tag() != TYPE_FUNC ) { - a->AttrExpr()->Error( + a->GetExpr()->Error( is_add ? "&add_func must be a function" : "&delete_func must be a function"); @@ -275,7 +275,7 @@ void Attributes::CheckAttr(Attr* a) FuncType* aft = at->AsFuncType(); if ( ! same_type(aft->Yield(), type) ) { - a->AttrExpr()->Error( + a->GetExpr()->Error( is_add ? "&add_func function must yield same type as variable" : "&delete_func function must yield same type as variable"); @@ -294,7 +294,7 @@ void Attributes::CheckAttr(Attr* a) break; } - const auto& atype = a->AttrExpr()->GetType(); + const auto& atype = a->GetExpr()->GetType(); if ( type->Tag() != TYPE_TABLE || (type->IsSet() && ! in_record) ) { @@ -314,7 +314,7 @@ void Attributes::CheckAttr(Attr* a) // Ok. break; - auto e = check_and_promote_expr(a->AttrExpr(), type.get()); + auto e = check_and_promote_expr(a->GetExpr().get(), type.get()); if ( e ) { @@ -323,7 +323,7 @@ void Attributes::CheckAttr(Attr* a) break; } - a->AttrExpr()->Error("&default value has inconsistent type", type.get()); + a->GetExpr()->Error("&default value has inconsistent type", type.get()); return; } @@ -354,7 +354,7 @@ void Attributes::CheckAttr(Attr* a) // Ok. break; - auto e = check_and_promote_expr(a->AttrExpr(), ytype.get()); + auto e = check_and_promote_expr(a->GetExpr().get(), ytype.get()); if ( e ) { @@ -380,7 +380,7 @@ void Attributes::CheckAttr(Attr* a) if ( (atype->Tag() == TYPE_TABLE && atype->AsTableType()->IsUnspecifiedTable()) ) { - auto e = check_and_promote_expr(a->AttrExpr(), type.get()); + auto e = check_and_promote_expr(a->GetExpr().get(), type.get()); if ( e ) { @@ -446,7 +446,7 @@ void Attributes::CheckAttr(Attr* a) break; } - const Expr* expire_func = a->AttrExpr(); + const auto& expire_func = a->GetExpr(); if ( expire_func->GetType()->Tag() != TYPE_FUNC ) Error("&expire_func attribute is not a function"); @@ -493,7 +493,7 @@ void Attributes::CheckAttr(Attr* a) break; } - const Expr* change_func = a->AttrExpr(); + const auto& change_func = a->GetExpr(); if ( change_func->GetType()->Tag() != TYPE_FUNC || change_func->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) Error("&on_change attribute is not a function"); @@ -588,7 +588,7 @@ void Attributes::CheckAttr(Attr* a) break; } - const auto& atype = a->AttrExpr()->GetType(); + const auto& atype = a->GetExpr()->GetType(); if ( atype->Tag() != TYPE_STRING ) { Error("type column needs to have a string argument"); diff --git a/src/Attr.h b/src/Attr.h index 7271bdd1f6..7e050d1a49 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -41,8 +41,13 @@ public: ~Attr() override; attr_tag Tag() const { return tag; } + + [[deprecated("Remove in v4.1. Use GetExpr().")]] Expr* AttrExpr() const { return expr.get(); } + const IntrusivePtr& GetExpr() const + { return expr; } + template void SetAttrExpr(E&& e) { expr = std::forward(e); } diff --git a/src/Expr.cc b/src/Expr.cc index 93c5d8f84e..c2a22bb3cc 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2895,7 +2895,7 @@ IntrusivePtr FieldExpr::Fold(Val* v) const const Attr* def_attr = td ? td->FindAttr(ATTR_DEFAULT) : nullptr; if ( def_attr ) - return def_attr->AttrExpr()->Eval(nullptr); + return def_attr->GetExpr()->Eval(nullptr); else { RuntimeError("field value missing"); @@ -3658,7 +3658,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const map[i])->FindAttr(ATTR_DEFAULT); if ( def ) - rhs = def->AttrExpr()->Eval(nullptr); + rhs = def->GetExpr()->Eval(nullptr); } assert(rhs || GetType()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_OPTIONAL)); @@ -3695,7 +3695,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const { if ( const Attr* def = GetType()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_DEFAULT) ) { - auto def_val = def->AttrExpr()->Eval(nullptr); + auto def_val = def->GetExpr()->Eval(nullptr); const auto& def_type = def_val->GetType(); const auto& field_type = GetType()->AsRecordType()->GetFieldType(i); @@ -5010,7 +5010,7 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types) return false; } - def_elements.push_front(def_attr->AttrExpr()); + def_elements.push_front(def_attr->GetExpr().get()); } for ( const auto& elem : def_elements ) diff --git a/src/Func.cc b/src/Func.cc index b35736db92..18875ff742 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -855,7 +855,7 @@ static int get_func_priority(const attr_list& attrs) continue; } - auto v = a->AttrExpr()->Eval(nullptr); + auto v = a->GetExpr()->Eval(nullptr); if ( ! v ) { diff --git a/src/ID.cc b/src/ID.cc index e39de42804..87185eb4e9 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -213,7 +213,7 @@ void ID::SetVal(IntrusivePtr ev, init_class c) if ( ! a ) Internal("no add/delete function in ID::SetVal"); - EvalFunc({NewRef{}, a->AttrExpr()}, std::move(ev)); + EvalFunc(a->GetExpr(), std::move(ev)); } bool ID::IsRedefinable() const @@ -291,7 +291,7 @@ std::string ID::GetDeprecationWarning() const Attr* depr_attr = FindAttr(ATTR_DEPRECATED); if ( depr_attr ) { - ConstExpr* expr = static_cast(depr_attr->AttrExpr()); + auto expr = static_cast(depr_attr->GetExpr().get()); if ( expr ) { StringVal* text = expr->Value()->AsStringVal(); diff --git a/src/Type.cc b/src/Type.cc index 7260c4194c..1c204ec052 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -689,7 +689,7 @@ IntrusivePtr RecordType::FieldDefault(int field) const const Attr* def_attr = td->attrs->FindAttr(ATTR_DEFAULT); - return def_attr ? def_attr->AttrExpr()->Eval(nullptr) : nullptr; + return def_attr ? def_attr->GetExpr()->Eval(nullptr) : nullptr; } int RecordType::FieldOffset(const char* field) const @@ -1010,7 +1010,7 @@ string RecordType::GetFieldDeprecationWarning(int field, bool has_check) const string result; if ( const Attr* deprecation = decl->FindAttr(ATTR_DEPRECATED) ) { - ConstExpr* expr = static_cast(deprecation->AttrExpr()); + auto expr = static_cast(deprecation->GetExpr().get()); if ( expr ) { StringVal* text = expr->Value()->AsStringVal(); diff --git a/src/Val.cc b/src/Val.cc index 4fa0733091..f541cfd61a 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1479,12 +1479,12 @@ void TableVal::SetAttrs(IntrusivePtr a) Attr* ef = attrs->FindAttr(ATTR_EXPIRE_FUNC); if ( ef ) - expire_func = {NewRef{}, ef->AttrExpr()}; + expire_func = ef->GetExpr(); auto cf = attrs->FindAttr(ATTR_ON_CHANGE); if ( cf ) - change_func = {NewRef{}, cf->AttrExpr()}; + change_func = cf->GetExpr(); } void TableVal::CheckExpireAttr(attr_tag at) @@ -1493,7 +1493,7 @@ void TableVal::CheckExpireAttr(attr_tag at) if ( a ) { - expire_time = {NewRef{}, a->AttrExpr()}; + expire_time = a->GetExpr(); if ( expire_time->GetType()->Tag() != TYPE_INTERVAL ) { @@ -1821,21 +1821,21 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) if ( ! def_val ) { const auto& ytype = GetType()->Yield(); - const auto& dtype = def_attr->AttrExpr()->GetType(); + const auto& dtype = def_attr->GetExpr()->GetType(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && ! same_type(dtype, ytype) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) { - auto coerce = make_intrusive( - IntrusivePtr{NewRef{}, def_attr->AttrExpr()}, - IntrusivePtr{NewRef{}, ytype->AsRecordType()}); + auto rt = cast_intrusive(ytype); + auto coerce = make_intrusive(def_attr->GetExpr(), + std::move(rt)); def_val = coerce->Eval(nullptr); } else - def_val = def_attr->AttrExpr()->Eval(nullptr); + def_val = def_attr->GetExpr()->Eval(nullptr); } if ( ! def_val ) @@ -1847,7 +1847,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) if ( def_val->GetType()->Tag() != TYPE_FUNC || same_type(def_val->GetType(), GetType()->Yield()) ) { - if ( def_attr->AttrExpr()->IsConst() ) + if ( def_attr->GetExpr()->IsConst() ) return def_val; try @@ -2345,7 +2345,7 @@ void TableVal::InitDefaultFunc(Frame* f) return; const auto& ytype = GetType()->Yield(); - const auto& dtype = def_attr->AttrExpr()->GetType(); + const auto& dtype = def_attr->GetExpr()->GetType(); if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && ! same_type(dtype, ytype) && @@ -2353,7 +2353,7 @@ void TableVal::InitDefaultFunc(Frame* f) ytype->AsRecordType()) ) return; // TableVal::Default will handle this. - def_val = def_attr->AttrExpr()->Eval(f); + def_val = def_attr->GetExpr()->Eval(f); } void TableVal::InitTimer(double delay) @@ -2715,7 +2715,7 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo { Attributes* a = rt->FieldDecl(i)->attrs.get(); Attr* def_attr = a ? a->FindAttr(ATTR_DEFAULT) : nullptr; - auto def = def_attr ? def_attr->AttrExpr()->Eval(nullptr) : nullptr; + auto def = def_attr ? def_attr->GetExpr()->Eval(nullptr) : nullptr; const auto& type = rt->FieldDecl(i)->type; if ( def && type->Tag() == TYPE_RECORD && diff --git a/src/Var.cc b/src/Var.cc index 0665169abc..47d34307c6 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -574,7 +574,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, } if ( Attr* depr_attr = find_attr(attrs, ATTR_DEPRECATED) ) - id->MakeDeprecated({NewRef{}, depr_attr->AttrExpr()}); + id->MakeDeprecated(depr_attr->GetExpr()); } class OuterIDBindingFinder : public TraversalCallback { diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 88b30f098f..1dc1a0beb5 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -944,7 +944,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, { // we have an annotation for the second column - c = rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN)->AttrExpr()->Eval(nullptr); + c = rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN)->GetExpr()->Eval(nullptr); assert(c); assert(c->GetType()->Tag() == TYPE_STRING); From 007533295a60b2a1ed616c5ed43012127fe7009b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 12:21:23 -0700 Subject: [PATCH 135/151] Change Attr::SetAttrExpr() to non-template --- src/Attr.cc | 3 +++ src/Attr.h | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Attr.cc b/src/Attr.cc index 9536be2554..8850c27396 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -37,6 +37,9 @@ Attr::Attr(attr_tag t) Attr::~Attr() = default; +void Attr::SetAttrExpr(IntrusivePtr e) + { expr = std::move(e); } + void Attr::Describe(ODesc* d) const { AddTag(d); diff --git a/src/Attr.h b/src/Attr.h index 7e050d1a49..7423ba9005 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -48,8 +48,7 @@ public: const IntrusivePtr& GetExpr() const { return expr; } - template - void SetAttrExpr(E&& e) { expr = std::forward(e); } + void SetAttrExpr(IntrusivePtr e); void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool shorten = false) const; From 102e58b80b6837b2700f2107d8a44d1a38f44b69 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 13:05:24 -0700 Subject: [PATCH 136/151] Change Attributes to store std:vector> This also changes the return type of Attributes::Attrs() from attr_list* --- NEWS | 3 ++ src/Attr.cc | 79 ++++++++++++++++++++++------------------------------- src/Attr.h | 8 ++++-- src/Expr.cc | 11 ++++++-- src/Var.cc | 12 +++++++- 5 files changed, 59 insertions(+), 54 deletions(-) diff --git a/NEWS b/NEWS index 297c60ee50..b0b0d49126 100644 --- a/NEWS +++ b/NEWS @@ -94,6 +94,9 @@ Changed Functionality - ``AsVector()`` has changed to return ``std::vector>*``. +- ``Attributes::Attrs()`` now returns ``const std::vector>&`` + instead of ``attr_list*`` + Removed Functionality --------------------- diff --git a/src/Attr.cc b/src/Attr.cc index 8850c27396..ef82f6a412 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -139,7 +139,7 @@ void Attr::AddTag(ODesc* d) const Attributes::Attributes(attr_list* a, IntrusivePtr t, bool arg_in_record, bool is_global) : type(std::move(t)) { - attrs = new attr_list(a->length()); + attrs.reserve(a->length()); in_record = arg_in_record; global_var = is_global; @@ -155,22 +155,11 @@ Attributes::Attributes(attr_list* a, IntrusivePtr t, bool arg_in_record delete a; } -Attributes::~Attributes() - { - for ( const auto& attr : *attrs ) - Unref(attr); - - delete attrs; - } - void Attributes::AddAttr(IntrusivePtr attr) { - if ( ! attrs ) - attrs = new attr_list(1); - // We overwrite old attributes by deleting them first. RemoveAttr(attr->Tag()); - attrs->push_back(IntrusivePtr{attr}.release()); + attrs.emplace_back(attr); // We only check the attribute after we've added it, to facilitate // generating error messages via Attributes::Describe. @@ -180,71 +169,69 @@ void Attributes::AddAttr(IntrusivePtr attr) // those attributes only have meaning for a redefinable value. if ( (attr->Tag() == ATTR_ADD_FUNC || attr->Tag() == ATTR_DEL_FUNC) && ! FindAttr(ATTR_REDEF) ) - attrs->push_back(new Attr(ATTR_REDEF)); + attrs.emplace_back(make_intrusive(ATTR_REDEF)); // For DEFAULT, add an implicit OPTIONAL if it's not a global. if ( ! global_var && attr->Tag() == ATTR_DEFAULT && ! FindAttr(ATTR_OPTIONAL) ) - attrs->push_back(new Attr(ATTR_OPTIONAL)); + attrs.emplace_back(make_intrusive(ATTR_OPTIONAL)); } void Attributes::AddAttrs(Attributes* a) { - attr_list* as = a->Attrs(); - for ( const auto& attr : *as ) - AddAttr({NewRef{}, attr}); + for ( const auto& attr : a->Attrs() ) + AddAttr(attr); Unref(a); } Attr* Attributes::FindAttr(attr_tag t) const { - if ( ! attrs ) - return nullptr; - - for ( const auto& a : *attrs ) - { + for ( const auto& a : attrs ) if ( a->Tag() == t ) - return a; - } + return a.get(); return nullptr; } void Attributes::RemoveAttr(attr_tag t) { - for ( int i = 0; i < attrs->length(); i++ ) - if ( (*attrs)[i]->Tag() == t ) - attrs->remove_nth(i--); + for ( auto it = attrs.begin(); it != attrs.end(); ) + { + if ( (*it)->Tag() == t ) + it = attrs.erase(it); + else + ++it; + } } void Attributes::Describe(ODesc* d) const { - if ( ! attrs ) + if ( attrs.empty() ) { d->AddCount(0); return; } - d->AddCount(attrs->length()); + d->AddCount(static_cast(attrs.size())); - loop_over_list(*attrs, i) + for ( size_t i = 0; i < attrs.size(); ++i ) { if ( (d->IsReadable() || d->IsPortable()) && i > 0 ) d->Add(", "); - (*attrs)[i]->Describe(d); + attrs[i]->Describe(d); } } void Attributes::DescribeReST(ODesc* d, bool shorten) const { - loop_over_list(*attrs, i) + for ( size_t i = 0; i < attrs.size(); ++i ) { if ( i > 0 ) d->Add(" "); - (*attrs)[i]->DescribeReST(d, shorten); + attrs[i]->DescribeReST(d, shorten); } } @@ -415,15 +402,13 @@ void Attributes::CheckAttr(Attr* a) } int num_expires = 0; - if ( attrs ) + + for ( const auto& a : attrs ) { - for ( const auto& a : *attrs ) - { - if ( a->Tag() == ATTR_EXPIRE_READ || - a->Tag() == ATTR_EXPIRE_WRITE || - a->Tag() == ATTR_EXPIRE_CREATE ) - num_expires++; - } + if ( a->Tag() == ATTR_EXPIRE_READ || + a->Tag() == ATTR_EXPIRE_WRITE || + a->Tag() == ATTR_EXPIRE_CREATE ) + num_expires++; } if ( num_expires > 1 ) @@ -609,13 +594,13 @@ void Attributes::CheckAttr(Attr* a) bool Attributes::operator==(const Attributes& other) const { - if ( ! attrs ) - return other.attrs; + if ( attrs.empty() ) + return other.attrs.empty(); - if ( ! other.attrs ) + if ( other.attrs.empty() ) return false; - for ( const auto& a : *attrs ) + for ( const auto& a : attrs ) { Attr* o = other.FindAttr(a->Tag()); @@ -626,7 +611,7 @@ bool Attributes::operator==(const Attributes& other) const return false; } - for ( const auto& o : *other.attrs ) + for ( const auto& o : other.attrs ) { Attr* a = FindAttr(o->Tag()); diff --git a/src/Attr.h b/src/Attr.h index 7423ba9005..e7dfef99e1 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -2,6 +2,8 @@ #pragma once +#include + #include "Obj.h" #include "BroList.h" #include "IntrusivePtr.h" @@ -78,7 +80,6 @@ protected: class Attributes final : public BroObj { public: Attributes(attr_list* a, IntrusivePtr t, bool in_record, bool is_global); - ~Attributes() override; void AddAttr(IntrusivePtr a); void AddAttrs(Attributes* a); // Unref's 'a' when done @@ -90,7 +91,8 @@ public: void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool shorten = false) const; - attr_list* Attrs() { return attrs; } + const std::vector>& Attrs() const + { return attrs; } bool operator==(const Attributes& other) const; @@ -98,7 +100,7 @@ protected: void CheckAttr(Attr* attr); IntrusivePtr type; - attr_list* attrs; + std::vector> attrs; bool in_record; bool global_var; }; diff --git a/src/Expr.cc b/src/Expr.cc index c2a22bb3cc..5ac4990889 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2170,9 +2170,14 @@ bool AssignExpr::TypeCheck(attr_list* attrs) if ( sce->Attrs() ) { - attr_list* a = sce->Attrs()->Attrs(); - attrs = new attr_list(a->length()); - std::copy(a->begin(), a->end(), std::back_inserter(*attrs)); + const auto& a = sce->Attrs()->Attrs(); + attr_copy = new attr_list(a.size()); + + for ( const auto& attr : a ) + { + ::Ref(attr.get()); + attrs->push_back(attr.get()); + } } int errors_before = reporter->Errors(); diff --git a/src/Var.cc b/src/Var.cc index 47d34307c6..1d350b737a 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -326,10 +326,20 @@ IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, *init->GetLocationInfo() : no_location; auto name_expr = make_intrusive(id, dt == VAR_CONST); - auto attrs = id->GetAttrs() ? id->GetAttrs()->Attrs() : nullptr; + attr_list* attrs = nullptr; + + if ( id->GetAttrs() ) + { + attrs = new attr_list(id->GetAttrs()->Attrs().size()); + + for ( const auto& a : id->GetAttrs()->Attrs() ) + attrs->push_back(a.get()); + } + auto assign_expr = make_intrusive(std::move(name_expr), std::move(init), 0, nullptr, attrs); + delete attrs; auto stmt = make_intrusive(std::move(assign_expr)); stmt->SetLocationInfo(&location); return stmt; From ccd1cbbc5453494f10a3d52cacf91df38f606542 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 15:05:38 -0700 Subject: [PATCH 137/151] Add Attributes ctor that takes IntrusivePtrs --- src/Attr.cc | 26 +++++++++++++++++++++++++- src/Attr.h | 5 +++++ src/Expr.cc | 22 ++++++++++++++++++++-- src/ID.cc | 10 +++++----- src/Type.cc | 13 +++++++++++-- src/Var.cc | 25 +++++++++++++++++++++---- 6 files changed, 87 insertions(+), 14 deletions(-) diff --git a/src/Attr.cc b/src/Attr.cc index ef82f6a412..ff3b5e8b3f 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -137,7 +137,6 @@ void Attr::AddTag(ODesc* d) const } Attributes::Attributes(attr_list* a, IntrusivePtr t, bool arg_in_record, bool is_global) - : type(std::move(t)) { attrs.reserve(a->length()); in_record = arg_in_record; @@ -155,6 +154,31 @@ Attributes::Attributes(attr_list* a, IntrusivePtr t, bool arg_in_record delete a; } +Attributes::Attributes(IntrusivePtr t, + bool arg_in_record, bool is_global) + : Attributes(std::vector>{}, std::move(t), + arg_in_record, is_global) + {} + +Attributes::Attributes(std::vector> a, + IntrusivePtr t, + bool arg_in_record, bool is_global) + : type(std::move(t)) + { + attrs.reserve(a.size()); + in_record = arg_in_record; + global_var = is_global; + + SetLocationInfo(&start_location, &end_location); + + // We loop through 'a' and add each attribute individually, + // rather than just taking over 'a' for ourselves, so that + // the necessary checking gets done. + + for ( auto& attr : a ) + AddAttr(std::move(attr)); + } + void Attributes::AddAttr(IntrusivePtr attr) { // We overwrite old attributes by deleting them first. diff --git a/src/Attr.h b/src/Attr.h index e7dfef99e1..3e90b52033 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -79,8 +79,13 @@ protected: // Manages a collection of attributes. class Attributes final : public BroObj { public: + [[deprecated("Remove in v4.1. Construct using IntrusivePtrs instead.")]] Attributes(attr_list* a, IntrusivePtr t, bool in_record, bool is_global); + Attributes(std::vector> a, IntrusivePtr t, + bool in_record, bool is_global); + Attributes(IntrusivePtr t, bool in_record, bool is_global); + void AddAttr(IntrusivePtr a); void AddAttrs(Attributes* a); // Unref's 'a' when done diff --git a/src/Expr.cc b/src/Expr.cc index 5ac4990889..672d5b4697 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3087,7 +3087,16 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li } } - attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; + if ( arg_attrs ) + { + std::vector> attrv; + + for ( auto& a : *arg_attrs ) + attrv.emplace_back(AdoptRef{}, a); + + attrs = new Attributes(std::move(attrv), type, false, false); + delete arg_attrs; + } const auto& indices = type->AsTableType()->GetIndices()->Types(); const expr_list& cle = op->AsListExpr()->Exprs(); @@ -3206,7 +3215,16 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, else if ( type->Tag() != TYPE_TABLE || ! type->AsTableType()->IsSet() ) SetError("values in set(...) constructor do not specify a set"); - attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; + if ( arg_attrs ) + { + std::vector> attrv; + + for ( auto& a : *arg_attrs ) + attrv.emplace_back(AdoptRef{}, a); + + attrs = new Attributes(std::move(attrv), type, false, false); + delete arg_attrs; + } const auto& indices = type->AsTableType()->GetIndices()->Types(); expr_list& cle = op->AsListExpr()->Exprs(); diff --git a/src/ID.cc b/src/ID.cc index 87185eb4e9..a4a0b6f119 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -258,7 +258,7 @@ void ID::UpdateValAttrs() TypeDecl* fd = rt->FieldDecl(i); if ( ! fd->attrs ) - fd->attrs = make_intrusive(new attr_list, rt->GetFieldType(i), true, IsGlobal()); + fd->attrs = make_intrusive(rt->GetFieldType(i), true, IsGlobal()); fd->attrs->AddAttr(make_intrusive(ATTR_LOG)); } @@ -281,8 +281,8 @@ void ID::MakeDeprecated(IntrusivePtr deprecation) if ( IsDeprecated() ) return; - attr_list* attr = new attr_list{new Attr(ATTR_DEPRECATED, std::move(deprecation))}; - AddAttrs(make_intrusive(attr, GetType(), false, IsGlobal())); + std::vector> attrv{make_intrusive(ATTR_DEPRECATED, std::move(deprecation))}; + AddAttrs(make_intrusive(std::move(attrv), GetType(), false, IsGlobal())); } std::string ID::GetDeprecationWarning() const @@ -331,8 +331,8 @@ void ID::SetOption() // option implied redefinable if ( ! IsRedefinable() ) { - attr_list* attr = new attr_list{new Attr(ATTR_REDEF)}; - AddAttrs(make_intrusive(attr, GetType(), false, IsGlobal())); + std::vector> attrv{make_intrusive(ATTR_REDEF)}; + AddAttrs(make_intrusive(std::move(attrv), GetType(), false, IsGlobal())); } } diff --git a/src/Type.cc b/src/Type.cc index 1c204ec052..86e901e0fe 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -609,9 +609,18 @@ std::optional FuncType::FindPrototype(const RecordType& arg TypeDecl::TypeDecl(IntrusivePtr t, const char* i, attr_list* arg_attrs, bool in_record) : type(std::move(t)), - attrs(arg_attrs ? make_intrusive(arg_attrs, type, in_record, false) : nullptr), id(i) { + if ( arg_attrs ) + { + std::vector> attrv; + + for ( auto& a : *arg_attrs ) + attrv.emplace_back(AdoptRef{}, a); + + attrs = make_intrusive(std::move(attrv), type, in_record, false); + delete arg_attrs; + } } TypeDecl::TypeDecl(const TypeDecl& other) @@ -856,7 +865,7 @@ const char* RecordType::AddFields(type_decl_list* others, attr_list* attr) if ( log ) { if ( ! td->attrs ) - td->attrs = make_intrusive(new attr_list, td->type, true, false); + td->attrs = make_intrusive(td->type, true, false); td->attrs->AddAttr(make_intrusive(ATTR_LOG)); } diff --git a/src/Var.cc b/src/Var.cc index 1d350b737a..4ec2b6b60d 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -196,7 +196,14 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, id->SetType(t); if ( attr ) - id->AddAttrs(make_intrusive(attr, t, false, id->IsGlobal())); + { + std::vector> attrv; + + for ( auto& a : *attr) + attrv.emplace_back(AdoptRef{}, a); + + id->AddAttrs(make_intrusive(std::move(attrv), t, false, id->IsGlobal())); + } if ( init ) { @@ -387,7 +394,15 @@ void add_type(ID* id, IntrusivePtr t, attr_list* attr) id->MakeType(); if ( attr ) - id->SetAttrs(make_intrusive(attr, tnew, false, false)); + { + std::vector> attrv; + + for ( auto& a : *attr ) + attrv.emplace_back(AdoptRef{}, a); + + id->SetAttrs(make_intrusive(std::move(attrv), tnew, false, false)); + delete attr; + } } static void transfer_arg_defaults(RecordType* args, RecordType* recv) @@ -404,8 +419,10 @@ static void transfer_arg_defaults(RecordType* args, RecordType* recv) if ( ! recv_i->attrs ) { - attr_list* a = new attr_list{def}; - recv_i->attrs = make_intrusive(a, recv_i->type, true, false); + std::vector> a{{NewRef{}, def}}; + recv_i->attrs = make_intrusive(std::move(a), + recv_i->type, + true, false); } else if ( ! recv_i->attrs->FindAttr(ATTR_DEFAULT) ) From 6daa33364b72bf53c7574267abac428f50b4f903 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 15:12:20 -0700 Subject: [PATCH 138/151] Deprecate Attributes::AddAttrs(Attributes*) Replaced with version taking an IntrusivePtr parameter --- src/Attr.cc | 6 ++++++ src/Attr.h | 4 ++++ src/ID.cc | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Attr.cc b/src/Attr.cc index ff3b5e8b3f..c8633858bf 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -201,6 +201,12 @@ void Attributes::AddAttr(IntrusivePtr attr) attrs.emplace_back(make_intrusive(ATTR_OPTIONAL)); } +void Attributes::AddAttrs(const IntrusivePtr& a) + { + for ( const auto& attr : a->Attrs() ) + AddAttr(attr); + } + void Attributes::AddAttrs(Attributes* a) { for ( const auto& attr : a->Attrs() ) diff --git a/src/Attr.h b/src/Attr.h index 3e90b52033..44d28f9d97 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -87,6 +87,10 @@ public: Attributes(IntrusivePtr t, bool in_record, bool is_global); void AddAttr(IntrusivePtr a); + + void AddAttrs(const IntrusivePtr& a); + + [[deprecated("Remove in v4.1. Pass IntrusivePtr instead.")]] void AddAttrs(Attributes* a); // Unref's 'a' when done Attr* FindAttr(attr_tag t) const; diff --git a/src/ID.cc b/src/ID.cc index a4a0b6f119..3cb2753ebe 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -308,7 +308,7 @@ std::string ID::GetDeprecationWarning() const void ID::AddAttrs(IntrusivePtr a) { if ( attrs ) - attrs->AddAttrs(a.release()); + attrs->AddAttrs(a); else attrs = std::move(a); From bee321711fee2e6d571d2e8c7ee0b260322777f7 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 15:25:08 -0700 Subject: [PATCH 139/151] Deprecate Attributes::FindAttr(), replace with Find() --- src/Attr.cc | 17 +++++++++++++---- src/Attr.h | 5 +++++ src/CompHash.cc | 6 +++--- src/Expr.cc | 2 +- src/File.cc | 2 +- src/ID.cc | 10 +++++----- src/Type.cc | 5 ++--- src/Type.h | 2 +- src/Val.cc | 20 ++++++++++---------- src/Var.cc | 10 +++++----- 10 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/Attr.cc b/src/Attr.cc index c8633858bf..c57f288313 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -192,12 +192,12 @@ void Attributes::AddAttr(IntrusivePtr attr) // For ADD_FUNC or DEL_FUNC, add in an implicit REDEF, since // those attributes only have meaning for a redefinable value. if ( (attr->Tag() == ATTR_ADD_FUNC || attr->Tag() == ATTR_DEL_FUNC) && - ! FindAttr(ATTR_REDEF) ) + ! Find(ATTR_REDEF) ) attrs.emplace_back(make_intrusive(ATTR_REDEF)); // For DEFAULT, add an implicit OPTIONAL if it's not a global. if ( ! global_var && attr->Tag() == ATTR_DEFAULT && - ! FindAttr(ATTR_OPTIONAL) ) + ! Find(ATTR_OPTIONAL) ) attrs.emplace_back(make_intrusive(ATTR_OPTIONAL)); } @@ -224,6 +224,15 @@ Attr* Attributes::FindAttr(attr_tag t) const return nullptr; } +const IntrusivePtr& Attributes::Find(attr_tag t) const + { + for ( const auto& a : attrs ) + if ( a->Tag() == t ) + return a; + + return Attr::nil; + } + void Attributes::RemoveAttr(attr_tag t) { for ( auto it = attrs.begin(); it != attrs.end(); ) @@ -632,7 +641,7 @@ bool Attributes::operator==(const Attributes& other) const for ( const auto& a : attrs ) { - Attr* o = other.FindAttr(a->Tag()); + const auto& o = other.Find(a->Tag()); if ( ! o ) return false; @@ -643,7 +652,7 @@ bool Attributes::operator==(const Attributes& other) const for ( const auto& o : other.attrs ) { - Attr* a = FindAttr(o->Tag()); + const auto& a = Find(o->Tag()); if ( ! a ) return false; diff --git a/src/Attr.h b/src/Attr.h index 44d28f9d97..fbf60f68a4 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -38,6 +38,8 @@ typedef enum { class Attr final : public BroObj { public: + static inline const IntrusivePtr nil; + Attr(attr_tag t, IntrusivePtr e); explicit Attr(attr_tag t); ~Attr() override; @@ -93,8 +95,11 @@ public: [[deprecated("Remove in v4.1. Pass IntrusivePtr instead.")]] void AddAttrs(Attributes* a); // Unref's 'a' when done + [[deprecated("Remove in v4.1. Use Find().")]] Attr* FindAttr(attr_tag t) const; + const IntrusivePtr& Find(attr_tag t) const; + void RemoveAttr(attr_tag t); void Describe(ODesc* d) const override; diff --git a/src/CompHash.cc b/src/CompHash.cc index 1804f24900..7bdc3eba6a 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -183,7 +183,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, auto rv_i = rv->GetField(i).get(); Attributes* a = rt->FieldDecl(i)->attrs.get(); - bool optional = (a && a->FindAttr(ATTR_OPTIONAL)); + bool optional = (a && a->Find(ATTR_OPTIONAL)); if ( ! (rv_i || optional) ) return nullptr; @@ -514,7 +514,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, for ( int i = 0; i < num_fields; ++i ) { Attributes* a = rt->FieldDecl(i)->attrs.get(); - bool optional = (a && a->FindAttr(ATTR_OPTIONAL)); + bool optional = (a && a->Find(ATTR_OPTIONAL)); sz = SingleTypeKeySize(rt->GetFieldType(i).get(), rv ? rv->GetField(i).get() : nullptr, @@ -906,7 +906,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, IntrusivePtr v; Attributes* a = rt->FieldDecl(i)->attrs.get(); - bool optional = (a && a->FindAttr(ATTR_OPTIONAL)); + bool optional = (a && a->Find(ATTR_OPTIONAL)); kp = RecoverOneVal(k, kp, k_end, rt->GetFieldType(i).get(), &v, optional); diff --git a/src/Expr.cc b/src/Expr.cc index 672d5b4697..f1a07fefdf 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -5025,7 +5025,7 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types) for ( int i = ntypes - 1; i >= el.length(); --i ) { TypeDecl* td = types->FieldDecl(i); - Attr* def_attr = td->attrs ? td->attrs->FindAttr(ATTR_DEFAULT) : nullptr; + const auto& def_attr = td->attrs ? td->attrs->Find(ATTR_DEFAULT).get() : nullptr; if ( ! def_attr ) { diff --git a/src/File.cc b/src/File.cc index d70d92047a..a496df5034 100644 --- a/src/File.cc +++ b/src/File.cc @@ -265,7 +265,7 @@ void BroFile::SetAttrs(Attributes* arg_attrs) attrs = arg_attrs; Ref(attrs); - if ( attrs->FindAttr(ATTR_RAW_OUTPUT) ) + if ( attrs->Find(ATTR_RAW_OUTPUT) ) EnableRawOutput(); } diff --git a/src/ID.cc b/src/ID.cc index 3cb2753ebe..5d1f2f3bc9 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -207,8 +207,7 @@ void ID::SetVal(IntrusivePtr v, init_class c) void ID::SetVal(IntrusivePtr ev, init_class c) { - Attr* a = attrs->FindAttr(c == INIT_EXTRA ? - ATTR_ADD_FUNC : ATTR_DEL_FUNC); + const auto& a = attrs->Find(c == INIT_EXTRA ? ATTR_ADD_FUNC : ATTR_DEL_FUNC); if ( ! a ) Internal("no add/delete function in ID::SetVal"); @@ -240,7 +239,7 @@ void ID::UpdateValAttrs() if ( GetType()->Tag() == TYPE_FUNC ) { - Attr* attr = attrs->FindAttr(ATTR_ERROR_HANDLER); + const auto& attr = attrs->Find(ATTR_ERROR_HANDLER); if ( attr ) event_registry->SetErrorHandler(Name()); @@ -248,7 +247,8 @@ void ID::UpdateValAttrs() if ( GetType()->Tag() == TYPE_RECORD ) { - Attr* attr = attrs->FindAttr(ATTR_LOG); + const auto& attr = attrs->Find(ATTR_LOG); + if ( attr ) { // Apply &log to all record fields. @@ -268,7 +268,7 @@ void ID::UpdateValAttrs() Attr* ID::FindAttr(attr_tag t) const { - return attrs ? attrs->FindAttr(t) : nullptr; + return attrs ? attrs->Find(t).get() : nullptr; } bool ID::IsDeprecated() const diff --git a/src/Type.cc b/src/Type.cc index 86e901e0fe..cdb55b2131 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -422,7 +422,7 @@ FuncType::FuncType(IntrusivePtr arg_args, { const TypeDecl* td = args->FieldDecl(i); - if ( td->attrs && td->attrs->FindAttr(ATTR_DEFAULT) ) + if ( td->attrs && td->attrs->Find(ATTR_DEFAULT) ) has_default_arg = true; else if ( has_default_arg ) @@ -696,8 +696,7 @@ IntrusivePtr RecordType::FieldDefault(int field) const if ( ! td->attrs ) return nullptr; - const Attr* def_attr = td->attrs->FindAttr(ATTR_DEFAULT); - + const auto& def_attr = td->attrs->Find(ATTR_DEFAULT); return def_attr ? def_attr->GetExpr()->Eval(nullptr) : nullptr; } diff --git a/src/Type.h b/src/Type.h index b0b114401a..7dce10f595 100644 --- a/src/Type.h +++ b/src/Type.h @@ -567,7 +567,7 @@ public: ~TypeDecl(); const Attr* FindAttr(attr_tag a) const - { return attrs ? attrs->FindAttr(a) : nullptr; } + { return attrs ? attrs->Find(a).get() : nullptr; } void DescribeReST(ODesc* d, bool roles_only = false) const; diff --git a/src/Val.cc b/src/Val.cc index f541cfd61a..c1c810556e 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1476,12 +1476,12 @@ void TableVal::SetAttrs(IntrusivePtr a) CheckExpireAttr(ATTR_EXPIRE_WRITE); CheckExpireAttr(ATTR_EXPIRE_CREATE); - Attr* ef = attrs->FindAttr(ATTR_EXPIRE_FUNC); + const auto& ef = attrs->Find(ATTR_EXPIRE_FUNC); if ( ef ) expire_func = ef->GetExpr(); - auto cf = attrs->FindAttr(ATTR_ON_CHANGE); + const auto& cf = attrs->Find(ATTR_ON_CHANGE); if ( cf ) change_func = cf->GetExpr(); @@ -1489,7 +1489,7 @@ void TableVal::SetAttrs(IntrusivePtr a) void TableVal::CheckExpireAttr(attr_tag at) { - Attr* a = attrs->FindAttr(at); + const auto& a = attrs->Find(at); if ( a ) { @@ -1560,7 +1560,7 @@ bool TableVal::Assign(IntrusivePtr index, std::unique_ptr k, } // Keep old expiration time if necessary. - if ( old_entry_val && attrs && attrs->FindAttr(ATTR_EXPIRE_CREATE) ) + if ( old_entry_val && attrs && attrs->Find(ATTR_EXPIRE_CREATE) ) new_entry_val->SetExpireAccess(old_entry_val->ExpireAccessTime()); Modified(); @@ -1901,7 +1901,7 @@ const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) TableEntryVal* v = (TableEntryVal*) subnets->Lookup(index.get()); if ( v ) { - if ( attrs && attrs->FindAttr(ATTR_EXPIRE_READ) ) + if ( attrs && attrs->Find(ATTR_EXPIRE_READ) ) v->SetExpireAccess(network_time); if ( v->GetVal() ) @@ -1925,7 +1925,7 @@ const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) if ( v ) { - if ( attrs && attrs->FindAttr(ATTR_EXPIRE_READ) ) + if ( attrs && attrs->Find(ATTR_EXPIRE_READ) ) v->SetExpireAccess(network_time); if ( v->GetVal() ) @@ -1997,7 +1997,7 @@ IntrusivePtr TableVal::LookupSubnetValues(const SubNetVal* search) if ( entry ) { - if ( attrs && attrs->FindAttr(ATTR_EXPIRE_READ) ) + if ( attrs && attrs->Find(ATTR_EXPIRE_READ) ) entry->SetExpireAccess(network_time); } } @@ -2201,7 +2201,7 @@ ListVal* TableVal::ConvertToPureList() const Attr* TableVal::FindAttr(attr_tag t) const { - return attrs ? attrs->FindAttr(t) : nullptr; + return attrs ? attrs->Find(t).get() : nullptr; } void TableVal::Describe(ODesc* d) const @@ -2714,7 +2714,7 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo for ( int i = 0; i < n; ++i ) { Attributes* a = rt->FieldDecl(i)->attrs.get(); - Attr* def_attr = a ? a->FindAttr(ATTR_DEFAULT) : nullptr; + Attr* def_attr = a ? a->Find(ATTR_DEFAULT).get() : nullptr; auto def = def_attr ? def_attr->GetExpr()->Eval(nullptr) : nullptr; const auto& type = rt->FieldDecl(i)->type; @@ -2728,7 +2728,7 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo def = std::move(tmp); } - if ( ! def && ! (a && a->FindAttr(ATTR_OPTIONAL)) ) + if ( ! def && ! (a && a->Find(ATTR_OPTIONAL)) ) { TypeTag tag = type->Tag(); diff --git a/src/Var.cc b/src/Var.cc index 4ec2b6b60d..19053bc489 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -412,21 +412,21 @@ static void transfer_arg_defaults(RecordType* args, RecordType* recv) TypeDecl* args_i = args->FieldDecl(i); TypeDecl* recv_i = recv->FieldDecl(i); - Attr* def = args_i->attrs ? args_i->attrs->FindAttr(ATTR_DEFAULT) : nullptr; + const auto& def = args_i->attrs ? args_i->attrs->Find(ATTR_DEFAULT) : nullptr; if ( ! def ) continue; if ( ! recv_i->attrs ) { - std::vector> a{{NewRef{}, def}}; + std::vector> a{def}; recv_i->attrs = make_intrusive(std::move(a), recv_i->type, true, false); } - else if ( ! recv_i->attrs->FindAttr(ATTR_DEFAULT) ) - recv_i->attrs->AddAttr({NewRef{}, def}); + else if ( ! recv_i->attrs->Find(ATTR_DEFAULT) ) + recv_i->attrs->AddAttr(def); } } @@ -523,7 +523,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, { auto f = args->FieldDecl(i); - if ( f->attrs && f->attrs->FindAttr(ATTR_DEFAULT) ) + if ( f->attrs && f->attrs->Find(ATTR_DEFAULT) ) { reporter->PushLocation(args->GetLocationInfo()); reporter->Warning( From 5fc78a548c31e09306b84397319888e0ef56a48c Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 15:31:31 -0700 Subject: [PATCH 140/151] Deprecate ID::FindAttr(), replace with GetAttr() --- src/ID.cc | 11 ++++++----- src/ID.h | 6 +++++- src/Var.cc | 4 ++-- src/zeekygen/ScriptInfo.cc | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ID.cc b/src/ID.cc index 5d1f2f3bc9..20172a5e54 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -217,7 +217,7 @@ void ID::SetVal(IntrusivePtr ev, init_class c) bool ID::IsRedefinable() const { - return FindAttr(ATTR_REDEF) != nullptr; + return GetAttr(ATTR_REDEF) != nullptr; } void ID::SetAttrs(IntrusivePtr a) @@ -266,14 +266,14 @@ void ID::UpdateValAttrs() } } -Attr* ID::FindAttr(attr_tag t) const +const IntrusivePtr& ID::GetAttr(attr_tag t) const { - return attrs ? attrs->Find(t).get() : nullptr; + return attrs ? attrs->Find(t) : Attr::nil; } bool ID::IsDeprecated() const { - return FindAttr(ATTR_DEPRECATED) != nullptr; + return GetAttr(ATTR_DEPRECATED) != nullptr; } void ID::MakeDeprecated(IntrusivePtr deprecation) @@ -288,7 +288,8 @@ void ID::MakeDeprecated(IntrusivePtr deprecation) std::string ID::GetDeprecationWarning() const { std::string result; - Attr* depr_attr = FindAttr(ATTR_DEPRECATED); + const auto& depr_attr = GetAttr(ATTR_DEPRECATED); + if ( depr_attr ) { auto expr = static_cast(depr_attr->GetExpr().get()); diff --git a/src/ID.h b/src/ID.h index ba63c46a03..4c7839bed9 100644 --- a/src/ID.h +++ b/src/ID.h @@ -109,7 +109,11 @@ public: [[deprecated("Remove in 4.1. Use GetAttrs().")]] Attributes* Attrs() const { return attrs.get(); } - Attr* FindAttr(attr_tag t) const; + [[deprecated("Remove in 4.1. Use GetAttr().")]] + Attr* FindAttr(attr_tag t) const + { return GetAttr(t).get(); } + + const IntrusivePtr& GetAttr(attr_tag t) const; bool IsDeprecated() const; diff --git a/src/Var.cc b/src/Var.cc index 19053bc489..5449fe939e 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -237,8 +237,8 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, // intention clearly isn't to overwrite entire existing table val. c = INIT_EXTRA; - if ( init && ((c == INIT_EXTRA && id->FindAttr(ATTR_ADD_FUNC)) || - (c == INIT_REMOVE && id->FindAttr(ATTR_DEL_FUNC)) )) + if ( init && ((c == INIT_EXTRA && id->GetAttr(ATTR_ADD_FUNC)) || + (c == INIT_REMOVE && id->GetAttr(ATTR_DEL_FUNC)) )) // Just apply the function. id->SetVal(init, c); diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index 7249f141d3..827bac5979 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -219,7 +219,7 @@ void ScriptInfo::DoInitPostScript() if ( id->IsConst() ) { - if ( id->FindAttr(ATTR_REDEF) ) + if ( id->GetAttr(ATTR_REDEF) ) { DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a redef_option", id->Name(), name.c_str()); From e3651058724dac436f0b640a246482de14657879 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 15:41:25 -0700 Subject: [PATCH 141/151] Deprecate TypeDecl::FindAttr(), replace with GetAttr() --- src/Expr.cc | 14 +++++++------- src/Type.cc | 7 +++---- src/Type.h | 8 ++++++-- src/Val.cc | 2 +- src/input/Manager.cc | 12 ++++++------ src/logging/Manager.cc | 6 +++--- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index f1a07fefdf..6c6b94b868 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2871,7 +2871,7 @@ IntrusivePtr FieldExpr::MakeLvalue() bool FieldExpr::CanDel() const { - return td->FindAttr(ATTR_DEFAULT) || td->FindAttr(ATTR_OPTIONAL); + return td->GetAttr(ATTR_DEFAULT) || td->GetAttr(ATTR_OPTIONAL); } void FieldExpr::Assign(Frame* f, IntrusivePtr v) @@ -2897,7 +2897,7 @@ IntrusivePtr FieldExpr::Fold(Val* v) const return result; // Check for &default. - const Attr* def_attr = td ? td->FindAttr(ATTR_DEFAULT) : nullptr; + const Attr* def_attr = td ? td->GetAttr(ATTR_DEFAULT).get() : nullptr; if ( def_attr ) return def_attr->GetExpr()->Eval(nullptr); @@ -3625,7 +3625,7 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, { if ( map[i] == -1 ) { - if ( ! t_r->FieldDecl(i)->FindAttr(ATTR_OPTIONAL) ) + if ( ! t_r->FieldDecl(i)->GetAttr(ATTR_OPTIONAL) ) { std::string error_msg = fmt( "non-optional field \"%s\" missing", t_r->FieldName(i)); @@ -3677,14 +3677,14 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const if ( ! rhs ) { - const Attr* def = rv->GetType()->AsRecordType()->FieldDecl( - map[i])->FindAttr(ATTR_DEFAULT); + const auto& def = rv->GetType()->AsRecordType()->FieldDecl( + map[i])->GetAttr(ATTR_DEFAULT); if ( def ) rhs = def->GetExpr()->Eval(nullptr); } - assert(rhs || GetType()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_OPTIONAL)); + assert(rhs || GetType()->AsRecordType()->FieldDecl(i)->GetAttr(ATTR_OPTIONAL)); if ( ! rhs ) { @@ -3716,7 +3716,7 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const } else { - if ( const Attr* def = GetType()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_DEFAULT) ) + if ( const auto& def = GetType()->AsRecordType()->FieldDecl(i)->GetAttr(ATTR_DEFAULT) ) { auto def_val = def->GetExpr()->Eval(nullptr); const auto& def_type = def_val->GetType(); diff --git a/src/Type.cc b/src/Type.cc index cdb55b2131..4e2d3790ba 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -816,7 +816,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const if ( rv ) fv = rv->GetField(i); - bool logged = (fd->attrs && fd->FindAttr(ATTR_LOG) != nullptr); + bool logged = (fd->attrs && fd->GetAttr(ATTR_LOG) != nullptr); auto nr = make_intrusive(record_field); @@ -849,8 +849,7 @@ const char* RecordType::AddFields(type_decl_list* others, attr_list* attr) for ( const auto& td : *others ) { - if ( ! td->FindAttr(ATTR_DEFAULT) && - ! td->FindAttr(ATTR_OPTIONAL) ) + if ( ! td->GetAttr(ATTR_DEFAULT) && ! td->GetAttr(ATTR_OPTIONAL) ) { delete others; return "extension field must be &optional or have &default"; @@ -1016,7 +1015,7 @@ string RecordType::GetFieldDeprecationWarning(int field, bool has_check) const if ( decl) { string result; - if ( const Attr* deprecation = decl->FindAttr(ATTR_DEPRECATED) ) + if ( const auto& deprecation = decl->GetAttr(ATTR_DEPRECATED) ) { auto expr = static_cast(deprecation->GetExpr().get()); if ( expr ) diff --git a/src/Type.h b/src/Type.h index 7dce10f595..bb5f8fc0ba 100644 --- a/src/Type.h +++ b/src/Type.h @@ -566,9 +566,13 @@ public: TypeDecl(const TypeDecl& other); ~TypeDecl(); + [[deprecated("Remove in v4.1. Use GetAttr().")]] const Attr* FindAttr(attr_tag a) const { return attrs ? attrs->Find(a).get() : nullptr; } + const IntrusivePtr& GetAttr(attr_tag a) const + { return attrs ? attrs->Find(a) : Attr::nil; } + void DescribeReST(ODesc* d, bool roles_only = false) const; IntrusivePtr type; @@ -664,13 +668,13 @@ public: bool IsFieldDeprecated(int field) const { const TypeDecl* decl = FieldDecl(field); - return decl && decl->FindAttr(ATTR_DEPRECATED) != nullptr; + return decl && decl->GetAttr(ATTR_DEPRECATED) != nullptr; } bool FieldHasAttr(int field, attr_tag at) const { const TypeDecl* decl = FieldDecl(field); - return decl && decl->FindAttr(at) != nullptr; + return decl && decl->GetAttr(at) != nullptr; } std::string GetFieldDeprecationWarning(int field, bool has_check) const; diff --git a/src/Val.cc b/src/Val.cc index c1c810556e..dbfe7bed59 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2881,7 +2881,7 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, for ( i = 0; i < ar_t->NumFields(); ++i ) if ( ! aggr->GetField(i) && - ! ar_t->FieldDecl(i)->FindAttr(ATTR_OPTIONAL) ) + ! ar_t->FieldDecl(i)->GetAttr(ATTR_OPTIONAL) ) { char buf[512]; snprintf(buf, sizeof(buf), diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 1dc1a0beb5..f98c60684c 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -896,7 +896,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, if ( ( rec->GetFieldType(i)->Tag() == TYPE_FILE || rec->GetFieldType(i)->Tag() == TYPE_FUNC || rec->GetFieldType(i)->Tag() == TYPE_OPAQUE ) && - rec->FieldDecl(i)->FindAttr(ATTR_OPTIONAL) ) + rec->FieldDecl(i)->GetAttr(ATTR_OPTIONAL) ) { reporter->Info("Encountered incompatible type \"%s\" in type definition for field \"%s\" in ReaderFrontend. Ignoring optional field.", type_name(rec->GetFieldType(i)->Tag()), name.c_str()); continue; @@ -911,7 +911,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, { string prep = nameprepend + rec->FieldName(i) + "."; - if ( rec->FieldDecl(i)->FindAttr(ATTR_OPTIONAL) ) + if ( rec->FieldDecl(i)->GetAttr(ATTR_OPTIONAL) ) { reporter->Info("The input framework does not support optional record fields: \"%s\"", rec->FieldName(i)); return false; @@ -940,11 +940,11 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, st = rec->GetFieldType(i)->AsVectorType()->Yield()->Tag(); else if ( ty == TYPE_PORT && - rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN) ) + rec->FieldDecl(i)->GetAttr(ATTR_TYPE_COLUMN) ) { // we have an annotation for the second column - c = rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN)->GetExpr()->Eval(nullptr); + c = rec->FieldDecl(i)->GetAttr(ATTR_TYPE_COLUMN)->GetExpr()->Eval(nullptr); assert(c); assert(c->GetType()->Tag() == TYPE_STRING); @@ -952,7 +952,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, secondary = c->AsStringVal()->AsString()->CheckString(); } - if ( rec->FieldDecl(i)->FindAttr(ATTR_OPTIONAL ) ) + if ( rec->FieldDecl(i)->GetAttr(ATTR_OPTIONAL ) ) optional = true; Field* field = new Field(name.c_str(), secondary, ty, st, optional); @@ -1866,7 +1866,7 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v // Hence -> assign null to the field, done. // Better check that it really is optional. Uou never know. - assert(request_type->FieldDecl(i)->FindAttr(ATTR_OPTIONAL)); + assert(request_type->FieldDecl(i)->GetAttr(ATTR_OPTIONAL)); } else { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index e585aea078..7fc6cab918 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -242,7 +242,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) for ( int i = 0; i < columns->NumFields(); i++ ) { - if ( ! (columns->FieldDecl(i)->FindAttr(ATTR_LOG)) ) + if ( ! (columns->FieldDecl(i)->GetAttr(ATTR_LOG)) ) continue; if ( ! threading::Value::IsCompatibleType(columns->GetFieldType(i).get()) ) @@ -410,7 +410,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, const auto& t = rtype->GetFieldType(i); // Ignore if &log not specified. - if ( ! rtype->FieldDecl(i)->FindAttr(ATTR_LOG) ) + if ( ! rtype->FieldDecl(i)->GetAttr(ATTR_LOG) ) continue; list new_indices = indices; @@ -516,7 +516,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, else if ( t->Tag() == TYPE_VECTOR ) st = t->AsVectorType()->Yield()->Tag(); - bool optional = rtype->FieldDecl(i)->FindAttr(ATTR_OPTIONAL); + bool optional = (bool)rtype->FieldDecl(i)->GetAttr(ATTR_OPTIONAL); filter->fields[filter->num_fields - 1] = new threading::Field(new_path.c_str(), nullptr, t->Tag(), st, optional); } From ce6f69cd19f5563c87d978a4e82c7c7018ea892d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 15:46:46 -0700 Subject: [PATCH 142/151] Deprecate TableVal::FindAttr(), replace with GetAttr() --- src/Val.cc | 9 +++++---- src/Val.h | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Val.cc b/src/Val.cc index dbfe7bed59..0d45446315 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1813,7 +1813,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) IntrusivePtr TableVal::Default(const IntrusivePtr& index) { - Attr* def_attr = FindAttr(ATTR_DEFAULT); + const auto& def_attr = GetAttr(ATTR_DEFAULT); if ( ! def_attr ) return nullptr; @@ -2199,9 +2199,9 @@ ListVal* TableVal::ConvertToPureList() const return ToPureListVal().release(); } -Attr* TableVal::FindAttr(attr_tag t) const +const IntrusivePtr& TableVal::GetAttr(attr_tag t) const { - return attrs ? attrs->Find(t).get() : nullptr; + return attrs ? attrs->Find(t) : Attr::nil; } void TableVal::Describe(ODesc* d) const @@ -2340,7 +2340,8 @@ void TableVal::InitDefaultFunc(Frame* f) if ( def_val ) return; - Attr* def_attr = FindAttr(ATTR_DEFAULT); + const auto& def_attr = GetAttr(ATTR_DEFAULT); + if ( ! def_attr ) return; diff --git a/src/Val.h b/src/Val.h index 70baef9aa7..b6a2bf2f9c 100644 --- a/src/Val.h +++ b/src/Val.h @@ -930,7 +930,12 @@ public: ListVal* ConvertToPureList() const; // must be single index type void SetAttrs(IntrusivePtr attrs); - Attr* FindAttr(attr_tag t) const; + + [[deprecated("Remove in v4.1. Use GetAttr().")]] + Attr* FindAttr(attr_tag t) const + { return GetAttr(t).get(); } + + const IntrusivePtr& GetAttr(attr_tag t) const; [[deprecated("Remove in v4.1. Use GetAttrs().")]] Attributes* Attrs() { return attrs.get(); } From 8b6de5852c876009770e76e582e669fa7eb7c44d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 26 May 2020 18:19:29 -0700 Subject: [PATCH 143/151] Switch parsing to use vector> from attr_list This allows improved passing/storing of Attr references to Exprs, TypeDecl, Scope, etc. --- src/Expr.cc | 80 +++++++++++------------------- src/Expr.h | 29 +++++++---- src/Func.cc | 4 +- src/Scope.cc | 19 +++----- src/Scope.h | 13 +++-- src/Type.cc | 42 ++++------------ src/Type.h | 11 +++-- src/Var.cc | 82 ++++++++++++------------------- src/Var.h | 19 +++++--- src/parse.y | 134 +++++++++++++++++++++++++++------------------------ 10 files changed, 194 insertions(+), 239 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 6c6b94b868..10a149d0e4 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2002,7 +2002,7 @@ void RefExpr::Assign(Frame* f, IntrusivePtr v) AssignExpr::AssignExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, bool arg_is_init, IntrusivePtr arg_val, - attr_list* arg_attrs) + const IntrusivePtr& attrs) : BinaryExpr(EXPR_ASSIGN, arg_is_init ? std::move(arg_op1) : arg_op1->MakeLvalue(), std::move(arg_op2)) @@ -2027,14 +2027,14 @@ AssignExpr::AssignExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, // We discard the status from TypeCheck since it has already // generated error messages. - (void) TypeCheck(arg_attrs); + (void) TypeCheck(attrs); val = std::move(arg_val); SetLocationInfo(op1->GetLocationInfo(), op2->GetLocationInfo()); } -bool AssignExpr::TypeCheck(attr_list* attrs) +bool AssignExpr::TypeCheck(const IntrusivePtr& attrs) { TypeTag bt1 = op1->GetType()->Tag(); TypeTag bt2 = op2->GetType()->Tag(); @@ -2069,22 +2069,19 @@ bool AssignExpr::TypeCheck(attr_list* attrs) if ( bt1 == TYPE_TABLE && op2->Tag() == EXPR_LIST ) { - attr_list* attr_copy = nullptr; + std::unique_ptr>> attr_copy; if ( attrs ) - { - attr_copy = new attr_list(attrs->length()); - std::copy(attrs->begin(), attrs->end(), std::back_inserter(*attr_copy)); - } + attr_copy = std::make_unique>>(attrs->Attrs()); bool empty_list_assignment = (op2->AsListExpr()->Exprs().empty()); if ( op1->GetType()->IsSet() ) op2 = make_intrusive( - IntrusivePtr{NewRef{}, op2->AsListExpr()}, attr_copy); + cast_intrusive(op2), std::move(attr_copy)); else op2 = make_intrusive( - IntrusivePtr{NewRef{}, op2->AsListExpr()}, attr_copy); + cast_intrusive(op2), std::move(attr_copy)); if ( ! empty_list_assignment && ! same_type(op1->GetType(), op2->GetType()) ) { @@ -2166,23 +2163,19 @@ bool AssignExpr::TypeCheck(attr_list* attrs) return false; } - attr_list* attr_copy = nullptr; + std::unique_ptr>> attr_copy; - if ( sce->Attrs() ) + + if ( sce->GetAttrs() ) { - const auto& a = sce->Attrs()->Attrs(); - attr_copy = new attr_list(a.size()); - - for ( const auto& attr : a ) - { - ::Ref(attr.get()); - attrs->push_back(attr.get()); - } + const auto& a = sce->GetAttrs()->Attrs(); + attr_copy = std::make_unique>>(a); } int errors_before = reporter->Errors(); op2 = make_intrusive( - IntrusivePtr{NewRef{}, ctor_list}, attr_copy, + IntrusivePtr{NewRef{}, ctor_list}, + std::move(attr_copy), op1->GetType()); int errors_after = reporter->Errors(); @@ -2286,7 +2279,7 @@ void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const if ( IsError() ) return; - TypeDecl td(nullptr, nullptr); + TypeDecl td; if ( IsRecordElement(&td) ) { @@ -2341,7 +2334,7 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) if ( IsError() ) return nullptr; - TypeDecl td(nullptr, nullptr); + TypeDecl td; if ( IsRecordElement(&td) ) { @@ -2997,7 +2990,7 @@ RecordConstructorExpr::RecordConstructorExpr(IntrusivePtr constructor_ FieldAssignExpr* field = (FieldAssignExpr*) e; const auto& field_type = field->GetType(); char* field_name = copy_string(field->FieldName()); - record_types->push_back(new TypeDecl(field_type, field_name)); + record_types->push_back(new TypeDecl(field_name, field_type)); } SetType(make_intrusive(record_types)); @@ -3051,10 +3044,9 @@ void RecordConstructorExpr::ExprDescribe(ODesc* d) const } TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_list, - attr_list* arg_attrs, + std::unique_ptr>> arg_attrs, IntrusivePtr arg_type) - : UnaryExpr(EXPR_TABLE_CONSTRUCTOR, std::move(constructor_list)), - attrs(nullptr) + : UnaryExpr(EXPR_TABLE_CONSTRUCTOR, std::move(constructor_list)) { if ( IsError() ) return; @@ -3088,15 +3080,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li } if ( arg_attrs ) - { - std::vector> attrv; - - for ( auto& a : *arg_attrs ) - attrv.emplace_back(AdoptRef{}, a); - - attrs = new Attributes(std::move(attrv), type, false, false); - delete arg_attrs; - } + attrs = make_intrusive(std::move(*arg_attrs), type, false, false); const auto& indices = type->AsTableType()->GetIndices()->Types(); const expr_list& cle = op->AsListExpr()->Exprs(); @@ -3144,8 +3128,7 @@ IntrusivePtr TableConstructorExpr::Eval(Frame* f) const if ( IsError() ) return nullptr; - auto aggr = make_intrusive(GetType(), - IntrusivePtr{NewRef{}, attrs}); + auto aggr = make_intrusive(GetType(), attrs); const expr_list& exprs = op->AsListExpr()->Exprs(); for ( const auto& expr : exprs ) @@ -3165,7 +3148,7 @@ IntrusivePtr TableConstructorExpr::InitVal(const BroType* t, IntrusivePtr{AdoptRef{}, aggr.release()->AsTableVal()} : - make_intrusive(std::move(tt), IntrusivePtr{NewRef{}, attrs}); + make_intrusive(std::move(tt), attrs); const expr_list& exprs = op->AsListExpr()->Exprs(); for ( const auto& expr : exprs ) @@ -3182,10 +3165,9 @@ void TableConstructorExpr::ExprDescribe(ODesc* d) const } SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, - attr_list* arg_attrs, + std::unique_ptr>> arg_attrs, IntrusivePtr arg_type) - : UnaryExpr(EXPR_SET_CONSTRUCTOR, std::move(constructor_list)), - attrs(nullptr) + : UnaryExpr(EXPR_SET_CONSTRUCTOR, std::move(constructor_list)) { if ( IsError() ) return; @@ -3216,15 +3198,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, SetError("values in set(...) constructor do not specify a set"); if ( arg_attrs ) - { - std::vector> attrv; - - for ( auto& a : *arg_attrs ) - attrv.emplace_back(AdoptRef{}, a); - - attrs = new Attributes(std::move(attrv), type, false, false); - delete arg_attrs; - } + attrs = make_intrusive(std::move(*arg_attrs), type, false, false); const auto& indices = type->AsTableType()->GetIndices()->Types(); expr_list& cle = op->AsListExpr()->Exprs(); @@ -3264,7 +3238,7 @@ IntrusivePtr SetConstructorExpr::Eval(Frame* f) const return nullptr; auto aggr = make_intrusive(IntrusivePtr{NewRef{}, type->AsTableType()}, - IntrusivePtr{NewRef{}, attrs}); + attrs); const expr_list& exprs = op->AsListExpr()->Exprs(); for ( const auto& expr : exprs ) @@ -3285,7 +3259,7 @@ IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtr(); auto tval = aggr ? IntrusivePtr{AdoptRef{}, aggr.release()->AsTableVal()} : - make_intrusive(std::move(tt), IntrusivePtr{NewRef{}, attrs}); + make_intrusive(std::move(tt), attrs); const expr_list& exprs = op->AsListExpr()->Exprs(); for ( const auto& e : exprs ) diff --git a/src/Expr.h b/src/Expr.h index 28c7d909fe..cd09920522 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -519,7 +519,8 @@ public: // If val is given, evaluating this expression will always yield the val // yet still perform the assignment. Used for triggers. AssignExpr(IntrusivePtr op1, IntrusivePtr op2, bool is_init, - IntrusivePtr val = nullptr, attr_list* attrs = nullptr); + IntrusivePtr val = nullptr, + const IntrusivePtr& attrs = nullptr); IntrusivePtr Eval(Frame* f) const override; void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override; @@ -529,7 +530,7 @@ public: bool IsPure() const override; protected: - bool TypeCheck(attr_list* attrs = nullptr); + bool TypeCheck(const IntrusivePtr& attrs = nullptr); bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2); bool is_init; @@ -630,11 +631,15 @@ protected: class TableConstructorExpr final : public UnaryExpr { public: - TableConstructorExpr(IntrusivePtr constructor_list, attr_list* attrs, + TableConstructorExpr(IntrusivePtr constructor_list, + std::unique_ptr>> attrs, IntrusivePtr arg_type = nullptr); - ~TableConstructorExpr() override { Unref(attrs); } - Attributes* Attrs() { return attrs; } + [[deprecated("Remove in v4.1. Use GetAttrs().")]] + Attributes* Attrs() { return attrs.get(); } + + const IntrusivePtr& GetAttrs() const + { return attrs; } IntrusivePtr Eval(Frame* f) const override; @@ -643,16 +648,20 @@ protected: void ExprDescribe(ODesc* d) const override; - Attributes* attrs; + IntrusivePtr attrs; }; class SetConstructorExpr final : public UnaryExpr { public: - SetConstructorExpr(IntrusivePtr constructor_list, attr_list* attrs, + SetConstructorExpr(IntrusivePtr constructor_list, + std::unique_ptr>> attrs, IntrusivePtr arg_type = nullptr); - ~SetConstructorExpr() override { Unref(attrs); } - Attributes* Attrs() { return attrs; } + [[deprecated("Remove in v4.1. Use GetAttrs().")]] + Attributes* Attrs() { return attrs.get(); } + + const IntrusivePtr& GetAttrs() const + { return attrs; } IntrusivePtr Eval(Frame* f) const override; @@ -661,7 +670,7 @@ protected: void ExprDescribe(ODesc* d) const override; - Attributes* attrs; + IntrusivePtr attrs; }; class VectorConstructorExpr final : public UnaryExpr { diff --git a/src/Func.cc b/src/Func.cc index 18875ff742..ae557bee67 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -840,7 +840,7 @@ bool check_built_in_call(BuiltinFunc* f, CallExpr* call) // Gets a function's priority from its Scope's attributes. Errors if it sees any // problems. -static int get_func_priority(const attr_list& attrs) +static int get_func_priority(const std::vector>& attrs) { int priority = 0; @@ -883,7 +883,7 @@ function_ingredients::function_ingredients(IntrusivePtr scope, IntrusiveP this->scope = std::move(scope); id = {NewRef{}, this->scope->ScopeID()}; - auto attrs = this->scope->Attrs(); + const auto& attrs = this->scope->Attrs(); priority = (attrs ? get_func_priority(*attrs) : 0); this->body = std::move(body); diff --git a/src/Scope.cc b/src/Scope.cc index 9378b477df..c7eaf9fdca 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -15,10 +15,10 @@ typedef PList scope_list; static scope_list scopes; static Scope* top_scope; -Scope::Scope(IntrusivePtr id, attr_list* al) - : scope_id(std::move(id)) +Scope::Scope(IntrusivePtr id, + std::unique_ptr>> al) + : scope_id(std::move(id)), attrs(std::move(al)) { - attrs = al; return_type = nullptr; inits = new id_list; @@ -39,14 +39,6 @@ Scope::Scope(IntrusivePtr id, attr_list* al) Scope::~Scope() { - if ( attrs ) - { - for ( const auto& attr : *attrs ) - Unref(attr); - - delete attrs; - } - if ( inits ) { for ( const auto& i : *inits ) @@ -210,9 +202,10 @@ void push_existing_scope(Scope* scope) scopes.push_back(scope); } -void push_scope(IntrusivePtr id, attr_list* attrs) +void push_scope(IntrusivePtr id, + std::unique_ptr>> attrs) { - top_scope = new Scope(std::move(id), attrs); + top_scope = new Scope(std::move(id), std::move(attrs)); scopes.push_back(top_scope); } diff --git a/src/Scope.h b/src/Scope.h index 5201d1b5e0..93c20213ca 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -19,7 +19,8 @@ class ListVal; class Scope : public BroObj { public: - explicit Scope(IntrusivePtr id, attr_list* al); + explicit Scope(IntrusivePtr id, + std::unique_ptr>> al); ~Scope() override; const IntrusivePtr& Find(std::string_view name) const; @@ -35,7 +36,10 @@ public: IntrusivePtr Remove(std::string_view name); ID* ScopeID() const { return scope_id.get(); } - attr_list* Attrs() const { return attrs; } + + const std::unique_ptr>>& Attrs() const + { return attrs; } + BroType* ReturnType() const { return return_type.get(); } size_t Length() const { return local.size(); } @@ -56,7 +60,7 @@ public: protected: IntrusivePtr scope_id; - attr_list* attrs; + std::unique_ptr>> attrs; IntrusivePtr return_type; std::map, std::less<>> local; id_list* inits; @@ -74,7 +78,8 @@ extern const IntrusivePtr& lookup_ID(const char* name, const char* module, extern IntrusivePtr install_ID(const char* name, const char* module_name, bool is_global, bool is_export); -extern void push_scope(IntrusivePtr id, attr_list* attrs); +extern void push_scope(IntrusivePtr id, + std::unique_ptr>> attrs); extern void push_existing_scope(Scope* scope); // Returns the one popped off. diff --git a/src/Type.cc b/src/Type.cc index 4e2d3790ba..382da6cb8c 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -607,21 +607,12 @@ std::optional FuncType::FindPrototype(const RecordType& arg return {}; } -TypeDecl::TypeDecl(IntrusivePtr t, const char* i, attr_list* arg_attrs, bool in_record) +TypeDecl::TypeDecl(const char* i, IntrusivePtr t, + IntrusivePtr arg_attrs) : type(std::move(t)), + attrs(std::move(arg_attrs)), id(i) - { - if ( arg_attrs ) - { - std::vector> attrv; - - for ( auto& a : *arg_attrs ) - attrv.emplace_back(AdoptRef{}, a); - - attrs = make_intrusive(std::move(attrv), type, in_record, false); - delete arg_attrs; - } - } + {} TypeDecl::TypeDecl(const TypeDecl& other) { @@ -832,35 +823,24 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const return rval; } -const char* RecordType::AddFields(type_decl_list* others, attr_list* attr) +const char* RecordType::AddFields(const type_decl_list& others, + bool add_log_attr) { assert(types); bool log = false; - if ( attr ) - { - for ( const auto& at : *attr ) - { - if ( at->Tag() == ATTR_LOG ) - log = true; - } - } - - for ( const auto& td : *others ) + for ( const auto& td : others ) { if ( ! td->GetAttr(ATTR_DEFAULT) && ! td->GetAttr(ATTR_OPTIONAL) ) - { - delete others; return "extension field must be &optional or have &default"; - } } TableVal::SaveParseTimeTableState(this); - for ( const auto& td : *others ) + for ( const auto& td : others ) { - if ( log ) + if ( add_log_attr ) { if ( ! td->attrs ) td->attrs = make_intrusive(td->type, true, false); @@ -871,8 +851,6 @@ const char* RecordType::AddFields(type_decl_list* others, attr_list* attr) types->push_back(td); } - delete others; - num_fields = types->length(); RecordVal::ResizeParseTimeRecords(this); TableVal::RebuildParseTimeTables(); @@ -1878,7 +1856,7 @@ IntrusivePtr merge_types(const IntrusivePtr& arg_t1, return nullptr; } - tdl3->push_back(new TypeDecl(std::move(tdl3_i), copy_string(td1->id))); + tdl3->push_back(new TypeDecl(copy_string(td1->id), std::move(tdl3_i))); } return make_intrusive(tdl3); diff --git a/src/Type.h b/src/Type.h index bb5f8fc0ba..80cd024ce5 100644 --- a/src/Type.h +++ b/src/Type.h @@ -562,7 +562,8 @@ protected: class TypeDecl final { public: - TypeDecl(IntrusivePtr t, const char* i, attr_list* attrs = nullptr, bool in_record = false); + TypeDecl() = default; + TypeDecl(const char* i, IntrusivePtr t, IntrusivePtr attrs = nullptr); TypeDecl(const TypeDecl& other); ~TypeDecl(); @@ -577,7 +578,7 @@ public: IntrusivePtr type; IntrusivePtr attrs; - const char* id; + const char* id = nullptr; }; typedef PList type_decl_list; @@ -656,9 +657,9 @@ public: */ IntrusivePtr GetRecordFieldsVal(const RecordVal* rv = nullptr) const; - // Returns 0 if all is ok, otherwise a pointer to an error message. - // Takes ownership of list. - const char* AddFields(type_decl_list* types, attr_list* attr); + // Returns null if all is ok, otherwise a pointer to an error message. + const char* AddFields(const type_decl_list& types, + bool add_log_attr = false); void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool roles_only = false) const override; diff --git a/src/Var.cc b/src/Var.cc index 5449fe939e..8e64f27b99 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -30,7 +30,8 @@ static IntrusivePtr init_val(Expr* init, const BroType* t, } } -static bool add_prototype(ID* id, BroType* t, attr_list* attrs, +static bool add_prototype(ID* id, BroType* t, + std::vector>* attrs, const IntrusivePtr& init) { if ( ! IsFunc(id->GetType()->Tag()) ) @@ -108,7 +109,9 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs, } static void make_var(ID* id, IntrusivePtr t, init_class c, - IntrusivePtr init, attr_list* attr, decl_type dt, + IntrusivePtr init, + std::unique_ptr>> attr, + decl_type dt, bool do_init) { if ( id->GetType() ) @@ -123,7 +126,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, else if ( dt != VAR_REDEF || init || ! attr ) { if ( IsFunc(id->GetType()->Tag()) ) - add_prototype(id, t.get(), attr, init); + add_prototype(id, t.get(), attr.get(), init); else id->Error("already defined", init.get()); @@ -196,14 +199,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, id->SetType(t); if ( attr ) - { - std::vector> attrv; - - for ( auto& a : *attr) - attrv.emplace_back(AdoptRef{}, a); - - id->AddAttrs(make_intrusive(std::move(attrv), t, false, id->IsGlobal())); - } + id->AddAttrs(make_intrusive(std::move(*attr), t, false, id->IsGlobal())); if ( init ) { @@ -211,16 +207,16 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, case EXPR_TABLE_CONSTRUCTOR: { TableConstructorExpr* ctor = (TableConstructorExpr*) init.get(); - if ( ctor->Attrs() ) - id->AddAttrs({NewRef{}, ctor->Attrs()}); + if ( ctor->GetAttrs() ) + id->AddAttrs(ctor->GetAttrs()); } break; case EXPR_SET_CONSTRUCTOR: { SetConstructorExpr* ctor = (SetConstructorExpr*) init.get(); - if ( ctor->Attrs() ) - id->AddAttrs({NewRef{}, ctor->Attrs()}); + if ( ctor->GetAttrs() ) + id->AddAttrs(ctor->GetAttrs()); } break; @@ -312,16 +308,19 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, void add_global(ID* id, IntrusivePtr t, init_class c, - IntrusivePtr init, attr_list* attr, decl_type dt) + IntrusivePtr init, + std::unique_ptr>> attr, + decl_type dt) { - make_var(id, std::move(t), c, std::move(init), attr, dt, true); + make_var(id, std::move(t), c, std::move(init), std::move(attr), dt, true); } IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, init_class c, IntrusivePtr init, - attr_list* attr, decl_type dt) + std::unique_ptr>> attr, + decl_type dt) { - make_var(id.get(), std::move(t), c, init, attr, dt, false); + make_var(id.get(), std::move(t), c, init, std::move(attr), dt, false); if ( init ) { @@ -333,20 +332,9 @@ IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, *init->GetLocationInfo() : no_location; auto name_expr = make_intrusive(id, dt == VAR_CONST); - attr_list* attrs = nullptr; - - if ( id->GetAttrs() ) - { - attrs = new attr_list(id->GetAttrs()->Attrs().size()); - - for ( const auto& a : id->GetAttrs()->Attrs() ) - attrs->push_back(a.get()); - } - auto assign_expr = make_intrusive(std::move(name_expr), std::move(init), 0, - nullptr, attrs); - delete attrs; + nullptr, id->GetAttrs()); auto stmt = make_intrusive(std::move(assign_expr)); stmt->SetLocationInfo(&location); return stmt; @@ -369,7 +357,8 @@ extern IntrusivePtr add_and_assign_local(IntrusivePtr id, false, std::move(val)); } -void add_type(ID* id, IntrusivePtr t, attr_list* attr) +void add_type(ID* id, IntrusivePtr t, + std::unique_ptr>> attr) { std::string new_type_name = id->Name(); std::string old_type_name = t->GetName(); @@ -394,15 +383,7 @@ void add_type(ID* id, IntrusivePtr t, attr_list* attr) id->MakeType(); if ( attr ) - { - std::vector> attrv; - - for ( auto& a : *attr ) - attrv.emplace_back(AdoptRef{}, a); - - id->SetAttrs(make_intrusive(std::move(attrv), tnew, false, false)); - delete attr; - } + id->SetAttrs(make_intrusive(std::move(*attr), tnew, false, false)); } static void transfer_arg_defaults(RecordType* args, RecordType* recv) @@ -430,23 +411,18 @@ static void transfer_arg_defaults(RecordType* args, RecordType* recv) } } -static Attr* find_attr(const attr_list* al, attr_tag tag) +static Attr* find_attr(const std::vector>* al, attr_tag tag) { if ( ! al ) return nullptr; - for ( int i = 0; i < al->length(); ++i ) + for ( size_t i = 0; i < al->size(); ++i ) if ( (*al)[i]->Tag() == tag ) - return (*al)[i]; + return (*al)[i].get(); return nullptr; } -static bool has_attr(const attr_list* al, attr_tag tag) - { - return find_attr(al, tag) != nullptr; - } - static std::optional func_type_check(const FuncType* decl, const FuncType* impl) { if ( decl->Flavor() != impl->Flavor() ) @@ -483,7 +459,8 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl } void begin_func(ID* id, const char* module_name, function_flavor flavor, - bool is_redef, IntrusivePtr t, attr_list* attrs) + bool is_redef, IntrusivePtr t, + std::unique_ptr>> attrs) { if ( flavor == FUNC_FLAVOR_EVENT ) { @@ -580,7 +557,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, else id->SetType(t); - push_scope({NewRef{}, id}, attrs); + push_scope({NewRef{}, id}, std::move(attrs)); const auto& args = t->Params(); int num_args = args->NumFields(); @@ -600,7 +577,8 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, arg_id->SetOffset(prototype->offsets[i]); } - if ( Attr* depr_attr = find_attr(attrs, ATTR_DEPRECATED) ) + if ( Attr* depr_attr = find_attr(current_scope()->Attrs().get(), + ATTR_DEPRECATED) ) id->MakeDeprecated(depr_attr->GetExpr()); } diff --git a/src/Var.h b/src/Var.h index 67d8928639..13fedce1dc 100644 --- a/src/Var.h +++ b/src/Var.h @@ -17,23 +17,30 @@ class ListVal; typedef enum { VAR_REGULAR, VAR_CONST, VAR_REDEF, VAR_OPTION, } decl_type; -extern void add_global(ID* id, IntrusivePtr t, init_class c, - IntrusivePtr init, attr_list* attr, decl_type dt); +extern void add_global(ID* id, + IntrusivePtr t, + init_class c, + IntrusivePtr init, + std::unique_ptr>> attr, + decl_type dt); extern IntrusivePtr add_local(IntrusivePtr id, - IntrusivePtr t, init_class c, - IntrusivePtr init, attr_list* attr, + IntrusivePtr t, + init_class c, + IntrusivePtr init, + std::unique_ptr>> attr, decl_type dt); extern IntrusivePtr add_and_assign_local(IntrusivePtr id, IntrusivePtr init, IntrusivePtr val = nullptr); -extern void add_type(ID* id, IntrusivePtr t, attr_list* attr); +extern void add_type(ID* id, IntrusivePtr t, + std::unique_ptr>> attr); extern void begin_func(ID* id, const char* module_name, function_flavor flavor, bool is_redef, IntrusivePtr t, - attr_list* attrs = nullptr); + std::unique_ptr>> attrs = nullptr); extern void end_func(IntrusivePtr body); diff --git a/src/parse.y b/src/parse.y index 6930c7e5e9..1a3aa37424 100644 --- a/src/parse.y +++ b/src/parse.y @@ -167,36 +167,8 @@ static void parser_redef_enum (ID *id) } } -static type_decl_list* copy_type_decl_list(type_decl_list* tdl) - { - if ( ! tdl ) - return 0; - - type_decl_list* rval = new type_decl_list(); - - for ( const auto& td : *tdl ) - rval->push_back(new TypeDecl(*td)); - - return rval; - } - -static attr_list* copy_attr_list(attr_list* al) - { - if ( ! al ) - return 0; - - attr_list* rval = new attr_list(); - - for ( const auto& a : *al ) - { - ::Ref(a); - rval->push_back(a); - } - - return rval; - } - -static void extend_record(ID* id, type_decl_list* fields, attr_list* attrs) +static void extend_record(ID* id, std::unique_ptr fields, + std::unique_ptr>> attrs) { std::set types = BroType::GetAliases(id->Name()); @@ -206,17 +178,19 @@ static void extend_record(ID* id, type_decl_list* fields, attr_list* attrs) return; } - for ( std::set::const_iterator it = types.begin(); it != types.end(); ) - { - RecordType* add_to = (*it)->AsRecordType(); - const char* error = 0; - ++it; + bool add_log_attr = false; - if ( it == types.end() ) - error = add_to->AddFields(fields, attrs); - else - error = add_to->AddFields(copy_type_decl_list(fields), - copy_attr_list(attrs)); + if ( attrs ) + for ( const auto& at : *attrs ) + if ( at->Tag() == ATTR_LOG ) + { + add_log_attr = true; + break; + } + + for ( auto t : types ) + { + auto error = t->AsRecordType()->AddFields(*fields, add_log_attr); if ( error ) { @@ -226,6 +200,19 @@ static void extend_record(ID* id, type_decl_list* fields, attr_list* attrs) } } +static IntrusivePtr +make_attributes(std::vector>* attrs, + IntrusivePtr t, bool in_record, bool is_global) + { + if ( ! attrs ) + return nullptr; + + auto rval = make_intrusive(std::move(*attrs), std::move(t), + in_record, is_global); + delete attrs; + return rval; + } + static bool expr_is_table_type_name(const Expr* expr) { if ( expr->Tag() != EXPR_NAME ) @@ -264,7 +251,7 @@ static bool expr_is_table_type_name(const Expr* expr) Case* c_case; case_list* case_l; Attr* attr; - attr_list* attr_l; + std::vector>* attr_l; attr_tag attrtag; } @@ -576,13 +563,15 @@ expr: opt_attr { // the ++in_init fixes up the parsing of "[x] = y" set_location(@1, @5); - $$ = new TableConstructorExpr({AdoptRef{}, $4}, $7); + std::unique_ptr>> attrs{$7}; + $$ = new TableConstructorExpr({AdoptRef{}, $4}, std::move(attrs)); } | TOK_SET '(' opt_expr_list ')' opt_attr { set_location(@1, @4); - $$ = new SetConstructorExpr({AdoptRef{}, $3}, $5); + std::unique_ptr>> attrs{$5}; + $$ = new SetConstructorExpr({AdoptRef{}, $3}, std::move(attrs)); } | TOK_VECTOR '(' opt_expr_list ')' @@ -1046,7 +1035,8 @@ type_decl: TOK_ID ':' type opt_attr ';' { set_location(@1, @4); - $$ = new TypeDecl({AdoptRef{}, $3}, $1, $4, (in_record > 0)); + auto attrs = make_attributes($4, {NewRef{}, $3}, in_record > 0, false); + $$ = new TypeDecl($1, {AdoptRef{}, $3}, std::move(attrs)); if ( in_record > 0 && cur_decl_type_id ) zeekygen_mgr->RecordField(cur_decl_type_id, $$, ::filename); @@ -1075,7 +1065,8 @@ formal_args_decl: TOK_ID ':' type opt_attr { set_location(@1, @4); - $$ = new TypeDecl({AdoptRef{}, $3}, $1, $4, true); + auto attrs = make_attributes($4, {NewRef{}, $3}, true, false); + $$ = new TypeDecl($1, {AdoptRef{}, $3}, std::move(attrs)); } ; @@ -1092,21 +1083,27 @@ decl: | TOK_GLOBAL def_global_id opt_type init_class opt_init opt_attr ';' { IntrusivePtr id{AdoptRef{}, $2}; - add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, $6, VAR_REGULAR); + add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, + std::unique_ptr>>{$6}, + VAR_REGULAR); zeekygen_mgr->Identifier(std::move(id)); } | TOK_OPTION def_global_id opt_type init_class opt_init opt_attr ';' { IntrusivePtr id{AdoptRef{}, $2}; - add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, $6, VAR_OPTION); + add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, + std::unique_ptr>>{$6}, + VAR_OPTION); zeekygen_mgr->Identifier(std::move(id)); } | TOK_CONST def_global_id opt_type init_class opt_init opt_attr ';' { IntrusivePtr id{AdoptRef{}, $2}; - add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, $6, VAR_CONST); + add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, + std::unique_ptr>>{$6}, + VAR_CONST); zeekygen_mgr->Identifier(std::move(id)); } @@ -1114,7 +1111,9 @@ decl: { IntrusivePtr id{AdoptRef{}, $2}; IntrusivePtr init{AdoptRef{}, $5}; - add_global(id.get(), {AdoptRef{}, $3}, $4, init, $6, VAR_REDEF); + add_global(id.get(), {AdoptRef{}, $3}, $4, init, + std::unique_ptr>>{$6}, + VAR_REDEF); zeekygen_mgr->Redef(id.get(), ::filename, $4, std::move(init)); } @@ -1138,7 +1137,8 @@ decl: if ( ! $3->GetType() ) $3->Error("unknown identifier"); else - extend_record($3, $8, $11); + extend_record($3, std::unique_ptr($8), + std::unique_ptr>>($11)); } | TOK_TYPE global_id ':' @@ -1147,7 +1147,8 @@ decl: { cur_decl_type_id = 0; IntrusivePtr id{AdoptRef{}, $2}; - add_type(id.get(), {AdoptRef{}, $5}, $6); + add_type(id.get(), {AdoptRef{}, $5}, + std::unique_ptr>>{$6}); zeekygen_mgr->Identifier(std::move(id)); } @@ -1180,7 +1181,8 @@ func_hdr: { IntrusivePtr id{AdoptRef{}, $2}; begin_func(id.get(), current_module.c_str(), - FUNC_FLAVOR_FUNCTION, 0, {NewRef{}, $3}, $4); + FUNC_FLAVOR_FUNCTION, 0, {NewRef{}, $3}, + std::unique_ptr>>{$4}); $$ = $3; zeekygen_mgr->Identifier(std::move(id)); } @@ -1194,7 +1196,8 @@ func_hdr: } begin_func($2, current_module.c_str(), - FUNC_FLAVOR_EVENT, 0, {NewRef{}, $3}, $4); + FUNC_FLAVOR_EVENT, 0, {NewRef{}, $3}, + std::unique_ptr>>{$4}); $$ = $3; } | TOK_HOOK def_global_id func_params opt_attr @@ -1202,13 +1205,15 @@ func_hdr: $3->ClearYieldType(FUNC_FLAVOR_HOOK); $3->SetYieldType(base_type(TYPE_BOOL)); begin_func($2, current_module.c_str(), - FUNC_FLAVOR_HOOK, 0, {NewRef{}, $3}, $4); + FUNC_FLAVOR_HOOK, 0, {NewRef{}, $3}, + std::unique_ptr>>{$4}); $$ = $3; } | TOK_REDEF TOK_EVENT event_id func_params opt_attr { begin_func($3, current_module.c_str(), - FUNC_FLAVOR_EVENT, 1, {NewRef{}, $4}, $5); + FUNC_FLAVOR_EVENT, 1, {NewRef{}, $4}, + std::unique_ptr>>{$5}); $$ = $4; } ; @@ -1334,16 +1339,16 @@ index_slice: opt_attr: attr_list | - { $$ = 0; } + { $$ = nullptr; } ; attr_list: attr_list attr - { $1->push_back($2); } + { $1->emplace_back(AdoptRef{}, $2); } | attr { - $$ = new attr_list; - $$->push_back($1); + $$ = new std::vector>; + $$->emplace_back(AdoptRef{}, $1); } ; @@ -1509,7 +1514,9 @@ stmt: { set_location(@1, @7); $$ = add_local({AdoptRef{}, $2}, {AdoptRef{}, $3}, $4, - {AdoptRef{}, $5}, $6, VAR_REGULAR).release(); + {AdoptRef{}, $5}, + std::unique_ptr>>{$6}, + VAR_REGULAR).release(); if ( ! $8 ) brofiler.AddStmt($$); } @@ -1518,7 +1525,9 @@ stmt: { set_location(@1, @6); $$ = add_local({AdoptRef{}, $2}, {AdoptRef{}, $3}, $4, - {AdoptRef{}, $5}, $6, VAR_CONST).release(); + {AdoptRef{}, $5}, + std::unique_ptr>>{$6}, + VAR_CONST).release(); if ( ! $8 ) brofiler.AddStmt($$); } @@ -1664,7 +1673,8 @@ case_type: else case_var = install_ID(name, current_module.c_str(), false, false); - add_local(case_var, std::move(type), INIT_NONE, 0, 0, VAR_REGULAR); + add_local(case_var, std::move(type), INIT_NONE, nullptr, nullptr, + VAR_REGULAR); $$ = case_var.release(); } From b0c95e30d0248d4136622b582b4ca0f023989313 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 27 May 2020 16:36:14 -0700 Subject: [PATCH 144/151] Deprecate Scope::ScopeID(), replace with GetID() --- src/Func.cc | 2 +- src/Scope.h | 4 ++++ src/Stmt.cc | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Func.cc b/src/Func.cc index ae557bee67..2cbf77d82a 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -881,7 +881,7 @@ function_ingredients::function_ingredients(IntrusivePtr scope, IntrusiveP inits = scope->GetInits(); this->scope = std::move(scope); - id = {NewRef{}, this->scope->ScopeID()}; + id = this->scope->GetID(); const auto& attrs = this->scope->Attrs(); diff --git a/src/Scope.h b/src/Scope.h index 93c20213ca..9608c5ca2f 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -35,8 +35,12 @@ public: IntrusivePtr Remove(std::string_view name); + [[deprecated("Remove in v4.1. Use GetID().")]] ID* ScopeID() const { return scope_id.get(); } + const IntrusivePtr& GetID() const + { return scope_id; } + const std::unique_ptr>>& Attrs() const { return attrs; } diff --git a/src/Stmt.cc b/src/Stmt.cc index a163e6362e..485ed13c81 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1414,21 +1414,21 @@ ReturnStmt::ReturnStmt(IntrusivePtr arg_e) { Scope* s = current_scope(); - if ( ! s || ! s->ScopeID() ) + if ( ! s || ! s->GetID() ) { Error("return statement outside of function/event"); return; } - FuncType* ft = s->ScopeID()->GetType()->AsFuncType(); + FuncType* ft = s->GetID()->GetType()->AsFuncType(); const auto& yt = ft->Yield(); - if ( s->ScopeID()->DoInferReturnType() ) + if ( s->GetID()->DoInferReturnType() ) { if ( e ) { ft->SetYieldType(e->GetType()); - s->ScopeID()->SetInferReturnType(false); + s->GetID()->SetInferReturnType(false); } } From a13899c95e4ba900613964419149fc582f47ecf1 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 27 May 2020 16:38:31 -0700 Subject: [PATCH 145/151] Deprecate Scope::ReturnType(), replace with GetReturnType() --- src/Scope.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Scope.h b/src/Scope.h index 9608c5ca2f..fe72eaa72c 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -44,8 +44,12 @@ public: const std::unique_ptr>>& Attrs() const { return attrs; } + [[deprecated("Remove in v4.1. Use GetReturnTrype().")]] BroType* ReturnType() const { return return_type.get(); } + const IntrusivePtr& GetReturnType() const + { return return_type; } + size_t Length() const { return local.size(); } const auto& Vars() { return local; } From 46e23b49fb388994a6f2c5ecf60b8c1cea37ead8 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 27 May 2020 16:51:25 -0700 Subject: [PATCH 146/151] Change Scope::GenerateTemporary() to return IntrusivePtr --- src/Scope.cc | 4 ++-- src/Scope.h | 2 +- src/Var.cc | 13 +++++++------ src/Var.h | 5 +++-- src/parse.y | 22 +++++++++++----------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/Scope.cc b/src/Scope.cc index c7eaf9fdca..19e3d581c5 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -72,9 +72,9 @@ IntrusivePtr Scope::Remove(std::string_view name) return nullptr; } -ID* Scope::GenerateTemporary(const char* name) +IntrusivePtr Scope::GenerateTemporary(const char* name) { - return new ID(name, SCOPE_FUNCTION, false); + return make_intrusive(name, SCOPE_FUNCTION, false); } id_list* Scope::GetInits() diff --git a/src/Scope.h b/src/Scope.h index fe72eaa72c..931e3d742c 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -53,7 +53,7 @@ public: size_t Length() const { return local.size(); } const auto& Vars() { return local; } - ID* GenerateTemporary(const char* name); + IntrusivePtr GenerateTemporary(const char* name); // Returns the list of variables needing initialization, and // removes it from this Scope. diff --git a/src/Var.cc b/src/Var.cc index 8e64f27b99..a086f045d2 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -458,8 +458,9 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl return true; } -void begin_func(ID* id, const char* module_name, function_flavor flavor, - bool is_redef, IntrusivePtr t, +void begin_func(IntrusivePtr id, const char* module_name, + function_flavor flavor, bool is_redef, + IntrusivePtr t, std::unique_ptr>> attrs) { if ( flavor == FUNC_FLAVOR_EVENT ) @@ -512,7 +513,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, } if ( prototype->deprecated ) - t->Warn("use of deprecated prototype", id); + t->Warn("use of deprecated prototype", id.get()); } else { @@ -521,7 +522,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, if ( canonical_arg_types_match(decl, t.get()) ) prototype = decl->Prototypes()[0]; else - t->Error("use of undeclared alternate prototype", id); + t->Error("use of undeclared alternate prototype", id.get()); } } @@ -557,7 +558,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, else id->SetType(t); - push_scope({NewRef{}, id}, std::move(attrs)); + push_scope(std::move(id), std::move(attrs)); const auto& args = t->Params(); int num_args = args->NumFields(); @@ -579,7 +580,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, if ( Attr* depr_attr = find_attr(current_scope()->Attrs().get(), ATTR_DEPRECATED) ) - id->MakeDeprecated(depr_attr->GetExpr()); + current_scope()->GetID()->MakeDeprecated(depr_attr->GetExpr()); } class OuterIDBindingFinder : public TraversalCallback { diff --git a/src/Var.h b/src/Var.h index 13fedce1dc..7806e25585 100644 --- a/src/Var.h +++ b/src/Var.h @@ -38,8 +38,9 @@ extern IntrusivePtr add_and_assign_local(IntrusivePtr id, extern void add_type(ID* id, IntrusivePtr t, std::unique_ptr>> attr); -extern void begin_func(ID* id, const char* module_name, function_flavor flavor, - bool is_redef, IntrusivePtr t, +extern void begin_func(IntrusivePtr id, const char* module_name, + function_flavor flavor, bool is_redef, + IntrusivePtr t, std::unique_ptr>> attrs = nullptr); extern void end_func(IntrusivePtr body); diff --git a/src/parse.y b/src/parse.y index 1a3aa37424..bfb403f97a 100644 --- a/src/parse.y +++ b/src/parse.y @@ -134,7 +134,6 @@ bool resolving_global_ID = false; bool defining_global_ID = false; std::vector saved_in_init; -ID* func_id = 0; static Location func_hdr_location; EnumType *cur_enum_type = 0; static ID* cur_decl_type_id = 0; @@ -496,15 +495,15 @@ expr: | '$' TOK_ID func_params '=' { func_hdr_location = @1; - func_id = current_scope()->GenerateTemporary("anonymous-function"); + auto func_id = current_scope()->GenerateTemporary("anonymous-function"); func_id->SetInferReturnType(true); - begin_func(func_id, current_module.c_str(), FUNC_FLAVOR_FUNCTION, - 0, {AdoptRef{}, $3}); + begin_func(std::move(func_id), current_module.c_str(), + FUNC_FLAVOR_FUNCTION, false, + {AdoptRef{}, $3}); } lambda_body { $$ = new FieldAssignExpr($2, IntrusivePtr{AdoptRef{}, $6}); - Unref(func_id); } | expr TOK_IN expr @@ -1180,7 +1179,7 @@ func_hdr: TOK_FUNCTION def_global_id func_params opt_attr { IntrusivePtr id{AdoptRef{}, $2}; - begin_func(id.get(), current_module.c_str(), + begin_func(id, current_module.c_str(), FUNC_FLAVOR_FUNCTION, 0, {NewRef{}, $3}, std::unique_ptr>>{$4}); $$ = $3; @@ -1195,7 +1194,7 @@ func_hdr: reporter->Error("event %s() is no longer available, use zeek_%s() instead", name, base.c_str()); } - begin_func($2, current_module.c_str(), + begin_func({NewRef{}, $2}, current_module.c_str(), FUNC_FLAVOR_EVENT, 0, {NewRef{}, $3}, std::unique_ptr>>{$4}); $$ = $3; @@ -1204,14 +1203,14 @@ func_hdr: { $3->ClearYieldType(FUNC_FLAVOR_HOOK); $3->SetYieldType(base_type(TYPE_BOOL)); - begin_func($2, current_module.c_str(), + begin_func({NewRef{}, $2}, current_module.c_str(), FUNC_FLAVOR_HOOK, 0, {NewRef{}, $3}, std::unique_ptr>>{$4}); $$ = $3; } | TOK_REDEF TOK_EVENT event_id func_params opt_attr { - begin_func($3, current_module.c_str(), + begin_func({NewRef{}, $3}, current_module.c_str(), FUNC_FLAVOR_EVENT, 1, {NewRef{}, $4}, std::unique_ptr>>{$5}); $$ = $4; @@ -1275,8 +1274,9 @@ anonymous_function: begin_func: func_params { - $$ = current_scope()->GenerateTemporary("anonymous-function"); - begin_func($$, current_module.c_str(), FUNC_FLAVOR_FUNCTION, 0, {AdoptRef{}, $1}); + auto id = current_scope()->GenerateTemporary("anonymous-function"); + begin_func(id, current_module.c_str(), FUNC_FLAVOR_FUNCTION, 0, {AdoptRef{}, $1}); + $$ = id.release(); } ; From 2cee468eac1512bc3c57ae488836238b4495d238 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 27 May 2020 17:27:40 -0700 Subject: [PATCH 147/151] Change Scope/Func inits from id_list* to vector> --- src/Expr.cc | 27 ++------------------------- src/Func.cc | 24 ++++++++++-------------- src/Func.h | 20 ++++++++++++-------- src/Scope.cc | 21 ++++----------------- src/Scope.h | 8 ++++---- src/Stmt.cc | 27 ++++++++++----------------- src/Stmt.h | 9 ++++----- src/Var.cc | 3 ++- 8 files changed, 48 insertions(+), 91 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 10a149d0e4..fd53c31ede 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4168,29 +4168,6 @@ void CallExpr::ExprDescribe(ODesc* d) const args->Describe(d); } -static std::unique_ptr shallow_copy_func_inits(const IntrusivePtr& body, - const id_list* src) - { - if ( ! body ) - return nullptr; - - if ( ! src ) - return nullptr; - - if ( src->empty() ) - return nullptr; - - auto dest = std::make_unique(src->length()); - - for ( ID* i : *src ) - { - Ref(i); - dest->push_back(i); - } - - return dest; - } - LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, id_list arg_outer_ids) : Expr(EXPR_LAMBDA) { @@ -4204,7 +4181,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, auto dummy_func = make_intrusive( ingredients->id.get(), ingredients->body, - shallow_copy_func_inits(ingredients->body, ingredients->inits).release(), + ingredients->inits, ingredients->frame_size, ingredients->priority); @@ -4255,7 +4232,7 @@ IntrusivePtr LambdaExpr::Eval(Frame* f) const auto lamb = make_intrusive( ingredients->id.get(), ingredients->body, - shallow_copy_func_inits(ingredients->body, ingredients->inits).release(), + ingredients->inits, ingredients->frame_size, ingredients->priority); diff --git a/src/Func.cc b/src/Func.cc index 2cbf77d82a..e9bcd07455 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -121,8 +121,9 @@ Func::Func(Kind arg_kind) : kind(arg_kind) Func::~Func() = default; -void Func::AddBody(IntrusivePtr /* new_body */, id_list* /* new_inits */, - size_t /* new_frame_size */, int /* priority */) +void Func::AddBody(IntrusivePtr /* new_body */, + const std::vector>& /* new_inits */, + size_t /* new_frame_size */, int /* priority */) { Internal("Func::AddBody called"); } @@ -267,7 +268,8 @@ void Func::CheckPluginResult(bool handled, const IntrusivePtr& hook_result, } } -BroFunc::BroFunc(ID* arg_id, IntrusivePtr arg_body, id_list* aggr_inits, +BroFunc::BroFunc(ID* arg_id, IntrusivePtr arg_body, + const std::vector>& aggr_inits, size_t arg_frame_size, int priority) : Func(BRO_FUNC) { @@ -447,7 +449,8 @@ IntrusivePtr BroFunc::operator()(zeek::Args* args, Frame* parent) const return result; } -void BroFunc::AddBody(IntrusivePtr new_body, id_list* new_inits, +void BroFunc::AddBody(IntrusivePtr new_body, + const std::vector>& new_inits, size_t new_frame_size, int priority) { if ( new_frame_size > frame_size ) @@ -571,9 +574,10 @@ void BroFunc::Describe(ODesc* d) const } } -IntrusivePtr BroFunc::AddInits(IntrusivePtr body, id_list* inits) +IntrusivePtr BroFunc::AddInits(IntrusivePtr body, + const std::vector>& inits) { - if ( ! inits || inits->length() == 0 ) + if ( inits.empty() ) return body; auto stmt_series = make_intrusive(); @@ -889,14 +893,6 @@ function_ingredients::function_ingredients(IntrusivePtr scope, IntrusiveP this->body = std::move(body); } -function_ingredients::~function_ingredients() - { - for ( const auto& i : *inits ) - Unref(i); - - delete inits; - } - BifReturnVal::BifReturnVal(std::nullptr_t) noexcept { } diff --git a/src/Func.h b/src/Func.h index ef2cf34fab..56c4adf75b 100644 --- a/src/Func.h +++ b/src/Func.h @@ -78,7 +78,8 @@ public: } // Add a new event handler to an existing function (event). - virtual void AddBody(IntrusivePtr new_body, id_list* new_inits, + virtual void AddBody(IntrusivePtr new_body, + const std::vector>& new_inits, size_t new_frame_size, int priority = 0); virtual void SetScope(IntrusivePtr newscope); @@ -128,7 +129,10 @@ protected: class BroFunc final : public Func { public: - BroFunc(ID* id, IntrusivePtr body, id_list* inits, size_t frame_size, int priority); + BroFunc(ID* id, IntrusivePtr body, + const std::vector>& inits, + size_t frame_size, int priority); + ~BroFunc() override; bool IsPure() const override; @@ -163,8 +167,9 @@ public: */ broker::expected SerializeClosure() const; - void AddBody(IntrusivePtr new_body, id_list* new_inits, - size_t new_frame_size, int priority) override; + void AddBody(IntrusivePtr new_body, + const std::vector>& new_inits, + size_t new_frame_size, int priority) override; /** Sets this function's outer_id list. */ void SetOuterIDs(id_list ids) @@ -174,7 +179,8 @@ public: protected: BroFunc() : Func(BRO_FUNC) {} - IntrusivePtr AddInits(IntrusivePtr body, id_list* inits); + IntrusivePtr AddInits(IntrusivePtr body, + const std::vector>& inits); /** * Clones this function along with its closures. @@ -263,11 +269,9 @@ struct function_ingredients { // to build a function. function_ingredients(IntrusivePtr scope, IntrusivePtr body); - ~function_ingredients(); - IntrusivePtr id; IntrusivePtr body; - id_list* inits; + std::vector> inits; int frame_size; int priority; IntrusivePtr scope; diff --git a/src/Scope.cc b/src/Scope.cc index 19e3d581c5..657a27170e 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -21,8 +21,6 @@ Scope::Scope(IntrusivePtr id, { return_type = nullptr; - inits = new id_list; - if ( id ) { const auto& id_type = scope_id->GetType(); @@ -37,17 +35,6 @@ Scope::Scope(IntrusivePtr id, } } -Scope::~Scope() - { - if ( inits ) - { - for ( const auto& i : *inits ) - Unref(i); - - delete inits; - } - } - const IntrusivePtr& Scope::Find(std::string_view name) const { auto entry = local.find(name); @@ -77,11 +64,11 @@ IntrusivePtr Scope::GenerateTemporary(const char* name) return make_intrusive(name, SCOPE_FUNCTION, false); } -id_list* Scope::GetInits() +std::vector> Scope::GetInits() { - id_list* ids = inits; - inits = nullptr; - return ids; + auto rval = std::move(inits); + inits = {}; + return rval; } void Scope::Describe(ODesc* d) const diff --git a/src/Scope.h b/src/Scope.h index 931e3d742c..146c5c051e 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -21,7 +21,6 @@ class Scope : public BroObj { public: explicit Scope(IntrusivePtr id, std::unique_ptr>> al); - ~Scope() override; const IntrusivePtr& Find(std::string_view name) const; @@ -57,10 +56,11 @@ public: // Returns the list of variables needing initialization, and // removes it from this Scope. - id_list* GetInits(); + std::vector> GetInits(); // Adds a variable to the list. - void AddInit(IntrusivePtr id) { inits->push_back(id.release()); } + void AddInit(IntrusivePtr id) + { inits.emplace_back(std::move(id)); } void Describe(ODesc* d) const override; @@ -71,7 +71,7 @@ protected: std::unique_ptr>> attrs; IntrusivePtr return_type; std::map, std::less<>> local; - id_list* inits; + std::vector> inits; }; diff --git a/src/Stmt.cc b/src/Stmt.cc index 485ed13c81..85ba3d4ec3 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1629,19 +1629,12 @@ void EventBodyList::Describe(ODesc* d) const StmtList::Describe(d); } -InitStmt::InitStmt(id_list* arg_inits) : Stmt(STMT_INIT) +InitStmt::InitStmt(std::vector> arg_inits) : Stmt(STMT_INIT) { - inits = arg_inits; - if ( arg_inits && arg_inits->length() ) - SetLocationInfo((*arg_inits)[0]->GetLocationInfo()); - } + inits = std::move(arg_inits); -InitStmt::~InitStmt() - { - for ( const auto& init : *inits ) - Unref(init); - - delete inits; + if ( ! inits.empty() ) + SetLocationInfo(inits[0]->GetLocationInfo()); } IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const @@ -1649,7 +1642,7 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const RegisterAccess(); flow = FLOW_NEXT; - for ( const auto& aggr : *inits ) + for ( const auto& aggr : inits ) { const auto& t = aggr->GetType(); @@ -1670,7 +1663,7 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const break; } - f->SetElement(aggr, std::move(v)); + f->SetElement(aggr.get(), std::move(v)); } return nullptr; @@ -1681,14 +1674,14 @@ void InitStmt::Describe(ODesc* d) const AddTag(d); if ( ! d->IsReadable() ) - d->AddCount(inits->length()); + d->AddCount(inits.size()); - loop_over_list(*inits, i) + for ( size_t i = 0; i < inits.size(); ++i ) { if ( ! d->IsBinary() && i > 0 ) d->AddSP(","); - (*inits)[i]->Describe(d); + inits[i]->Describe(d); } DescribeDone(d); @@ -1699,7 +1692,7 @@ TraversalCode InitStmt::Traverse(TraversalCallback* cb) const TraversalCode tc = cb->PreStmt(this); HANDLE_TC_STMT_PRE(tc); - for ( const auto& init : *inits ) + for ( const auto& init : inits ) { tc = init->Traverse(cb); HANDLE_TC_STMT_PRE(tc); diff --git a/src/Stmt.h b/src/Stmt.h index 0fb57c7b23..0cc4e8ae43 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -393,20 +393,19 @@ protected: class InitStmt final : public Stmt { public: - explicit InitStmt(id_list* arg_inits); - - ~InitStmt() override; + explicit InitStmt(std::vector> arg_inits); IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; - const id_list* Inits() const { return inits; } + const std::vector>& Inits() const + { return inits; } void Describe(ODesc* d) const override; TraversalCode Traverse(TraversalCallback* cb) const override; protected: - id_list* inits; + std::vector> inits; }; class NullStmt final : public Stmt { diff --git a/src/Var.cc b/src/Var.cc index a086f045d2..b46956090f 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -301,7 +301,8 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, // For events, add a function value (without any body) here so that // we can later access the ID even if no implementations have been // defined. - auto f = make_intrusive(id, nullptr, nullptr, 0, 0); + std::vector> inits; + auto f = make_intrusive(id, nullptr, inits, 0, 0); id->SetVal(make_intrusive(std::move(f))); } } From 0d19e8fb4c21ee01d4e3ecfde950b88e5803a4db Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 27 May 2020 17:30:28 -0700 Subject: [PATCH 148/151] Add version of Frame::SetElement() taking IntrusivePtr Expect the version using raw ID* could go away eventually, but this is convenience for the meantime. --- src/Expr.cc | 2 +- src/Frame.h | 2 ++ src/Stmt.cc | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index fd53c31ede..eadefb59d9 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -273,7 +273,7 @@ void NameExpr::Assign(Frame* f, IntrusivePtr v) if ( id->IsGlobal() ) id->SetVal(std::move(v)); else - f->SetElement(id.get(), std::move(v)); + f->SetElement(id, std::move(v)); } bool NameExpr::IsPure() const diff --git a/src/Frame.h b/src/Frame.h index 6dc3a055c5..a85254469c 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -66,6 +66,8 @@ public: * @param v the value to associate it with */ void SetElement(const ID* id, IntrusivePtr v); + void SetElement(const IntrusivePtr& id, IntrusivePtr v) + { SetElement(id.get(), std::move(v)); } /** * Gets the value associated with *id* and returns it. Returns diff --git a/src/Stmt.cc b/src/Stmt.cc index 85ba3d4ec3..60b93f1201 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -1191,7 +1191,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const delete k; if ( value_var ) - f->SetElement(value_var.get(), current_tev->GetVal()); + f->SetElement(value_var, current_tev->GetVal()); for ( int i = 0; i < ind_lv->Length(); i++ ) f->SetElement((*loop_vars)[i], ind_lv->Idx(i)); @@ -1663,7 +1663,7 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const break; } - f->SetElement(aggr.get(), std::move(v)); + f->SetElement(aggr, std::move(v)); } return nullptr; From 1f45e690a0eec2164521b3ba9d6db7bde4c88b63 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 27 May 2020 17:40:02 -0700 Subject: [PATCH 149/151] Change BroFunc ctor to take const-ref IntrusivePtr --- src/Expr.cc | 4 ++-- src/Func.cc | 2 +- src/Func.h | 2 +- src/Var.cc | 16 ++++++++-------- src/Var.h | 2 +- src/parse.y | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index eadefb59d9..3943786560 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4179,7 +4179,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr arg_ing, // Install a dummy version of the function globally for use only // when broker provides a closure. auto dummy_func = make_intrusive( - ingredients->id.get(), + ingredients->id, ingredients->body, ingredients->inits, ingredients->frame_size, @@ -4230,7 +4230,7 @@ Scope* LambdaExpr::GetScope() const IntrusivePtr LambdaExpr::Eval(Frame* f) const { auto lamb = make_intrusive( - ingredients->id.get(), + ingredients->id, ingredients->body, ingredients->inits, ingredients->frame_size, diff --git a/src/Func.cc b/src/Func.cc index e9bcd07455..e8a29612bb 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -268,7 +268,7 @@ void Func::CheckPluginResult(bool handled, const IntrusivePtr& hook_result, } } -BroFunc::BroFunc(ID* arg_id, IntrusivePtr arg_body, +BroFunc::BroFunc(const IntrusivePtr& arg_id, IntrusivePtr arg_body, const std::vector>& aggr_inits, size_t arg_frame_size, int priority) : Func(BRO_FUNC) diff --git a/src/Func.h b/src/Func.h index 56c4adf75b..f861171980 100644 --- a/src/Func.h +++ b/src/Func.h @@ -129,7 +129,7 @@ protected: class BroFunc final : public Func { public: - BroFunc(ID* id, IntrusivePtr body, + BroFunc(const IntrusivePtr& id, IntrusivePtr body, const std::vector>& inits, size_t frame_size, int priority); diff --git a/src/Var.cc b/src/Var.cc index b46956090f..af1665d92a 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -30,7 +30,7 @@ static IntrusivePtr init_val(Expr* init, const BroType* t, } } -static bool add_prototype(ID* id, BroType* t, +static bool add_prototype(const IntrusivePtr& id, BroType* t, std::vector>* attrs, const IntrusivePtr& init) { @@ -39,7 +39,7 @@ static bool add_prototype(ID* id, BroType* t, if ( ! IsFunc(t->Tag()) ) { - t->Error("type incompatible with previous definition", id); + t->Error("type incompatible with previous definition", id.get()); return false; } @@ -108,7 +108,7 @@ static bool add_prototype(ID* id, BroType* t, return true; } -static void make_var(ID* id, IntrusivePtr t, init_class c, +static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt, @@ -308,8 +308,8 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, } -void add_global(ID* id, IntrusivePtr t, init_class c, - IntrusivePtr init, +void add_global(const IntrusivePtr& id, IntrusivePtr t, + init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt) { @@ -321,7 +321,7 @@ IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, std::unique_ptr>> attr, decl_type dt) { - make_var(id.get(), std::move(t), c, init, std::move(attr), dt, false); + make_var(id, std::move(t), c, init, std::move(attr), dt, false); if ( init ) { @@ -352,7 +352,7 @@ extern IntrusivePtr add_and_assign_local(IntrusivePtr id, IntrusivePtr init, IntrusivePtr val) { - make_var(id.get(), nullptr, INIT_FULL, init, nullptr, VAR_REGULAR, false); + make_var(id, nullptr, INIT_FULL, init, nullptr, VAR_REGULAR, false); auto name_expr = make_intrusive(std::move(id)); return make_intrusive(std::move(name_expr), std::move(init), false, std::move(val)); @@ -646,7 +646,7 @@ void end_func(IntrusivePtr body) else { auto f = make_intrusive( - ingredients->id.get(), + ingredients->id, ingredients->body, ingredients->inits, ingredients->frame_size, diff --git a/src/Var.h b/src/Var.h index 7806e25585..935e276f86 100644 --- a/src/Var.h +++ b/src/Var.h @@ -17,7 +17,7 @@ class ListVal; typedef enum { VAR_REGULAR, VAR_CONST, VAR_REDEF, VAR_OPTION, } decl_type; -extern void add_global(ID* id, +extern void add_global(const IntrusivePtr& id, IntrusivePtr t, init_class c, IntrusivePtr init, diff --git a/src/parse.y b/src/parse.y index bfb403f97a..59b229bdca 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1082,7 +1082,7 @@ decl: | TOK_GLOBAL def_global_id opt_type init_class opt_init opt_attr ';' { IntrusivePtr id{AdoptRef{}, $2}; - add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, + add_global(id, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, std::unique_ptr>>{$6}, VAR_REGULAR); zeekygen_mgr->Identifier(std::move(id)); @@ -1091,7 +1091,7 @@ decl: | TOK_OPTION def_global_id opt_type init_class opt_init opt_attr ';' { IntrusivePtr id{AdoptRef{}, $2}; - add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, + add_global(id, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, std::unique_ptr>>{$6}, VAR_OPTION); zeekygen_mgr->Identifier(std::move(id)); @@ -1100,7 +1100,7 @@ decl: | TOK_CONST def_global_id opt_type init_class opt_init opt_attr ';' { IntrusivePtr id{AdoptRef{}, $2}; - add_global(id.get(), {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, + add_global(id, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, std::unique_ptr>>{$6}, VAR_CONST); zeekygen_mgr->Identifier(std::move(id)); @@ -1110,7 +1110,7 @@ decl: { IntrusivePtr id{AdoptRef{}, $2}; IntrusivePtr init{AdoptRef{}, $5}; - add_global(id.get(), {AdoptRef{}, $3}, $4, init, + add_global(id, {AdoptRef{}, $3}, $4, init, std::unique_ptr>>{$6}, VAR_REDEF); zeekygen_mgr->Redef(id.get(), ::filename, $4, std::move(init)); From 82ce64ca7005de1aaf8ee3c02fb4bf3afdbb80e3 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 27 May 2020 17:56:25 -0700 Subject: [PATCH 150/151] Switch Broker Val converter visitor to return IntrusivePtr --- src/broker/Data.cc | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/broker/Data.cc b/src/broker/Data.cc index f317576eb8..0c3a04aee3 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -76,7 +76,7 @@ TEST_CASE("converting Broker to Zeek protocol constants") } struct val_converter { - using result_type = Val*; + using result_type = IntrusivePtr; BroType* type; @@ -88,30 +88,30 @@ struct val_converter { result_type operator()(bool a) { if ( type->Tag() == TYPE_BOOL ) - return val_mgr->Bool(a)->Ref(); + return val_mgr->Bool(a); return nullptr; } result_type operator()(uint64_t a) { if ( type->Tag() == TYPE_COUNT ) - return val_mgr->Count(a).release(); + return val_mgr->Count(a); if ( type->Tag() == TYPE_COUNTER ) - return val_mgr->Count(a).release(); + return val_mgr->Count(a); return nullptr; } result_type operator()(int64_t a) { if ( type->Tag() == TYPE_INT ) - return val_mgr->Int(a).release(); + return val_mgr->Int(a); return nullptr; } result_type operator()(double a) { if ( type->Tag() == TYPE_DOUBLE ) - return new Val(a, TYPE_DOUBLE); + return make_intrusive(a, TYPE_DOUBLE); return nullptr; } @@ -119,13 +119,13 @@ struct val_converter { { switch ( type->Tag() ) { case TYPE_STRING: - return new StringVal(a.size(), a.data()); + return make_intrusive(a.size(), a.data()); case TYPE_FILE: { auto file = BroFile::Get(a.data()); if ( file ) - return new Val(std::move(file)); + return make_intrusive(std::move(file)); return nullptr; } @@ -139,7 +139,7 @@ struct val_converter { if ( type->Tag() == TYPE_ADDR ) { auto bits = reinterpret_cast(&a.bytes()); - return new AddrVal(IPAddr(*bits)); + return make_intrusive(IPAddr(*bits)); } return nullptr; @@ -150,7 +150,7 @@ struct val_converter { if ( type->Tag() == TYPE_SUBNET ) { auto bits = reinterpret_cast(&a.network().bytes()); - return new SubNetVal(IPPrefix(IPAddr(*bits), a.length())); + return make_intrusive(IPPrefix(IPAddr(*bits), a.length())); } return nullptr; @@ -159,7 +159,7 @@ struct val_converter { result_type operator()(broker::port& a) { if ( type->Tag() == TYPE_PORT ) - return val_mgr->Port(a.number(), bro_broker::to_bro_port_proto(a.type()))->Ref(); + return val_mgr->Port(a.number(), bro_broker::to_bro_port_proto(a.type())); return nullptr; } @@ -171,7 +171,7 @@ struct val_converter { using namespace std::chrono; auto s = duration_cast(a.time_since_epoch()); - return new Val(s.count(), TYPE_TIME); + return make_intrusive(s.count(), TYPE_TIME); } result_type operator()(broker::timespan& a) @@ -181,7 +181,7 @@ struct val_converter { using namespace std::chrono; auto s = duration_cast(a); - return new Val(s.count(), TYPE_INTERVAL); + return make_intrusive(s.count(), TYPE_INTERVAL); } result_type operator()(broker::enum_value& a) @@ -195,7 +195,7 @@ struct val_converter { return nullptr; auto rval = etype->GetVal(i); - return rval.release(); + return rval; } return nullptr; @@ -257,7 +257,7 @@ struct val_converter { rval->Assign(std::move(list_val), nullptr); } - return rval.release(); + return rval; } result_type operator()(broker::table& a) @@ -321,7 +321,7 @@ struct val_converter { rval->Assign(std::move(list_val), std::move(value_val)); } - return rval.release(); + return rval; } result_type operator()(broker::vector& a) @@ -341,7 +341,7 @@ struct val_converter { rval->Assign(rval->Size(), std::move(item_val)); } - return rval.release(); + return rval; } else if ( type->Tag() == TYPE_FUNC ) { @@ -381,7 +381,7 @@ struct val_converter { return nullptr; } - return rval->Ref(); + return rval; } else if ( type->Tag() == TYPE_RECORD ) { @@ -411,7 +411,7 @@ struct val_converter { ++idx; } - return rval.release(); + return rval; } else if ( type->Tag() == TYPE_PATTERN ) { @@ -435,11 +435,11 @@ struct val_converter { return nullptr; } - auto rval = new PatternVal(re); + auto rval = make_intrusive(re); return rval; } else if ( type->Tag() == TYPE_OPAQUE ) - return OpaqueVal::Unserialize(a).release(); + return OpaqueVal::Unserialize(a); return nullptr; } @@ -787,7 +787,7 @@ IntrusivePtr bro_broker::data_to_val(broker::data d, BroType* type) if ( type->Tag() == TYPE_ANY ) return bro_broker::make_data_val(move(d)); - return {AdoptRef{}, caf::visit(val_converter{type}, std::move(d))}; + return caf::visit(val_converter{type}, std::move(d)); } broker::expected bro_broker::val_to_data(const Val* v) From 9c133b9b108a9cdd27c8bf9699f4eb921b0e3733 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 29 May 2020 19:04:00 -0700 Subject: [PATCH 151/151] Integrate review feedback * Add deprecation for MIME_Entity::ContentType(), use GetContentType() * Add deprecation for MIME_Entity::ContentSubType(), use GetContentSubType() * Add deprecation for MIME_Message::BuildHeaderVal(), use ToHeaderVal() * Add deprecation for MIME_Message::BuildHeaderTable(), use ToHeaderTable() * Add deprecation for mime::new_string_val(), use mime::to_stringval() * Add deprecation for ARP_Analyzer::ConstructAddrVal(), use ToAddrVal() * Add deprecation for ARP_Analyzer::EthAddrToStr(), use ToEthAddrStr() * Change the Func::Call() replacement to be named Func::Invoke() --- NEWS | 6 ++-- src/Discard.cc | 8 ++--- src/EventHandler.cc | 2 +- src/Expr.cc | 2 +- src/Func.cc | 6 ++-- src/Func.h | 16 +++++----- src/Hash.h | 4 +-- src/ID.h | 4 +-- src/RuleCondition.cc | 2 +- src/Val.cc | 6 ++-- src/analyzer/protocol/arp/ARP.cc | 30 +++++++++++-------- src/analyzer/protocol/arp/ARP.h | 10 +++++-- src/analyzer/protocol/http/HTTP.cc | 30 +++++++++---------- src/analyzer/protocol/mime/MIME.cc | 39 +++++++++++++++++-------- src/analyzer/protocol/mime/MIME.h | 29 +++++++++++++----- src/broker/Manager.cc | 4 +-- src/broker/messaging.bif | 4 +-- src/file_analysis/analyzer/x509/X509.cc | 4 +-- src/input/Manager.cc | 8 ++--- src/logging/Manager.cc | 12 ++++---- src/option.bif | 2 +- src/zeek.bif | 4 +-- 22 files changed, 137 insertions(+), 95 deletions(-) diff --git a/NEWS b/NEWS index b0b0d49126..047d24b202 100644 --- a/NEWS +++ b/NEWS @@ -114,9 +114,9 @@ Deprecated Functionality method to now use is called ``HookFunctionCall`` and uses ``IntrusivePtr`` arguments and return value. -- The ``Func::Call(val_list*, ...)`` method is now deprecated. Use operator() +- The ``Func::Call(val_list*, ...)`` method is now deprecated. Use ``Invoke()`` instead which takes a ``zeek::Args`` (``std::vector>``). - There's also a variadic template for operator() that forwards all arguments + There's also a variadic template for ``Invoke()`` that forwards all arguments into a ``zeek::Args`` for you. - The ``EventMgr::QueueEvent()`` and EventMgr::QueueEventFast()`` methods @@ -151,7 +151,7 @@ Deprecated Functionality - Various methods of converting protocol structures, like IP or packet headers, to associated ``Val`` type are now deprecated, the deprecation warning - message will advice what new method to use instead. + message will advise what new method to use instead. - Various methods of ``Tag`` classes are deprecated with the warning message advising what new method to use instead. diff --git a/src/Discard.cc b/src/Discard.cc index c5563f1cd8..6625786e3b 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -43,7 +43,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_ip->operator()(&args)->AsBool(); + discard_packet = check_ip->Invoke(&args)->AsBool(); } catch ( InterpreterException& e ) @@ -98,7 +98,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_tcp->operator()(&args)->AsBool(); + discard_packet = check_tcp->Invoke(&args)->AsBool(); } catch ( InterpreterException& e ) @@ -122,7 +122,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_udp->operator()(&args)->AsBool(); + discard_packet = check_udp->Invoke(&args)->AsBool(); } catch ( InterpreterException& e ) @@ -142,7 +142,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) try { - discard_packet = check_icmp->operator()(&args)->AsBool(); + discard_packet = check_icmp->Invoke(&args)->AsBool(); } catch ( InterpreterException& e ) diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 5e75fa6731..68673801d1 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -98,7 +98,7 @@ void EventHandler::Call(zeek::Args* vl, bool no_remote) if ( local ) // No try/catch here; we pass exceptions upstream. - local->operator()(vl); + local->Invoke(vl); } void EventHandler::NewEvent(zeek::Args* vl) diff --git a/src/Expr.cc b/src/Expr.cc index 3943786560..667b563373 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -4131,7 +4131,7 @@ IntrusivePtr CallExpr::Eval(Frame* f) const f->SetCall(this); auto& args = *v; - ret = funcv->operator()(&args, f); + ret = funcv->Invoke(&args, f); if ( f ) f->SetCall(current_call); diff --git a/src/Func.cc b/src/Func.cc index e8a29612bb..f0cb8e693a 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -301,10 +301,10 @@ bool BroFunc::IsPure() const Val* Func::Call(val_list* args, Frame* parent) const { auto zargs = zeek::val_list_to_args(*args); - return operator()(&zargs, parent).release(); + return Invoke(&zargs, parent).release(); }; -IntrusivePtr BroFunc::operator()(zeek::Args* args, Frame* parent) const +IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -614,7 +614,7 @@ bool BuiltinFunc::IsPure() const return is_pure; } -IntrusivePtr BuiltinFunc::operator()(zeek::Args* args, Frame* parent) const +IntrusivePtr BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); diff --git a/src/Func.h b/src/Func.h index f861171980..5b2ee5eebc 100644 --- a/src/Func.h +++ b/src/Func.h @@ -51,7 +51,7 @@ public: const std::vector& GetBodies() const { return bodies; } bool HasBodies() const { return bodies.size(); } - [[deprecated("Remove in v4.1. Use operator() instead.")]] + [[deprecated("Remove in v4.1. Use Invoke() instead.")]] Val* Call(val_list* args, Frame* parent = nullptr) const; /** @@ -60,21 +60,21 @@ public: * @param parent the frame from which the function is being called. * @return the return value of the function call. */ - virtual IntrusivePtr operator()(zeek::Args* args, - Frame* parent = nullptr) const = 0; + virtual IntrusivePtr Invoke(zeek::Args* args, + Frame* parent = nullptr) const = 0; /** - * A version of operator() taking a variable number of individual arguments. + * A version of Invoke() taking a variable number of individual arguments. */ template std::enable_if_t< std::is_convertible_v>, IntrusivePtr>, IntrusivePtr> - operator()(Args&&... args) const + Invoke(Args&&... args) const { auto zargs = zeek::Args{std::forward(args)...}; - return operator()(&zargs); + return Invoke(&zargs); } // Add a new event handler to an existing function (event). @@ -136,7 +136,7 @@ public: ~BroFunc() override; bool IsPure() const override; - IntrusivePtr operator()(zeek::Args* args, Frame* parent) const override; + IntrusivePtr Invoke(zeek::Args* args, Frame* parent) const override; /** * Adds adds a closure to the function. Closures are cloned and @@ -234,7 +234,7 @@ public: ~BuiltinFunc() override; bool IsPure() const override; - IntrusivePtr operator()(zeek::Args* args, Frame* parent) const override; + IntrusivePtr Invoke(zeek::Args* args, Frame* parent) const override; built_in_func TheFunc() const { return func; } void Describe(ODesc* d) const override; diff --git a/src/Hash.h b/src/Hash.h index bff33c2b9f..9e39909d58 100644 --- a/src/Hash.h +++ b/src/Hash.h @@ -30,9 +30,9 @@ class BroString; class Val; class Frame; class BifReturnVal; -namespace zeek { namespace BifFunc { +namespace zeek::BifFunc { extern BifReturnVal md5_hmac_bif(Frame* frame, const zeek::Args*); -}} +} typedef uint64_t hash_t; typedef uint64_t hash64_t; diff --git a/src/ID.h b/src/ID.h index 4c7839bed9..5c0c5e84b7 100644 --- a/src/ID.h +++ b/src/ID.h @@ -164,7 +164,7 @@ protected: }; -namespace zeek { namespace id { +namespace zeek::id { /** * Lookup an ID in the global module and return it, if one exists; @@ -254,4 +254,4 @@ void init(); } // namespace zeek::id::detail -}} // namespace zeek::id +} // namespace zeek::id diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index c66d3a3b3f..732c74b4ac 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -181,7 +181,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, try { - auto val = id->GetVal()->AsFunc()->operator()(&args); + auto val = id->GetVal()->AsFunc()->Invoke(&args); result = val && val->AsBool(); } diff --git a/src/Val.cc b/src/Val.cc index 0d45446315..a2c062d3b2 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1879,7 +1879,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) try { - result = f->operator()(&vl); + result = f->Invoke(&vl); } catch ( InterpreterException& e ) @@ -2088,7 +2088,7 @@ void TableVal::CallChangeFunc(const Val* index, vl.emplace_back(old_value); in_change_func = true; - f->operator()(&vl); + f->Invoke(&vl); } catch ( InterpreterException& e ) { @@ -2546,7 +2546,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) vl.emplace_back(std::move(idx)); } - auto result = f->operator()(&vl); + auto result = f->Invoke(&vl); if ( result ) secs = result->AsInterval(); diff --git a/src/analyzer/protocol/arp/ARP.cc b/src/analyzer/protocol/arp/ARP.cc index ec5906bdde..4d8b83b8b8 100644 --- a/src/analyzer/protocol/arp/ARP.cc +++ b/src/analyzer/protocol/arp/ARP.cc @@ -192,10 +192,10 @@ void ARP_Analyzer::BadARP(const struct arp_pkthdr* hdr, const char* msg) return; mgr.Enqueue(bad_arp, - ConstructAddrVal(ar_spa(hdr)), - EthAddrToStr((const u_char*) ar_sha(hdr)), - ConstructAddrVal(ar_tpa(hdr)), - EthAddrToStr((const u_char*) ar_tha(hdr)), + ToAddrVal(ar_spa(hdr)), + ToEthAddrStr((const u_char*) ar_sha(hdr)), + ToAddrVal(ar_tpa(hdr)), + ToEthAddrStr((const u_char*) ar_tha(hdr)), make_intrusive(msg) ); } @@ -214,22 +214,28 @@ void ARP_Analyzer::RREvent(EventHandlerPtr e, return; mgr.Enqueue(e, - EthAddrToStr(src), - EthAddrToStr(dst), - ConstructAddrVal(spa), - EthAddrToStr((const u_char*) sha), - ConstructAddrVal(tpa), - EthAddrToStr((const u_char*) tha) + ToEthAddrStr(src), + ToEthAddrStr(dst), + ToAddrVal(spa), + ToEthAddrStr((const u_char*) sha), + ToAddrVal(tpa), + ToEthAddrStr((const u_char*) tha) ); } -IntrusivePtr ARP_Analyzer::ConstructAddrVal(const void* addr) +AddrVal* ARP_Analyzer::ConstructAddrVal(const void* addr) + { return ToAddrVal(addr).release(); } + +IntrusivePtr ARP_Analyzer::ToAddrVal(const void* addr) { // ### For now, we only handle IPv4 addresses. return make_intrusive(*(const uint32_t*) addr); } -IntrusivePtr ARP_Analyzer::EthAddrToStr(const u_char* addr) +StringVal* ARP_Analyzer::EthAddrToStr(const u_char* addr) + { return ToEthAddrStr(addr).release(); } + +IntrusivePtr ARP_Analyzer::ToEthAddrStr(const u_char* addr) { char buf[1024]; snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x", diff --git a/src/analyzer/protocol/arp/ARP.h b/src/analyzer/protocol/arp/ARP.h index 62e1fbd8bb..d1de7de01f 100644 --- a/src/analyzer/protocol/arp/ARP.h +++ b/src/analyzer/protocol/arp/ARP.h @@ -45,8 +45,14 @@ public: const char* tpa, const char* tha); protected: - IntrusivePtr ConstructAddrVal(const void* addr); - IntrusivePtr EthAddrToStr(const u_char* addr); + + [[deprecated("Remove in v4.1. Use ToAddrVal().")]] + AddrVal* ConstructAddrVal(const void* addr); + [[deprecated("Remove in v4.1. Use ToEthAddrStr().")]] + StringVal* EthAddrToStr(const u_char* addr); + + IntrusivePtr ToAddrVal(const void* addr); + IntrusivePtr ToEthAddrStr(const u_char* addr); void BadARP(const struct arp_pkthdr* hdr, const char* string); void Corrupted(const char* string); }; diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index e2cc88b465..c8f2689dca 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -738,15 +738,15 @@ void HTTP_Message::SubmitAllHeaders(mime::MIME_HeaderList& hlist) analyzer->EnqueueConnEvent(http_all_headers, analyzer->ConnVal(), val_mgr->Bool(is_orig), - BuildHeaderTable(hlist) + ToHeaderTable(hlist) ); if ( http_content_type ) analyzer->EnqueueConnEvent(http_content_type, analyzer->ConnVal(), val_mgr->Bool(is_orig), - current_entity->ContentType(), - current_entity->ContentSubType() + current_entity->GetContentType(), + current_entity->GetContentSubType() ); } @@ -928,7 +928,7 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig) return; } - // HTTP_Event("HTTP line", new_string_val(length, line)); + // HTTP_Event("HTTP line", to_string_val(length, line)); if ( is_orig ) { @@ -961,7 +961,7 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig) { if ( ! RequestExpected() ) HTTP_Event("crud_trailing_HTTP_request", - mime::new_string_val(line, end_of_line)); + mime::to_string_val(line, end_of_line)); else { // We do see HTTP requests with a @@ -1304,10 +1304,10 @@ bool HTTP_Analyzer::ParseRequest(const char* line, const char* end_of_line) version_end = version_start + 3; if ( skip_whitespace(version_end, end_of_line) != end_of_line ) HTTP_Event("crud after HTTP version is ignored", - mime::new_string_val(line, end_of_line)); + mime::to_string_val(line, end_of_line)); } else - HTTP_Event("bad_HTTP_version", mime::new_string_val(line, end_of_line)); + HTTP_Event("bad_HTTP_version", mime::to_string_val(line, end_of_line)); } // NormalizeURI(line, end_of_uri); @@ -1333,7 +1333,7 @@ HTTP_Analyzer::HTTP_VersionNumber HTTP_Analyzer::HTTP_Version(int len, const cha } else { - HTTP_Event("bad_HTTP_version", mime::new_string_val(len, data)); + HTTP_Event("bad_HTTP_version", mime::to_string_val(len, data)); return {}; } } @@ -1509,7 +1509,7 @@ int HTTP_Analyzer::HTTP_ReplyLine(const char* line, const char* end_of_line) // ##TODO: some server replies with an HTML document // without a status line and a MIME header, when the // request is malformed. - HTTP_Event("bad_HTTP_reply", mime::new_string_val(line, end_of_line)); + HTTP_Event("bad_HTTP_reply", mime::to_string_val(line, end_of_line)); return 0; } @@ -1522,7 +1522,7 @@ int HTTP_Analyzer::HTTP_ReplyLine(const char* line, const char* end_of_line) if ( rest >= end_of_line ) { HTTP_Event("HTTP_reply_code_missing", - mime::new_string_val(line, end_of_line)); + mime::to_string_val(line, end_of_line)); return 0; } @@ -1531,7 +1531,7 @@ int HTTP_Analyzer::HTTP_ReplyLine(const char* line, const char* end_of_line) if ( rest + 3 > end_of_line ) { HTTP_Event("HTTP_reply_code_missing", - mime::new_string_val(line, end_of_line)); + mime::to_string_val(line, end_of_line)); return 0; } @@ -1544,7 +1544,7 @@ int HTTP_Analyzer::HTTP_ReplyLine(const char* line, const char* end_of_line) if ( rest >= end_of_line ) { HTTP_Event("HTTP_reply_reason_phrase_missing", - mime::new_string_val(line, end_of_line)); + mime::to_string_val(line, end_of_line)); // Tolerate missing reason phrase? return 1; } @@ -1635,15 +1635,15 @@ void HTTP_Analyzer::HTTP_Header(bool is_orig, mime::MIME_Header* h) if ( DEBUG_http ) DEBUG_MSG("%.6f http_header\n", network_time); - auto upper_hn = mime::new_string_val(h->get_name()); + auto upper_hn = mime::to_string_val(h->get_name()); upper_hn->ToUpper(); EnqueueConnEvent(http_header, ConnVal(), val_mgr->Bool(is_orig), - mime::new_string_val(h->get_name()), + mime::to_string_val(h->get_name()), std::move(upper_hn), - mime::new_string_val(h->get_value()) + mime::to_string_val(h->get_value()) ); } } diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index 81222adf97..dbe81f41a9 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -108,19 +108,28 @@ bool is_lws(char ch) return ch == 9 || ch == 32; } -IntrusivePtr new_string_val(int length, const char* data) +StringVal* new_string_val(int length, const char* data) + { return to_string_val(length, data).release(); } + +StringVal* new_string_val(const char* data, const char* end_of_data) + { return to_string_val(data, end_of_data).release(); } + +StringVal* new_string_val(const data_chunk_t buf) + { return to_string_val(buf).release(); } + +IntrusivePtr to_string_val(int length, const char* data) { return make_intrusive(length, data); } -IntrusivePtr new_string_val(const char* data, const char* end_of_data) +IntrusivePtr to_string_val(const char* data, const char* end_of_data) { return make_intrusive(end_of_data - data, data); } -IntrusivePtr new_string_val(const data_chunk_t buf) +IntrusivePtr to_string_val(const data_chunk_t buf) { - return new_string_val(buf.length, buf.data); + return to_string_val(buf.length, buf.data); } static data_chunk_t get_data_chunk(BroString* s) @@ -1287,19 +1296,25 @@ void MIME_Entity::DebugPrintHeaders() #endif } -IntrusivePtr MIME_Message::BuildHeaderVal(MIME_Header* h) +RecordVal* MIME_Message::BuildHeaderVal(MIME_Header* h) + { return ToHeaderVal(h).release(); } + +IntrusivePtr MIME_Message::ToHeaderVal(MIME_Header* h) { static auto mime_header_rec = zeek::id::find_type("mime_header_rec"); auto header_record = make_intrusive(mime_header_rec); - header_record->Assign(0, new_string_val(h->get_name())); - auto upper_hn = new_string_val(h->get_name()); + header_record->Assign(0, to_string_val(h->get_name())); + auto upper_hn = to_string_val(h->get_name()); upper_hn->ToUpper(); header_record->Assign(1, std::move(upper_hn)); - header_record->Assign(2, new_string_val(h->get_value())); + header_record->Assign(2, to_string_val(h->get_value())); return header_record; } -IntrusivePtr MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) +TableVal* MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) + { return ToHeaderTable(hlist).release(); } + +IntrusivePtr MIME_Message::ToHeaderTable(MIME_HeaderList& hlist) { static auto mime_header_list = zeek::id::find_type("mime_header_list"); auto t = make_intrusive(mime_header_list); @@ -1308,7 +1323,7 @@ IntrusivePtr MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) { auto index = val_mgr->Count(i + 1); // index starting from 1 MIME_Header* h = hlist[i]; - t->Assign(std::move(index), BuildHeaderVal(h)); + t->Assign(std::move(index), ToHeaderVal(h)); } return t; @@ -1427,7 +1442,7 @@ void MIME_Mail::SubmitHeader(MIME_Header* h) if ( mime_one_header ) analyzer->EnqueueConnEvent(mime_one_header, analyzer->ConnVal(), - BuildHeaderVal(h) + ToHeaderVal(h) ); } @@ -1436,7 +1451,7 @@ void MIME_Mail::SubmitAllHeaders(MIME_HeaderList& hlist) if ( mime_all_headers ) analyzer->EnqueueConnEvent(mime_all_headers, analyzer->ConnVal(), - BuildHeaderTable(hlist) + ToHeaderTable(hlist) ); } diff --git a/src/analyzer/protocol/mime/MIME.h b/src/analyzer/protocol/mime/MIME.h index f897b094a7..50fdb8366b 100644 --- a/src/analyzer/protocol/mime/MIME.h +++ b/src/analyzer/protocol/mime/MIME.h @@ -97,8 +97,12 @@ public: MIME_Entity* Parent() const { return parent; } int MIMEContentType() const { return content_type; } - const IntrusivePtr& ContentType() const { return content_type_str; } - const IntrusivePtr& ContentSubType() const { return content_subtype_str; } + [[deprecated("Remove in v4.1. Use GetContentType().")]] + StringVal* ContentType() const { return content_type_str.get(); } + [[deprecated("Remove in v4.1. Use GetContentSubType().")]] + StringVal* ContentSubType() const { return content_subtype_str.get(); } + const IntrusivePtr& GetContentType() const { return content_type_str; } + const IntrusivePtr& GetContentSubType() const { return content_subtype_str; } int ContentTransferEncoding() const { return content_encoding; } protected: @@ -225,8 +229,13 @@ protected: MIME_Entity* top_level; bool finished; - IntrusivePtr BuildHeaderVal(MIME_Header* h); - IntrusivePtr BuildHeaderTable(MIME_HeaderList& hlist); + [[deprecated("Remove in v4.1. Use ToHeaderVal().")]] + RecordVal* BuildHeaderVal(MIME_Header* h); + [[deprecated("Remove in v4.1. Use ToHeaderTable().")]] + TableVal* BuildHeaderTable(MIME_HeaderList& hlist); + + IntrusivePtr ToHeaderVal(MIME_Header* h); + IntrusivePtr ToHeaderTable(MIME_HeaderList& hlist); }; class MIME_Mail final : public MIME_Message { @@ -265,9 +274,15 @@ protected: extern bool is_null_data_chunk(data_chunk_t b); -extern IntrusivePtr new_string_val(int length, const char* data); -extern IntrusivePtr new_string_val(const char* data, const char* end_of_data); -extern IntrusivePtr new_string_val(const data_chunk_t buf); +[[deprecated("Remove in v4.1. Use analyzer::mime::to_string_val().")]] +extern StringVal* new_string_val(int length, const char* data); +[[deprecated("Remove in v4.1. Use analyzer::mime::to_string_val().")]] +extern StringVal* new_string_val(const char* data, const char* end_of_data); +[[deprecated("Remove in v4.1. Use analyzer::mime::to_string_val().")]] +extern StringVal* new_string_val(const data_chunk_t buf); +extern IntrusivePtr to_string_val(int length, const char* data); +extern IntrusivePtr to_string_val(const char* data, const char* end_of_data); +extern IntrusivePtr to_string_val(const data_chunk_t buf); extern int fputs(data_chunk_t b, FILE* fp); extern bool istrequal(data_chunk_t s, const char* t); extern bool is_lws(char ch); diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 98f9651d41..469cc997f0 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -552,8 +552,8 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int std::string serial_data(data, len); free(data); - auto v = log_topic_func->operator()(IntrusivePtr{NewRef{}, stream}, - make_intrusive(path)); + auto v = log_topic_func->Invoke(IntrusivePtr{NewRef{}, stream}, + make_intrusive(path)); if ( ! v ) { diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index 14d6c43219..b88320bcd2 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -188,7 +188,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool topic_func = global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; - auto topic = topic_func->operator()(&vl); + auto topic = topic_func->Invoke(&vl); if ( ! topic->AsString()->Len() ) return val_mgr->False(); @@ -225,7 +225,7 @@ function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool topic_func = global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc(); zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}}; - auto topic = topic_func->operator()(&vl); + auto topic = topic_func->Invoke(&vl); if ( ! topic->AsString()->Len() ) return val_mgr->False(); diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 8ad24921ef..016a265d8f 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -62,8 +62,8 @@ bool file_analysis::X509::EndOfFile() return false; // yup, let's call the callback. - cache_hit_callback->operator()(GetFile()->ToVal(), entry, - make_intrusive(cert_sha256)); + cache_hit_callback->Invoke(GetFile()->ToVal(), entry, + make_intrusive(cert_sha256)); return false; } } diff --git a/src/input/Manager.cc b/src/input/Manager.cc index f98c60684c..4914fc6fe4 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -480,11 +480,11 @@ bool Manager::CreateTableStream(RecordVal* fval) auto dst = fval->GetFieldOrDefault("destination"); // check if index fields match table description - int num = idx->NumFields(); + size_t num = idx->NumFields(); const auto& tl = dst->GetType()->AsTableType()->IndexTypes(); - int j; + size_t j; - for ( j = 0; j < static_cast(tl.size()); ++j ) + for ( j = 0; j < tl.size(); ++j ) { if ( j >= num ) { @@ -1768,7 +1768,7 @@ bool Manager::CallPred(Func* pred_func, const int numvals, ...) const va_end(lP); - auto v = pred_func->operator()(&vl); + auto v = pred_func->Invoke(&vl); if ( v ) result = v->AsBool(); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 7fc6cab918..8ab3ba9f51 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -717,7 +717,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) // See whether the predicates indicates that we want // to log this record. int result = 1; - auto v = filter->pred->operator()(columns); + auto v = filter->pred->Invoke(columns); if ( v ) result = v->AsBool(); @@ -744,9 +744,9 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) // Can be TYPE_ANY here. rec_arg = columns; - auto v = filter->path_func->operator()(IntrusivePtr{NewRef{}, id}, - std::move(path_arg), - std::move(rec_arg)); + auto v = filter->path_func->Invoke(IntrusivePtr{NewRef{}, id}, + std::move(path_arg), + std::move(rec_arg)); if ( ! v ) return false; @@ -1050,7 +1050,7 @@ threading::Value** Manager::RecordToFilterVals(Stream* stream, Filter* filter, if ( filter->num_ext_fields > 0 ) { - auto res = filter->ext_func->operator()(IntrusivePtr{NewRef{}, filter->path_val}); + auto res = filter->ext_func->Invoke(IntrusivePtr{NewRef{}, filter->path_val}); if ( res ) ext_rec = {AdoptRef{}, res.release()->AsRecordVal()}; @@ -1527,7 +1527,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con // Call the postprocessor function. int result = 0; - auto v = func->operator()(std::move(info)); + auto v = func->Invoke(std::move(info)); if ( v ) result = v->AsBool(); diff --git a/src/option.bif b/src/option.bif index 91d5509c3c..f2024062c4 100644 --- a/src/option.bif +++ b/src/option.bif @@ -24,7 +24,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, const IntrusiveP if ( add_loc ) vl.emplace_back(NewRef{}, location); - val = handler_function->operator()(&vl); // consumed by next call. + val = handler_function->Invoke(&vl); // consumed by next call. if ( ! val ) { diff --git a/src/zeek.bif b/src/zeek.bif index 8079ed8af9..fceaa3ac5f 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1338,7 +1338,7 @@ bool sort_function(const IntrusivePtr& a, const IntrusivePtr& b) if ( ! b ) return 1; - auto result = sort_function_comp->operator()(a, b); + auto result = sort_function_comp->Invoke(a, b); int int_result = result->CoerceToInt(); return int_result < 0; @@ -1516,7 +1516,7 @@ function order%(v: any, ...%) : index_vec if ( comp ) { - const auto& comp_type = comp->GetType()->AsFuncType(); + const auto& comp_type = comp->GetType(); if ( comp_type->Yield()->Tag() != TYPE_INT || ! comp_type->ParamList()->AllMatch(elt_type, 0) ) {