/src/zeek/src/packet_analysis/protocol/ip/SessionAdapter.cc
Line | Count | Source |
1 | | // See the file "COPYING" in the main distribution directory for copyright. |
2 | | |
3 | | #include "zeek/packet_analysis/protocol/ip/SessionAdapter.h" |
4 | | |
5 | | #include "zeek/File.h" |
6 | | #include "zeek/ZeekString.h" |
7 | | #include "zeek/packet_analysis/protocol/ip/IPBasedAnalyzer.h" |
8 | | |
9 | | using namespace zeek::packet_analysis::IP; |
10 | | |
11 | 372k | void SessionAdapter::Done() { |
12 | 372k | Analyzer::Done(); |
13 | 372k | for ( const auto& ta : tap_analyzers ) |
14 | 0 | ta->Done(); |
15 | 372k | } |
16 | | |
17 | 46.0k | bool SessionAdapter::IsReuse(double t, const u_char* pkt) { return parent->IsReuse(t, pkt); } |
18 | | |
19 | 0 | void SessionAdapter::SetContentsFile(unsigned int /* direction */, FilePtr /* f */) { |
20 | 0 | reporter->Error("analyzer type does not support writing to a contents file"); |
21 | 0 | } |
22 | | |
23 | 0 | zeek::FilePtr SessionAdapter::GetContentsFile(unsigned int /* direction */) const { |
24 | 0 | reporter->Error("analyzer type does not support writing to a contents file"); |
25 | 0 | return nullptr; |
26 | 0 | } |
27 | | |
28 | 189k | void SessionAdapter::PacketContents(const u_char* data, int len) { |
29 | 189k | if ( packet_contents && len > 0 ) { |
30 | 180k | zeek::String* cbs = new zeek::String(data, len, true); |
31 | 180k | auto contents = make_intrusive<StringVal>(cbs); |
32 | 180k | EnqueueConnEvent(packet_contents, ConnVal(), std::move(contents)); |
33 | 180k | } |
34 | 189k | } |
35 | | |
36 | 0 | void SessionAdapter::AddTapAnalyzer(TapAnalyzerPtr ta) { |
37 | 0 | assert(! IsFinished()); |
38 | 0 | tap_analyzers.push_back(std::move(ta)); |
39 | 0 | tap_analyzers.back()->Init(); |
40 | 0 | } |
41 | | |
42 | 0 | bool SessionAdapter::RemoveTapAnalyzer(const TapAnalyzer* ta) { |
43 | | // Find the raw pointer, call Done(), remove it, thereby destructing it. |
44 | 0 | for ( auto it = tap_analyzers.begin(); it != tap_analyzers.end(); ++it ) { |
45 | 0 | if ( it->get() == ta ) { |
46 | | // Ensure Done() is called only after removal from tap_analyzers. |
47 | 0 | auto ptr{std::move(*it)}; |
48 | 0 | tap_analyzers.erase(it); |
49 | 0 | ptr->Done(); |
50 | 0 | ptr.reset(); |
51 | 0 | return true; |
52 | 0 | } |
53 | 0 | } |
54 | | |
55 | 0 | return false; |
56 | 0 | } |
57 | | |
58 | 191k | void SessionAdapter::TapPacket(const Packet* pkt, PacketAction action, SkipReason skip_reason) const { |
59 | 191k | for ( const auto& ta : tap_analyzers ) |
60 | 0 | ta->TapPacket(*pkt, action, skip_reason); |
61 | 191k | } |
62 | | |
63 | 483M | void SessionAdapter::UpdateConnVal(RecordVal* conn_val) { |
64 | 483M | Analyzer::UpdateConnVal(conn_val); |
65 | | |
66 | 483M | for ( const auto& ta : tap_analyzers ) |
67 | 0 | ta->UpdateConnVal(conn_val); |
68 | 483M | } |