diff --git a/TODO.iosources b/TODO.iosources index 7b84a60fb4..e6afb3978a 100644 --- a/TODO.iosources +++ b/TODO.iosources @@ -1,10 +1,4 @@ -- Move the current_{iosrc,pkt_src,etc.} into manager -- Remove all 2ndary path code -- Remove all flow src code. -- Move pktsrc/*.{h,cc} up a level? Or create a subsublibrary there? -- Create a global Packet data structure and pass that around instead - of the pcap_* stuff? - PktDumper: Move Dump() to public and remove Record() - Wrap BPF_Program into namespace and clean up -- Tests, in particular the packet dumping needs testing. - Add an interface for derived pkt source to run a BPF filter. +- Tests, in particular the packet dumping needs testing. diff --git a/src/Net.cc b/src/Net.cc index af9e3bb57f..70d8b70169 100644 --- a/src/Net.cc +++ b/src/Net.cc @@ -30,8 +30,8 @@ #include "Serializer.h" #include "PacketDumper.h" #include "iosource/Manager.h" -#include "iosource/pktsrc/PktSrc.h" -#include "iosource/pktsrc/PktDumper.h" +#include "iosource/PktSrc.h" +#include "iosource/PktDumper.h" #include "plugin/Manager.h" extern "C" { diff --git a/src/Net.h b/src/Net.h index 073ffcd527..41cbd69abe 100644 --- a/src/Net.h +++ b/src/Net.h @@ -9,8 +9,8 @@ #include "Func.h" #include "RemoteSerializer.h" #include "iosource/IOSource.h" -#include "iosource/pktsrc/PktSrc.h" -#include "iosource/pktsrc/PktDumper.h" +#include "iosource/PktSrc.h" +#include "iosource/PktDumper.h" extern void net_init(name_list& interfaces, name_list& readfiles, const char* writefile, const char* filter, diff --git a/src/iosource/CMakeLists.txt b/src/iosource/CMakeLists.txt index c2b63e3d7e..6bcfa16289 100644 --- a/src/iosource/CMakeLists.txt +++ b/src/iosource/CMakeLists.txt @@ -6,15 +6,11 @@ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ) -add_subdirectory(pktsrc) - set(iosource_SRCS Component.cc Manager.cc - - pktsrc/Component.cc - pktsrc/PktDumper.cc - pktsrc/PktSrc.cc + PktDumper.cc + PktSrc.cc ) bro_add_subdir_library(iosource ${iosource_SRCS}) diff --git a/src/iosource/Component.cc b/src/iosource/Component.cc index fa57a7d5ad..f54c212352 100644 --- a/src/iosource/Component.cc +++ b/src/iosource/Component.cc @@ -2,6 +2,7 @@ #include "Component.h" #include "Desc.h" +#include "Reporter.h" using namespace iosource; @@ -18,3 +19,149 @@ Component::Component(plugin::component::Type type, const std::string& name) Component::~Component() { } + +PktSrcComponent::PktSrcComponent(const std::string& arg_name, const std::string& arg_prefix, InputType arg_type, factory_callback arg_factory) + : iosource::Component(plugin::component::PKTSRC, arg_name) + { + tokenize_string(arg_prefix, ":", &prefixes); + type = arg_type; + factory = arg_factory; + } + +PktSrcComponent::~PktSrcComponent() + { + } + +const std::vector& PktSrcComponent::Prefixes() const + { + return prefixes; + } + +bool PktSrcComponent::HandlesPrefix(const string& prefix) const + { + for ( std::vector::const_iterator i = prefixes.begin(); + i != prefixes.end(); i++ ) + { + if ( *i == prefix ) + return true; + } + + return false; + } + +bool PktSrcComponent::DoesLive() const + { + return type == LIVE || type == BOTH; + } + +bool PktSrcComponent::DoesTrace() const + { + return type == TRACE || type == BOTH; + } + +PktSrcComponent::factory_callback PktSrcComponent::Factory() const + { + return factory; + } + + +void PktSrcComponent::Describe(ODesc* d) const + { + iosource::Component::Describe(d); + + string prefs; + + for ( std::vector::const_iterator i = prefixes.begin(); + i != prefixes.end(); i++ ) + { + if ( prefs.size() ) + prefs += ", "; + + prefs += *i; + } + + d->Add(" (interface prefix"); + if ( prefixes.size() > 1 ) + d->Add("es"); + + d->Add(": "); + d->Add(prefs); + d->Add("; "); + + switch ( type ) { + case LIVE: + d->Add("live input"); + break; + + case TRACE: + d->Add("trace input"); + break; + + case BOTH: + d->Add("live and trace input"); + break; + + default: + reporter->InternalError("unknown PkrSrc type"); + } + + d->Add(")"); + } + +PktDumperComponent::PktDumperComponent(const std::string& name, const std::string& arg_prefix, factory_callback arg_factory) + : plugin::Component(plugin::component::PKTDUMPER, name) + { + tokenize_string(arg_prefix, ":", &prefixes); + factory = arg_factory; + } + +PktDumperComponent::~PktDumperComponent() + { + } + +PktDumperComponent::factory_callback PktDumperComponent::Factory() const + { + return factory; + } + +const std::vector& PktDumperComponent::Prefixes() const + { + return prefixes; + } + +bool PktDumperComponent::HandlesPrefix(const string& prefix) const + { + for ( std::vector::const_iterator i = prefixes.begin(); + i != prefixes.end(); i++ ) + { + if ( *i == prefix ) + return true; + } + + return false; + } + +void PktDumperComponent::Describe(ODesc* d) const + { + plugin::Component::Describe(d); + + string prefs; + + for ( std::vector::const_iterator i = prefixes.begin(); + i != prefixes.end(); i++ ) + { + if ( prefs.size() ) + prefs += ", "; + + prefs += *i; + } + + d->Add(" (dumper prefix"); + + if ( prefixes.size() > 1 ) + d->Add("es"); + + d->Add(": "); + d->Add(prefs); + d->Add(")"); + } diff --git a/src/iosource/Component.h b/src/iosource/Component.h index 065855caea..c93597fd67 100644 --- a/src/iosource/Component.h +++ b/src/iosource/Component.h @@ -3,11 +3,16 @@ #ifndef IOSOURCE_PLUGIN_COMPONENT_H #define IOSOURCE_PLUGIN_COMPONENT_H +#include +#include + #include "plugin/Component.h" namespace iosource { class IOSource; +class PktSrc; +class PktDumper; /** * Component description for plugins providing IOSources. @@ -38,6 +43,110 @@ protected: Component(plugin::component::Type type, const std::string& name); }; +/** + * Component description for plugins providing a PktSrc for packet input. + */ +class PktSrcComponent : public iosource::Component { +public: + enum InputType { LIVE, TRACE, BOTH }; + + typedef PktSrc* (*factory_callback)(const std::string& path, const std::string& filter, bool is_live); + + /** + * XXX + */ + PktSrcComponent(const std::string& name, const std::string& prefixes, InputType type, factory_callback factory); + + /** + * Destructor. + */ + virtual ~PktSrcComponent(); + + /** + * Returns the prefix(es) passed to the constructor. + */ + const std::vector& Prefixes() const; + + /** + * Returns true if the given prefix is among the one specified for the component. + */ + bool HandlesPrefix(const std::string& prefix) const; + + /** + * Returns true if packet source instantiated by the component handle + * live traffic. + */ + bool DoesLive() const; + + /** + * Returns true if packet source instantiated by the component handle + * offline traces. + */ + bool DoesTrace() const; + + /** + * Returns the source's factory function. + */ + factory_callback Factory() const; + + /** + * Generates a human-readable description of the component. This goes + * into the output of \c "bro -NN". + */ + virtual void Describe(ODesc* d) const; + +private: + std::vector prefixes; + InputType type; + factory_callback factory; +}; + +/** + * Component description for plugins providing a PktDumper for packet output. + * + * PktDumpers aren't IOSurces but we locate them here to keep them along with + * the PktSrc. + */ +class PktDumperComponent : public plugin::Component { +public: + typedef PktDumper* (*factory_callback)(const std::string& path, bool append); + + /** + * XXX + */ + PktDumperComponent(const std::string& name, const std::string& prefixes, factory_callback factory); + + /** + * Destructor. + */ + ~PktDumperComponent(); + + /** + * Returns the prefix(es) passed to the constructor. + */ + const std::vector& Prefixes() const; + + /** + * Returns true if the given prefix is among the one specified for the component. + */ + bool HandlesPrefix(const std::string& prefix) const; + + /** + * Returns the source's factory function. + */ + factory_callback Factory() const; + + /** + * Generates a human-readable description of the component. This goes + * into the output of \c "bro -NN". + */ + virtual void Describe(ODesc* d) const; + +private: + std::vector prefixes; + factory_callback factory; +}; + } #endif diff --git a/src/iosource/Manager.cc b/src/iosource/Manager.cc index 6c01e5e57b..e2be297a77 100644 --- a/src/iosource/Manager.cc +++ b/src/iosource/Manager.cc @@ -8,9 +8,8 @@ #include "Manager.h" #include "IOSource.h" -#include "pktsrc/PktSrc.h" -#include "pktsrc/PktDumper.h" -#include "pktsrc/Component.h" +#include "PktSrc.h" +#include "PktDumper.h" #include "plugin/Manager.h" #include "util.h" @@ -222,14 +221,14 @@ PktSrc* Manager::OpenPktSrc(const std::string& path, const std::string& filter, // Find the component providing packet sources of the requested prefix. - pktsrc::SourceComponent* component = 0; + PktSrcComponent* component = 0; - std::list all_components = plugin_mgr->Components(); + std::list all_components = plugin_mgr->Components(); - for ( std::list::const_iterator i = all_components.begin(); + for ( std::list::const_iterator i = all_components.begin(); i != all_components.end(); i++ ) { - pktsrc::SourceComponent* c = *i; + PktSrcComponent* c = *i; if ( c->HandlesPrefix(prefix) && (( is_live && c->DoesLive() ) || @@ -272,11 +271,11 @@ PktDumper* Manager::OpenPktDumper(const string& path, bool append) // Find the component providing packet dumpers of the requested prefix. - pktsrc::DumperComponent* component = 0; + PktDumperComponent* component = 0; - std::list all_components = plugin_mgr->Components(); + std::list all_components = plugin_mgr->Components(); - for ( std::list::const_iterator i = all_components.begin(); + for ( std::list::const_iterator i = all_components.begin(); i != all_components.end(); i++ ) { if ( (*i)->HandlesPrefix(prefix) ) diff --git a/src/iosource/pktsrc/PktDumper.cc b/src/iosource/PktDumper.cc similarity index 100% rename from src/iosource/pktsrc/PktDumper.cc rename to src/iosource/PktDumper.cc diff --git a/src/iosource/pktsrc/PktDumper.h b/src/iosource/PktDumper.h similarity index 97% rename from src/iosource/pktsrc/PktDumper.h rename to src/iosource/PktDumper.h index b8f3595e32..794992d870 100644 --- a/src/iosource/pktsrc/PktDumper.h +++ b/src/iosource/PktDumper.h @@ -3,7 +3,7 @@ #ifndef IOSOURCE_PKTSRC_PKTDUMPER_H #define IOSOURCE_PKTSRC_PKTDUMPER_H -#include "../IOSource.h" +#include "IOSource.h" namespace iosource { diff --git a/src/iosource/pktsrc/PktSrc.cc b/src/iosource/PktSrc.cc similarity index 100% rename from src/iosource/pktsrc/PktSrc.cc rename to src/iosource/PktSrc.cc diff --git a/src/iosource/pktsrc/PktSrc.h b/src/iosource/PktSrc.h similarity index 99% rename from src/iosource/pktsrc/PktSrc.h rename to src/iosource/PktSrc.h index 3eddaec6e8..d04ca24817 100644 --- a/src/iosource/pktsrc/PktSrc.h +++ b/src/iosource/PktSrc.h @@ -7,7 +7,7 @@ extern "C" { #include } -#include "../IOSource.h" +#include "IOSource.h" namespace iosource { diff --git a/src/iosource/pktsrc/pcap/BPF_Program.cc b/src/iosource/pcap/BPF_Program.cc similarity index 100% rename from src/iosource/pktsrc/pcap/BPF_Program.cc rename to src/iosource/pcap/BPF_Program.cc diff --git a/src/iosource/pktsrc/pcap/BPF_Program.h b/src/iosource/pcap/BPF_Program.h similarity index 100% rename from src/iosource/pktsrc/pcap/BPF_Program.h rename to src/iosource/pcap/BPF_Program.h diff --git a/src/iosource/pktsrc/pcap/CMakeLists.txt b/src/iosource/pcap/CMakeLists.txt similarity index 100% rename from src/iosource/pktsrc/pcap/CMakeLists.txt rename to src/iosource/pcap/CMakeLists.txt diff --git a/src/iosource/pktsrc/pcap/Dumper.cc b/src/iosource/pcap/Dumper.cc similarity index 100% rename from src/iosource/pktsrc/pcap/Dumper.cc rename to src/iosource/pcap/Dumper.cc diff --git a/src/iosource/pktsrc/pcap/Dumper.h b/src/iosource/pcap/Dumper.h similarity index 100% rename from src/iosource/pktsrc/pcap/Dumper.h rename to src/iosource/pcap/Dumper.h diff --git a/src/iosource/pktsrc/pcap/Plugin.cc b/src/iosource/pcap/Plugin.cc similarity index 100% rename from src/iosource/pktsrc/pcap/Plugin.cc rename to src/iosource/pcap/Plugin.cc diff --git a/src/iosource/pktsrc/pcap/Source.cc b/src/iosource/pcap/Source.cc similarity index 100% rename from src/iosource/pktsrc/pcap/Source.cc rename to src/iosource/pcap/Source.cc diff --git a/src/iosource/pktsrc/pcap/Source.h b/src/iosource/pcap/Source.h similarity index 100% rename from src/iosource/pktsrc/pcap/Source.h rename to src/iosource/pcap/Source.h diff --git a/src/iosource/pktsrc/CMakeLists.txt b/src/iosource/pktsrc/CMakeLists.txt deleted file mode 100644 index 07303b46a3..0000000000 --- a/src/iosource/pktsrc/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ - -add_subdirectory(pcap) diff --git a/src/iosource/pktsrc/Component.cc b/src/iosource/pktsrc/Component.cc deleted file mode 100644 index 6caf743ff9..0000000000 --- a/src/iosource/pktsrc/Component.cc +++ /dev/null @@ -1,155 +0,0 @@ -// See the file "COPYING" in the main distribution directory for copyright. - -#include "Component.h" - -#include "../Desc.h" -#include "../Reporter.h" - -using namespace iosource::pktsrc; - -SourceComponent::SourceComponent(const std::string& arg_name, const std::string& arg_prefix, InputType arg_type, factory_callback arg_factory) - : iosource::Component(plugin::component::PKTSRC, arg_name) - { - tokenize_string(arg_prefix, ":", &prefixes); - type = arg_type; - factory = arg_factory; - } - -SourceComponent::~SourceComponent() - { - } - -const std::vector& SourceComponent::Prefixes() const - { - return prefixes; - } - -bool SourceComponent::HandlesPrefix(const string& prefix) const - { - for ( std::vector::const_iterator i = prefixes.begin(); - i != prefixes.end(); i++ ) - { - if ( *i == prefix ) - return true; - } - - return false; - } - -bool SourceComponent::DoesLive() const - { - return type == LIVE || type == BOTH; - } - -bool SourceComponent::DoesTrace() const - { - return type == TRACE || type == BOTH; - } - -SourceComponent::factory_callback SourceComponent::Factory() const - { - return factory; - } - - -void SourceComponent::Describe(ODesc* d) const - { - iosource::Component::Describe(d); - - string prefs; - - for ( std::vector::const_iterator i = prefixes.begin(); - i != prefixes.end(); i++ ) - { - if ( prefs.size() ) - prefs += ", "; - - prefs += *i; - } - - d->Add(" (interface prefix"); - if ( prefixes.size() > 1 ) - d->Add("es"); - - d->Add(": "); - d->Add(prefs); - d->Add("; "); - - switch ( type ) { - case LIVE: - d->Add("live input"); - break; - - case TRACE: - d->Add("trace input"); - break; - - case BOTH: - d->Add("live and trace input"); - break; - - default: - reporter->InternalError("unknown PkrSrc type"); - } - - d->Add(")"); - } - -DumperComponent::DumperComponent(const std::string& name, const std::string& arg_prefix, factory_callback arg_factory) - : plugin::Component(plugin::component::PKTDUMPER, name) - { - tokenize_string(arg_prefix, ":", &prefixes); - factory = arg_factory; - } - -DumperComponent::~DumperComponent() - { - } - -DumperComponent::factory_callback DumperComponent::Factory() const - { - return factory; - } - -const std::vector& DumperComponent::Prefixes() const - { - return prefixes; - } - -bool DumperComponent::HandlesPrefix(const string& prefix) const - { - for ( std::vector::const_iterator i = prefixes.begin(); - i != prefixes.end(); i++ ) - { - if ( *i == prefix ) - return true; - } - - return false; - } - -void DumperComponent::Describe(ODesc* d) const - { - plugin::Component::Describe(d); - - string prefs; - - for ( std::vector::const_iterator i = prefixes.begin(); - i != prefixes.end(); i++ ) - { - if ( prefs.size() ) - prefs += ", "; - - prefs += *i; - } - - d->Add(" (dumper prefix"); - - if ( prefixes.size() > 1 ) - d->Add("es"); - - d->Add(": "); - d->Add(prefs); - d->Add(")"); - } - diff --git a/src/iosource/pktsrc/Component.h b/src/iosource/pktsrc/Component.h deleted file mode 100644 index 0e4755d7b8..0000000000 --- a/src/iosource/pktsrc/Component.h +++ /dev/null @@ -1,124 +0,0 @@ -// See the file "COPYING" in the main distribution directory for copyright. - -#ifndef IOSOURCE_PKTSRC_PLUGIN_COMPONENT_H -#define IOSOURCE_PKTSRC_PLUGIN_COMPONENT_H - -#include - -#include "../Component.h" - -namespace iosource { - -class PktSrc; -class PktDumper; - -namespace pktsrc { - -/** - * Component description for plugins providing a PktSrc for packet input. - */ -class SourceComponent : public iosource::Component { -public: - enum InputType { LIVE, TRACE, BOTH }; - - typedef PktSrc* (*factory_callback)(const std::string& path, const std::string& filter, bool is_live); - - /** - * XXX - */ - SourceComponent(const std::string& name, const std::string& prefixes, InputType type, factory_callback factory); - - /** - * Destructor. - */ - virtual ~SourceComponent(); - - /** - * Returns the prefix(es) passed to the constructor. - */ - const std::vector& Prefixes() const; - - /** - * Returns true if the given prefix is among the one specified for the component. - */ - bool HandlesPrefix(const std::string& prefix) const; - - /** - * Returns true if packet source instantiated by the component handle - * live traffic. - */ - bool DoesLive() const; - - /** - * Returns true if packet source instantiated by the component handle - * offline traces. - */ - bool DoesTrace() const; - - /** - * Returns the source's factory function. - */ - factory_callback Factory() const; - - /** - * Generates a human-readable description of the component. This goes - * into the output of \c "bro -NN". - */ - virtual void Describe(ODesc* d) const; - -private: - std::vector prefixes; - InputType type; - factory_callback factory; -}; - -/** - * Component description for plugins providing a PktDumper for packet output. - * - * PktDumpers aren't IOSurces but we locate them here to keep them along with - * the PktSrc. - */ -class DumperComponent : public plugin::Component { -public: - typedef PktDumper* (*factory_callback)(const std::string& path, bool append); - - /** - * XXX - */ - DumperComponent(const std::string& name, const std::string& prefixes, factory_callback factory); - - /** - * Destructor. - */ - ~DumperComponent(); - - /** - * Returns the prefix(es) passed to the constructor. - */ - const std::vector& Prefixes() const; - - /** - * Returns true if the given prefix is among the one specified for the component. - */ - bool HandlesPrefix(const std::string& prefix) const; - - /** - * Returns the source's factory function. - */ - factory_callback Factory() const; - - /** - * Generates a human-readable description of the component. This goes - * into the output of \c "bro -NN". - */ - virtual void Describe(ODesc* d) const; - -private: - std::vector prefixes; - factory_callback factory; -}; - -} -} - -#endif diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index 773fe139f6..ccda20054c 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -10,7 +10,6 @@ #include "analyzer/Component.h" #include "file_analysis/Component.h" #include "iosource/Component.h" -#include "iosource/pktsrc/Component.h" // We allow to override this externally for testing purposes. #ifndef BRO_PLUGIN_API_VERSION