Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Avoid deprecation warnings with Zeek >= 4.2.
Browse files Browse the repository at this point in the history
Also includes a bug fix triggering an internal error when no
`{protocol,analyzer}_confirmation` event handler is defined.

Also add Zeek 4.2 to CI.
  • Loading branch information
rsmmr committed Apr 19, 2022
1 parent c9ca2d9 commit f8fde8d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ zkg_ubuntu_task:
- docker_arguments:
- ZEEK_LTS: 1
- ZEEK_VERSION: 4.0.3-0
- docker_arguments:
- ZEEK_LTS:
- ZEEK_VERSION: 4.2.0-0
cpu: 2
memory: 8G

Expand Down
9 changes: 4 additions & 5 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ RUN apt-get update \
https://download.zeek.org/binary-packages/xUbuntu_20.04/amd64/zeek${ZEEK_LTS}-core-dev_${ZEEK_VERSION}_amd64.deb \
https://download.zeek.org/binary-packages/xUbuntu_20.04/amd64/libbroker${ZEEK_LTS}-dev_${ZEEK_VERSION}_amd64.deb \
https://download.zeek.org/binary-packages/xUbuntu_20.04/amd64/zeek${ZEEK_LTS}-libcaf-dev_${ZEEK_VERSION}_amd64.deb \
&& if echo ${ZEEK_VERSION} | grep -q '^4\.'; then \
https://download.zeek.org/binary-packages/xUbuntu_20.04/amd64/zeek${ZEEK_LTS}-btest_${ZEEK_VERSION}_amd64.deb \
https://download.zeek.org/binary-packages/xUbuntu_20.04/amd64/zeek${ZEEK_LTS}-zkg_${ZEEK_VERSION}_amd64.deb \
&& if echo ${ZEEK_VERSION} | grep -vq '^4\.0'; then \
curl -L --remote-name-all \
https://download.zeek.org/binary-packages/xUbuntu_20.04/amd64/zeek${ZEEK_LTS}-btest_${ZEEK_VERSION}_amd64.deb \
https://download.zeek.org/binary-packages/xUbuntu_20.04/amd64/zeek${ZEEK_LTS}-zkg_${ZEEK_VERSION}_amd64.deb; \
else \
pip3 install --no-cache-dir "btest>=0.66" zkg; \
https://download.zeek.org/binary-packages/xUbuntu_20.04/amd64/zeek${ZEEK_LTS}-btest-data_${ZEEK_VERSION}_amd64.deb; \
fi \
&& dpkg -i ./*.deb \
&& cd - \
Expand Down
20 changes: 20 additions & 0 deletions include/zeek-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ class PacketAnalysisTag : public ::zeek::Tag {

namespace spicy::zeek::compat {

#if ZEEK_VERSION_NUMBER >= 40200 // Zeek >= 4.2
inline auto Analyzer_AnalyzerConfirmation(::zeek::analyzer::Analyzer* analyzer, ::zeek::Tag tag) {
analyzer->AnalyzerConfirmation(tag);
}

inline auto Analyzer_AnalyzerViolation(::zeek::analyzer::Analyzer* analyzer, const char* reason,
const char* data = nullptr, int len = 0) {
analyzer->AnalyzerViolation(reason, data, len);
}
#else
inline auto Analyzer_AnalyzerConfirmation(::zeek::analyzer::Analyzer* analyzer, ::zeek::analyzer::Tag tag) {
analyzer->ProtocolConfirmation(tag);
}

inline auto Analyzer_AnalyzerViolation(::zeek::analyzer::Analyzer* analyzer, const char* reason,
const char* data = nullptr, int len = 0) {
analyzer->ProtocolViolation(reason, data, len);
}
#endif

#if ZEEK_VERSION_NUMBER >= 40100 // Zeek >= 4.1
inline auto Connection_ConnVal(::zeek::Connection* c) { return c->GetVal(); }
#else
Expand Down
9 changes: 6 additions & 3 deletions src/runtime-support.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,11 @@ std::string rt::uid() {
auto cookie = static_cast<Cookie*>(hilti::rt::context::cookie());
assert(cookie);

if ( auto c = std::get_if<cookie::ProtocolAnalyzer>(cookie) )
if ( auto c = std::get_if<cookie::ProtocolAnalyzer>(cookie) ) {
// Retrieve the ConnVal() so that we ensure the UID has been set.
c->analyzer->ConnVal();
return c->analyzer->Conn()->GetUID().Base62("C");
}
else
throw ValueUnavailable("uid() not available in current context");
}
Expand Down Expand Up @@ -248,7 +251,7 @@ void rt::confirm_protocol() {

if ( auto x = std::get_if<cookie::ProtocolAnalyzer>(cookie) ) {
auto tag = OurPlugin->tagForProtocolAnalyzer(x->analyzer->GetAnalyzerTag());
return x->analyzer->ProtocolConfirmation(tag);
return ::spicy::zeek::compat::Analyzer_AnalyzerConfirmation(x->analyzer, tag);
}
else
throw ValueUnavailable("no current connection available");
Expand All @@ -259,7 +262,7 @@ void rt::reject_protocol(const std::string& reason) {
assert(cookie);

if ( auto x = std::get_if<cookie::ProtocolAnalyzer>(cookie) )
return x->analyzer->ProtocolViolation(reason.c_str());
return ::spicy::zeek::compat::Analyzer_AnalyzerViolation(x->analyzer, reason.c_str());
else
throw ValueUnavailable("no current connection available");
}
Expand Down
4 changes: 4 additions & 0 deletions tests/zeek/replaces.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ event ssh::banner(c: connection, is_orig: bool, version: string, software: strin
print "SSH banner", c$id, is_orig, version, software;
}

@if ( Version::number >= 40200 )
event analyzer_confirmation(c: connection, atype: AllAnalyzers::Tag, aid: count)
@else
event protocol_confirmation(c: connection, atype: Analyzer::Tag, aid: count)
@endif
{
print atype, aid;
}
Expand Down
12 changes: 10 additions & 2 deletions tests/zeek/ssh-banner.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ event ssh::banner(c: connection, is_orig: bool, version: string, software: strin
print "SSH banner", c$id, is_orig, version, software;
}

@if ( Version::number >= 40200 )
event analyzer_confirmation(c: connection, atype: AllAnalyzers::Tag, aid: count)
@else
event protocol_confirmation(c: connection, atype: Analyzer::Tag, aid: count)
@endif
{
if ( atype == Analyzer::ANALYZER_SPICY_SSH )
if ( atype == Analyzer::ANALYZER_SPICY_SSH )
print "confirm", atype;
}

@if ( Version::number >= 40200 )
event analyzer_violation(c: connection, atype: AllAnalyzers::Tag, aid: count, reason: string)
@else
event protocol_violation(c: connection, atype: Analyzer::Tag, aid: count, reason: string)
@endif
{
if ( atype == Analyzer::ANALYZER_SPICY_SSH )
if ( atype == Analyzer::ANALYZER_SPICY_SSH )
print "violation", atype;
}

Expand Down

0 comments on commit f8fde8d

Please sign in to comment.