Remove zeek::Span and use std::span instead

This commit is contained in:
Dominik Charousset 2025-07-24 20:25:51 +02:00
parent 941ea4282b
commit 690a2a1122
33 changed files with 125 additions and 238 deletions

View file

@ -2,6 +2,8 @@
#include "zeek/packet_analysis/Manager.h"
#include <span>
#include "zeek/Event.h"
#include "zeek/RunState.h"
#include "zeek/Stats.h"
@ -251,8 +253,8 @@ void Manager::ReportUnknownProtocol(const std::string& analyzer, uint32_t protoc
}
}
std::vector<zeek::Span<const uint8_t>> Manager::GetAnalyzerData(const AnalyzerPtr& analyzer) {
std::vector<zeek::Span<const uint8_t>> result;
std::vector<std::span<const uint8_t>> Manager::GetAnalyzerData(const AnalyzerPtr& analyzer) {
std::vector<std::span<const uint8_t>> result;
for ( const auto [sa, span] : analyzer_stack ) {
if ( sa == analyzer.get() )
result.push_back(span);

View file

@ -2,6 +2,8 @@
#pragma once
#include <span>
#include "zeek/PacketFilter.h"
#include "zeek/Tag.h"
#include "zeek/iosource/Packet.h"
@ -195,7 +197,7 @@ public:
*
* @returns An array of data spans.
*/
std::vector<zeek::Span<const uint8_t>> GetAnalyzerData(const AnalyzerPtr& analyzer);
std::vector<std::span<const uint8_t>> GetAnalyzerData(const AnalyzerPtr& analyzer);
private:
/**
@ -248,7 +250,7 @@ private:
struct StackEntry {
const Analyzer* analyzer;
zeek::Span<const uint8_t> data; // Start of this layer, limited by span's size.
std::span<const uint8_t> data; // Start of this layer, limited by span's size.
};
std::vector<StackEntry> analyzer_stack;

View file

@ -2,13 +2,14 @@
#include "zeek/packet_analysis/protocol/geneve/Geneve.h"
#include "zeek/Span.h"
#include <span>
#include "zeek/packet_analysis/protocol/geneve/events.bif.h"
#include "zeek/packet_analysis/protocol/iptunnel/IPTunnel.h"
using namespace zeek::packet_analysis::Geneve;
void zeek::packet_analysis::Geneve::detail::parse_options(zeek::Span<const uint8_t> data, detail::Callback cb) {
void zeek::packet_analysis::Geneve::detail::parse_options(std::span<const uint8_t> data, detail::Callback cb) {
size_t remaining = data.size();
if ( remaining < 8 )
@ -40,7 +41,7 @@ void zeek::packet_analysis::Geneve::detail::parse_options(zeek::Span<const uint8
if ( remaining < opt_len )
break;
cb(opt_class, opt_critical, opt_type, zeek::Span{p, opt_len});
cb(opt_class, opt_critical, opt_type, std::span{p, opt_len});
p += opt_len;
}

View file

@ -4,8 +4,8 @@
#include <cstdint>
#include <functional>
#include <span>
#include "zeek/Span.h"
#include "zeek/iosource/Packet.h"
#include "zeek/packet_analysis/Analyzer.h"
@ -17,7 +17,7 @@ namespace detail {
* Callback for parse_options(), passing the individual option pieces.
*/
using Callback =
std::function<void(uint16_t opt_class, bool opt_critical, uint8_t opt_type, zeek::Span<const uint8_t> opt_data)>;
std::function<void(uint16_t opt_class, bool opt_critical, uint8_t opt_type, std::span<const uint8_t> opt_data)>;
/**
* Parse Geneve options from the header data.
@ -27,7 +27,7 @@ using Callback =
* @param data The data span to treat as a Geneve header.
* @param cb The callback to invoke with each parsed option.
*/
void parse_options(zeek::Span<const uint8_t> data, Callback cb);
void parse_options(std::span<const uint8_t> data, Callback cb);
} // namespace detail

View file

@ -1,6 +1,7 @@
module PacketAnalyzer::Geneve;
%%{
#include <span>
#include "zeek/packet_analysis/Manager.h"
#include "zeek/packet_analysis/protocol/geneve/Geneve.h"
%%}
@ -24,7 +25,7 @@ function get_options%(%): geneve_options_vec_vec
for ( const auto& span : spans ) {
auto v = zeek::make_intrusive<zeek::VectorVal>(vtype);
auto cb = [&v](uint16_t opt_class, bool opt_critical, uint8_t opt_type, zeek::Span<const uint8_t> opt_data) -> void {
auto cb = [&v](uint16_t opt_class, bool opt_critical, uint8_t opt_type, std::span<const uint8_t> opt_data) -> void {
auto rv = zeek::make_intrusive<zeek::RecordVal>(rtype);
rv->Assign(0, zeek::val_mgr->Count(opt_class));
rv->Assign(1, zeek::val_mgr->Bool(opt_critical));