Deprecate RecordVal(RecordType*) ctor

Replaced with one that takes IntrusivePtr
This commit is contained in:
Jon Siwek 2020-05-14 19:31:43 -07:00
parent 4debad8caf
commit 440b0623ac
22 changed files with 135 additions and 181 deletions

129
src/IP.cc
View file

@ -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<VectorVal> BuildOptionsVal(const u_char* data, int len)
{
auto vv = make_intrusive<VectorVal>(zeek::id::find_type<VectorType>("ip6_options"));
while ( len > 0 )
{
static auto ip6_option_type = zeek::id::find_type<RecordType>("ip6_option");
const struct ip6_opt* opt = (const struct ip6_opt*) data;
auto rv = make_intrusive<RecordVal>(hdrType(ip6_option_type, "ip6_option"));
auto rv = make_intrusive<RecordVal>(ip6_option_type);
rv->Assign(0, val_mgr->Count(opt->ip6o_type));
if ( opt->ip6o_type == 0 )
@ -84,7 +56,8 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
switch ( type ) {
case IPPROTO_IPV6:
{
rv = make_intrusive<RecordVal>(hdrType(ip6_hdr_type, "ip6_hdr"));
static auto ip6_hdr_type = zeek::id::find_type<RecordType>("ip6_hdr");
rv = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_HOPOPTS:
{
rv = make_intrusive<RecordVal>(hdrType(ip6_hopopts_type, "ip6_hopopts"));
static auto ip6_hopopts_type = zeek::id::find_type<RecordType>("ip6_hopopts");
rv = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_DSTOPTS:
{
rv = make_intrusive<RecordVal>(hdrType(ip6_dstopts_type, "ip6_dstopts"));
static auto ip6_dstopts_type = zeek::id::find_type<RecordType>("ip6_dstopts");
rv = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_ROUTING:
{
rv = make_intrusive<RecordVal>(hdrType(ip6_routing_type, "ip6_routing"));
static auto ip6_routing_type = zeek::id::find_type<RecordType>("ip6_routing");
rv = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_FRAGMENT:
{
rv = make_intrusive<RecordVal>(hdrType(ip6_fragment_type, "ip6_fragment"));
static auto ip6_fragment_type = zeek::id::find_type<RecordType>("ip6_fragment");
rv = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_AH:
{
rv = make_intrusive<RecordVal>(hdrType(ip6_ah_type, "ip6_ah"));
static auto ip6_ah_type = zeek::id::find_type<RecordType>("ip6_ah");
rv = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_ESP:
{
rv = make_intrusive<RecordVal>(hdrType(ip6_esp_type, "ip6_esp"));
static auto ip6_esp_type = zeek::id::find_type<RecordType>("ip6_esp");
rv = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
#ifdef ENABLE_MOBILE_IPV6
case IPPROTO_MOBILITY:
{
rv = make_intrusive<RecordVal>(hdrType(ip6_mob_type, "ip6_mobility_hdr"));
static auto ip6_mob_type = zeek::id::find_type<RecordType>("ip6_mobility_hdr");
rv = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> 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<RecordVal>(hdrType(ip6_mob_msg_type, "ip6_mobility_msg"));
static auto ip6_mob_msg_type = zeek::id::find_type<RecordType>("ip6_mobility_msg");
auto msg = make_intrusive<RecordVal>(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<RecordType>("ip6_mobility_brr");
static auto ip6_mob_hoti_type = zeek::id::find_type<RecordType>("ip6_mobility_hoti");
static auto ip6_mob_coti_type = zeek::id::find_type<RecordType>("ip6_mobility_coti");
static auto ip6_mob_hot_type = zeek::id::find_type<RecordType>("ip6_mobility_hot");
static auto ip6_mob_cot_type = zeek::id::find_type<RecordType>("ip6_mobility_cot");
static auto ip6_mob_bu_type = zeek::id::find_type<RecordType>("ip6_mobility_bu");
static auto ip6_mob_back_type = zeek::id::find_type<RecordType>("ip6_mobility_back");
static auto ip6_mob_be_type = zeek::id::find_type<RecordType>("ip6_mobility_be");
switch ( mob->ip6mob_type ) {
case 0:
{
auto m = make_intrusive<RecordVal>(hdrType(ip6_mob_brr_type, "ip6_mobility_brr"));
auto m = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 1:
{
auto m = make_intrusive<RecordVal>(hdrType(ip6_mob_brr_type, "ip6_mobility_hoti"));
auto m = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 2:
{
auto m = make_intrusive<RecordVal>(hdrType(ip6_mob_brr_type, "ip6_mobility_coti"));
auto m = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 3:
{
auto m = make_intrusive<RecordVal>(hdrType(ip6_mob_brr_type, "ip6_mobility_hot"));
auto m = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 4:
{
auto m = make_intrusive<RecordVal>(hdrType(ip6_mob_brr_type, "ip6_mobility_cot"));
auto m = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 5:
{
auto m = make_intrusive<RecordVal>(hdrType(ip6_mob_brr_type, "ip6_mobility_bu"));
auto m = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 6:
{
auto m = make_intrusive<RecordVal>(hdrType(ip6_mob_brr_type, "ip6_mobility_back"));
auto m = make_intrusive<RecordVal>(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<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 7:
{
auto m = make_intrusive<RecordVal>(hdrType(ip6_mob_brr_type, "ip6_mobility_be"));
auto m = make_intrusive<RecordVal>(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<AddrVal>(IPAddr(*hoa)));
@ -339,7 +329,8 @@ IntrusivePtr<RecordVal> IP_Hdr::ToIPHdrVal() const
if ( ip4 )
{
rval = make_intrusive<RecordVal>(hdrType(ip4_hdr_type, "ip4_hdr"));
static auto ip4_hdr_type = zeek::id::find_type<RecordType>("ip4_hdr");
rval = make_intrusive<RecordVal>(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<RecordVal> 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<RecordType>("pkt_hdr");
return ToPktHdrVal(make_intrusive<RecordVal>(pkt_hdr_type), 0);
}
@ -379,16 +366,9 @@ RecordVal* IP_Hdr::BuildPktHdrVal() const
IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(IntrusivePtr<RecordVal> 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<RecordType>("tcp_hdr");
static auto udp_hdr_type = zeek::id::find_type<RecordType>("udp_hdr");
static auto icmp_hdr_type = zeek::id::find_type<RecordType>("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<VectorVal> 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<VectorVal>(
zeek::id::find_type<VectorType>("ip6_ext_hdr_chain"));
static auto ip6_ext_hdr_type = zeek::id::find_type<RecordType>("ip6_ext_hdr");
static auto ip6_hopopts_type = zeek::id::find_type<RecordType>("ip6_hopopts");
static auto ip6_dstopts_type = zeek::id::find_type<RecordType>("ip6_dstopts");
static auto ip6_routing_type = zeek::id::find_type<RecordType>("ip6_routing");
static auto ip6_fragment_type = zeek::id::find_type<RecordType>("ip6_fragment");
static auto ip6_ah_type = zeek::id::find_type<RecordType>("ip6_ah");
static auto ip6_esp_type = zeek::id::find_type<RecordType>("ip6_esp");
static auto ip6_ext_hdr_chain_type = zeek::id::find_type<VectorType>("ip6_ext_hdr_chain");
auto rval = make_intrusive<VectorVal>(ip6_ext_hdr_chain_type);
for ( size_t i = 1; i < chain.size(); ++i )
{