A set of smaller API tweaks, and polishing.

This commit is contained in:
Robin Sommer 2014-09-03 12:45:38 -07:00
parent 5e4f498083
commit 569853444f
4 changed files with 31 additions and 24 deletions

View file

@ -64,10 +64,9 @@ PktSrcComponent::factory_callback PktSrcComponent::Factory() const
return factory; return factory;
} }
void PktSrcComponent::DoDescribe(ODesc* d) const
void PktSrcComponent::Describe(ODesc* d) const
{ {
iosource::Component::Describe(d); iosource::Component::DoDescribe(d);
string prefs; string prefs;
@ -77,16 +76,16 @@ void PktSrcComponent::Describe(ODesc* d) const
if ( prefs.size() ) if ( prefs.size() )
prefs += ", "; prefs += ", ";
prefs += *i; prefs += '"' + *i + '"';
} }
d->Add(" (interface prefix"); d->Add("interface prefix");
if ( prefixes.size() > 1 ) if ( prefixes.size() > 1 )
d->Add("es"); d->Add("es");
d->Add(": "); d->Add(" ");
d->Add(prefs); d->Add(prefs);
d->Add("; "); d->Add("; supports ");
switch ( type ) { switch ( type ) {
case LIVE: case LIVE:
@ -105,7 +104,6 @@ void PktSrcComponent::Describe(ODesc* d) const
reporter->InternalError("unknown PkrSrc type"); reporter->InternalError("unknown PkrSrc type");
} }
d->Add(")");
} }
PktDumperComponent::PktDumperComponent(const std::string& name, const std::string& arg_prefix, factory_callback arg_factory) PktDumperComponent::PktDumperComponent(const std::string& name, const std::string& arg_prefix, factory_callback arg_factory)
@ -141,9 +139,9 @@ bool PktDumperComponent::HandlesPrefix(const string& prefix) const
return false; return false;
} }
void PktDumperComponent::Describe(ODesc* d) const void PktDumperComponent::DoDescribe(ODesc* d) const
{ {
plugin::Component::Describe(d); plugin::Component::DoDescribe(d);
string prefs; string prefs;
@ -156,12 +154,11 @@ void PktDumperComponent::Describe(ODesc* d) const
prefs += *i; prefs += *i;
} }
d->Add(" (dumper prefix"); d->Add("dumper prefix");
if ( prefixes.size() > 1 ) if ( prefixes.size() > 1 )
d->Add("es"); d->Add("es");
d->Add(": "); d->Add(": ");
d->Add(prefs); d->Add(prefs);
d->Add(")");
} }

View file

@ -93,7 +93,7 @@ public:
* Generates a human-readable description of the component. This goes * Generates a human-readable description of the component. This goes
* into the output of \c "bro -NN". * into the output of \c "bro -NN".
*/ */
virtual void Describe(ODesc* d) const; virtual void DoDescribe(ODesc* d) const;
private: private:
std::vector<std::string> prefixes; std::vector<std::string> prefixes;
@ -140,7 +140,7 @@ public:
* Generates a human-readable description of the component. This goes * Generates a human-readable description of the component. This goes
* into the output of \c "bro -NN". * into the output of \c "bro -NN".
*/ */
virtual void Describe(ODesc* d) const; virtual void DoDescribe(ODesc* d) const;
private: private:
std::vector<std::string> prefixes; std::vector<std::string> prefixes;

View file

@ -89,6 +89,16 @@ double PktSrc::CurrentPacketWallClock()
void PktSrc::Opened(const Properties& arg_props) void PktSrc::Opened(const Properties& arg_props)
{ {
if ( arg_props.hdr_size < 0 )
{
char buf[512];
safe_snprintf(buf, sizeof(buf),
"unknown data link type 0x%x", props.link_type);
Error(buf);
Close();
return;
}
props = arg_props; props = arg_props;
SetClosed(false); SetClosed(false);
@ -98,6 +108,9 @@ void PktSrc::Opened(const Properties& arg_props)
return; return;
} }
if ( props.is_live )
Info(fmt("listening on %s, capture length %d bytes\n", props.path.c_str(), SnapLen()));
DBG_LOG(DBG_PKTIO, "Opened source %s", props.path.c_str()); DBG_LOG(DBG_PKTIO, "Opened source %s", props.path.c_str());
} }
@ -433,6 +446,9 @@ bool PktSrc::ExtractNextPacketInternal()
bool PktSrc::PrecompileBPFFilter(int index, const std::string& filter) bool PktSrc::PrecompileBPFFilter(int index, const std::string& filter)
{ {
if ( index < 0 )
return false;
char errbuf[PCAP_ERRBUF_SIZE]; char errbuf[PCAP_ERRBUF_SIZE];
// Compile filter. // Compile filter.
@ -465,6 +481,9 @@ bool PktSrc::PrecompileBPFFilter(int index, const std::string& filter)
BPF_Program* PktSrc::GetBPFFilter(int index) BPF_Program* PktSrc::GetBPFFilter(int index)
{ {
if ( index < 0 )
return 0;
HashKey* hash = new HashKey(HashKey(bro_int_t(index))); HashKey* hash = new HashKey(HashKey(bro_int_t(index)));
BPF_Program* code = filters.Lookup(hash); BPF_Program* code = filters.Lookup(hash);
delete hash; delete hash;

View file

@ -108,9 +108,8 @@ void PcapSource::OpenLive()
return; return;
props.is_live = true; props.is_live = true;
Opened(props);
Info(fmt("listening on %s, capture length %d bytes\n", props.path.c_str(), SnapLen())); Opened(props);
} }
void PcapSource::OpenOffline() void PcapSource::OpenOffline()
@ -264,14 +263,6 @@ void PcapSource::SetHdrSize()
props.link_type = pcap_datalink(pd); props.link_type = pcap_datalink(pd);
props.hdr_size = GetLinkHeaderSize(props.link_type); props.hdr_size = GetLinkHeaderSize(props.link_type);
if ( props.hdr_size < 0 )
{
safe_snprintf(errbuf, sizeof(errbuf),
"unknown data link type 0x%x", props.link_type);
Error(errbuf);
Close();
}
} }
iosource::PktSrc* PcapSource::Instantiate(const std::string& path, bool is_live) iosource::PktSrc* PcapSource::Instantiate(const std::string& path, bool is_live)