Initial skeleton of new Broxygen infrastructure.

Doesn't generate any docs, but it's hooked in to all places needed to
gather the necessary stuff w/ significantly less coupling than before.

The gathering now always occurs unconditionally to make documentation
available at runtime and a command line switch (-X) only toggles whether
to output docs to disk (reST format).

Should also improve the treatment of type name aliasing which wasn't a
big problem in practice before, but I think it's more correct now:
there's now a distinct BroType for each alias, but extensible types
(record/enum) will automatically update the types for aliases on redef.

Other misc refactoring of note:

    - Removed a redundant/unused way of declaring event types.

    - Changed type serialization format/process to preserve type name
      information and remove compatibility code (since broccoli will
      have be updated anyway).
This commit is contained in:
Jon Siwek 2013-10-03 10:42:04 -05:00
parent eeaf3e9baf
commit 5a857a6dfc
18 changed files with 393 additions and 838 deletions

View file

@ -61,8 +61,8 @@ extern "C" void OPENSSL_add_all_algorithms_conf(void);
#include "analyzer/Manager.h"
#include "analyzer/Tag.h"
#include "plugin/Manager.h"
#include "file_analysis/Manager.h"
#include "broxygen/Manager.h"
#include "binpac_bro.h"
@ -100,6 +100,7 @@ input::Manager* input_mgr = 0;
plugin::Manager* plugin_mgr = 0;
analyzer::Manager* analyzer_mgr = 0;
file_analysis::Manager* file_mgr = 0;
broxygen::Manager* broxygen_mgr = 0;
Stmt* stmts;
EventHandlerPtr net_done = 0;
RuleMatcher* rule_matcher = 0;
@ -116,7 +117,6 @@ int signal_val = 0;
int optimize = 0;
int do_notice_analysis = 0;
int rule_bench = 0;
int generate_documentation = 0;
SecondaryPath* secondary_path = 0;
extern char version[];
char* command_line_policy = 0;
@ -124,6 +124,8 @@ vector<string> params;
char* proc_status_file = 0;
int snaplen = 0; // this gets set from the scripting-layer's value
TypeAliasMap type_aliases;
OpaqueType* md5_type = 0;
OpaqueType* sha1_type = 0;
OpaqueType* sha256_type = 0;
@ -132,8 +134,6 @@ OpaqueType* cardinality_type = 0;
OpaqueType* topk_type = 0;
OpaqueType* bloomfilter_type = 0;
extern std::list<BroDoc*> docs_generated;
// Keep copy of command line
int bro_argc;
char** bro_argv;
@ -203,7 +203,7 @@ void usage()
fprintf(stderr, " -T|--re-level <level> | set 'RE_level' for rules\n");
fprintf(stderr, " -U|--status-file <file> | Record process status in file\n");
fprintf(stderr, " -W|--watchdog | activate watchdog timer\n");
fprintf(stderr, " -Z|--doc-scripts | generate documentation for all loaded scripts\n");
fprintf(stderr, " -X|--broxygen | generate documentation based on config file\n");
#ifdef USE_PERFTOOLS_DEBUG
fprintf(stderr, " -m|--mem-leaks | show leaks [perftools]\n");
@ -373,6 +373,7 @@ void terminate_bro()
plugin_mgr->FinishPlugins();
delete broxygen_mgr;
delete timer_mgr;
delete dns_mgr;
delete persistence_serializer;
@ -473,7 +474,7 @@ int main(int argc, char** argv)
{"filter", required_argument, 0, 'f'},
{"help", no_argument, 0, 'h'},
{"iface", required_argument, 0, 'i'},
{"doc-scripts", no_argument, 0, 'Z'},
{"broxygen", required_argument, 0, 'X'},
{"prefix", required_argument, 0, 'p'},
{"readfile", required_argument, 0, 'r'},
{"flowfile", required_argument, 0, 'y'},
@ -532,7 +533,7 @@ int main(int argc, char** argv)
if ( p )
add_to_name_list(p, ':', prefixes);
string active_file;
string broxygen_config;
#ifdef USE_IDMEF
string libidmef_dtd_path = "idmef-message.dtd";
@ -545,7 +546,7 @@ int main(int argc, char** argv)
opterr = 0;
char opts[256];
safe_strncpy(opts, "B:D:e:f:I:i:K:l:n:p:R:r:s:T:t:U:w:x:X:y:Y:z:CFGLNOPSWbdghvZ",
safe_strncpy(opts, "B:D:e:f:I:i:K:l:n:p:R:r:s:T:t:U:w:x:X:y:Y:z:CFGLNOPSWbdghv",
sizeof(opts));
#ifdef USE_PERFTOOLS_DEBUG
@ -727,8 +728,8 @@ int main(int argc, char** argv)
break;
#endif
case 'Z':
generate_documentation = 1;
case 'X':
broxygen_config = optarg;
break;
#ifdef USE_IDMEF
@ -760,6 +761,7 @@ int main(int argc, char** argv)
reporter = new Reporter();
thread_mgr = new threading::Manager();
broxygen_mgr = new broxygen::Manager(broxygen_config);
#ifdef DEBUG
if ( debug_streams )
@ -888,23 +890,6 @@ int main(int argc, char** argv)
}
#endif
if ( generate_documentation )
{
CreateProtoAnalyzerDoc("proto-analyzers.rst");
CreateFileAnalyzerDoc("file-analyzers.rst");
std::list<BroDoc*>::iterator it;
for ( it = docs_generated.begin(); it != docs_generated.end(); ++it )
(*it)->WriteDocFile();
for ( it = docs_generated.begin(); it != docs_generated.end(); ++it )
delete *it;
terminate_bro();
return 0;
}
if ( reporter->Errors() > 0 )
{
delete dns_mgr;
@ -915,6 +900,8 @@ int main(int argc, char** argv)
init_general_global_var();
broxygen_mgr->GenerateDocs();
if ( user_pcap_filter )
{
ID* id = global_scope()->Lookup("cmd_line_bpf_filter");