mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
Adding test for dynamic packet dumper plugin.
This commit is contained in:
parent
b813b6f83b
commit
6e33c92cf0
7 changed files with 127 additions and 0 deletions
12
testing/btest/Baseline/plugins.pktdumper/output
Normal file
12
testing/btest/Baseline/plugins.pktdumper/output
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
Demo::Foo - A Foo packet dumper (dynamic, version 1.0)
|
||||||
|
[Packet Dumper] FooPktDumper (dumper prefix: foo)
|
||||||
|
|
||||||
|
===
|
||||||
|
Dumping to XXX: 1373858797.646968 len 94
|
||||||
|
Dumping to XXX: 1373858797.646998 len 94
|
||||||
|
Dumping to XXX: 1373858797.647041 len 86
|
||||||
|
Dumping to XXX: 1373858797.647147 len 98
|
||||||
|
Dumping to XXX: 1373858797.647186 len 86
|
||||||
|
Dumping to XXX: 1373858797.647250 len 86
|
||||||
|
Dumping to XXX: 1373858797.647317 len 86
|
||||||
|
Dumping to XXX: 1373858797.647350 len 86
|
0
testing/btest/plugins/pktdumper-plugin/.btest-ignore
Normal file
0
testing/btest/plugins/pktdumper-plugin/.btest-ignore
Normal file
17
testing/btest/plugins/pktdumper-plugin/CMakeLists.txt
Normal file
17
testing/btest/plugins/pktdumper-plugin/CMakeLists.txt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
project(Bro-Plugin-Demo-Foo)
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 2.6.3)
|
||||||
|
|
||||||
|
if ( NOT BRO_DIST )
|
||||||
|
message(FATAL_ERROR "BRO_DIST not set")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH ${BRO_DIST}/cmake)
|
||||||
|
|
||||||
|
include(BroPlugin)
|
||||||
|
|
||||||
|
bro_plugin_begin(Demo Foo)
|
||||||
|
bro_plugin_cc(src/Plugin.cc)
|
||||||
|
bro_plugin_cc(src/Foo.cc)
|
||||||
|
bro_plugin_end()
|
40
testing/btest/plugins/pktdumper-plugin/src/Foo.cc
Normal file
40
testing/btest/plugins/pktdumper-plugin/src/Foo.cc
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "Foo.h"
|
||||||
|
|
||||||
|
using namespace plugin::Demo_Foo;
|
||||||
|
|
||||||
|
Foo::Foo(const std::string& path, bool is_live)
|
||||||
|
{
|
||||||
|
props.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
Foo::~Foo()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Foo::Open()
|
||||||
|
{
|
||||||
|
props.open_time = network_time;
|
||||||
|
props.hdr_size = 0;
|
||||||
|
Opened(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Foo::Close()
|
||||||
|
{
|
||||||
|
Closed();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Foo::Dump(const Packet* pkt)
|
||||||
|
{
|
||||||
|
double t = double(pkt->hdr->ts.tv_sec) + double(pkt->hdr->ts.tv_usec) / 1e6;
|
||||||
|
fprintf(stdout, "Dumping to %s: %.6f len %u\n", props.path.c_str(), t, (unsigned int)pkt->hdr->len);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
iosource::PktDumper* Foo::Instantiate(const std::string& path, bool append)
|
||||||
|
{
|
||||||
|
return new Foo(path, append);
|
||||||
|
}
|
30
testing/btest/plugins/pktdumper-plugin/src/Foo.h
Normal file
30
testing/btest/plugins/pktdumper-plugin/src/Foo.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
|
||||||
|
#ifndef BRO_PLUGIN_DEMO_FOO_H
|
||||||
|
#define BRO_PLUGIN_DEMO_FOO_H
|
||||||
|
|
||||||
|
#include <Val.h>
|
||||||
|
#include <iosource/PktDumper.h>
|
||||||
|
|
||||||
|
namespace plugin {
|
||||||
|
namespace Demo_Foo {
|
||||||
|
|
||||||
|
class Foo : public iosource::PktDumper {
|
||||||
|
public:
|
||||||
|
Foo(const std::string& path, bool is_live);
|
||||||
|
virtual ~Foo();
|
||||||
|
|
||||||
|
static PktDumper* Instantiate(const std::string& path, bool append);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void Open();
|
||||||
|
virtual void Close();
|
||||||
|
virtual bool Dump(const Packet* pkt);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Properties props;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
20
testing/btest/plugins/pktdumper-plugin/src/Plugin.cc
Normal file
20
testing/btest/plugins/pktdumper-plugin/src/Plugin.cc
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
#include "Plugin.h"
|
||||||
|
|
||||||
|
#include "Foo.h"
|
||||||
|
|
||||||
|
namespace plugin { namespace Demo_Foo { Plugin plugin; } }
|
||||||
|
|
||||||
|
using namespace plugin::Demo_Foo;
|
||||||
|
|
||||||
|
plugin::Configuration Plugin::Configure()
|
||||||
|
{
|
||||||
|
AddComponent(new ::iosource::PktDumperComponent("FooPktDumper", "foo", ::plugin::Demo_Foo::Foo::Instantiate));
|
||||||
|
|
||||||
|
plugin::Configuration config;
|
||||||
|
config.name = "Demo::Foo";
|
||||||
|
config.description = "A Foo packet dumper";
|
||||||
|
config.version.major = 1;
|
||||||
|
config.version.minor = 0;
|
||||||
|
return config;
|
||||||
|
}
|
8
testing/btest/plugins/pktdumper.bro
Normal file
8
testing/btest/plugins/pktdumper.bro
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Foo
|
||||||
|
# @TEST-EXEC: cp -r %DIR/pktdumper-plugin/* .
|
||||||
|
# @TEST-EXEC: ./configure --bro-dist=${DIST} && make
|
||||||
|
# @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -NN Demo::Foo >>output
|
||||||
|
# @TEST-EXEC: echo === >>output
|
||||||
|
# @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -r $TRACES/port4242.trace -w foo:XXX %INPUT FilteredTraceDetection::enable=F >>output
|
||||||
|
# @TEST-EXEC: btest-diff output
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue