Giving analyzer/ its own CMakeLists.txt.

Also moving src/analyzer.bif to src/analyzer/analyzer.bif, along with
the infrastructure to build/incude bif code at other locations.

We should generally move to having per-directory CMakeLists.txt. I'll
convert the others over later.
This commit is contained in:
Robin Sommer 2013-04-04 16:53:21 -07:00
parent bccaea6883
commit 897be0e147
10 changed files with 83 additions and 40 deletions

View file

@ -103,7 +103,6 @@ target_link_libraries(bifcl)
include(BifCl)
set(BIF_SRCS
analyzer.bif
bro.bif
logging.bif
input.bif
@ -158,6 +157,17 @@ binpac_target(syslog.pac
binpac_target(modbus.pac
modbus-protocol.pac modbus-analyzer.pac)
########################################################################
## Including subdirectories.
########################################################################
add_subdirectory(analyzer)
set(bro_SUBDIRS
$<TARGET_OBJECTS:bro_analyzer>
)
########################################################################
## Including plug-ins that are compiled in statically.
########################################################################
@ -389,11 +399,6 @@ set(bro_SRCS
plugin/Manager.cc
plugin/Plugin.cc
analyzer/Analyzer.cc
analyzer/Manager.cc
analyzer/Component.cc
analyzer/Tag.cc
protocols/BuiltInAnalyzers.cc
nb_dns.c
@ -402,7 +407,7 @@ set(bro_SRCS
collect_headers(bro_HEADERS ${bro_SRCS})
add_executable(bro ${bro_SRCS} ${bro_HEADERS} ${bro_PLUGIN_OBJECT_LIBS})
add_executable(bro ${bro_SRCS} ${bro_HEADERS} ${bro_PLUGIN_OBJECT_LIBS} ${bro_SUBDIRS})
target_link_libraries(bro ${brodeps} ${CMAKE_THREAD_LIBS_INIT})

View file

@ -548,14 +548,12 @@ void builtin_error(const char* msg, BroObj* arg)
reporter->Error(msg, arg);
}
#include "analyzer.bif.func_h"
#include "bro.bif.func_h"
#include "logging.bif.func_h"
#include "input.bif.func_h"
#include "reporter.bif.func_h"
#include "strings.bif.func_h"
#include "analyzer.bif.func_def"
#include "bro.bif.func_def"
#include "logging.bif.func_def"
#include "input.bif.func_def"
@ -571,7 +569,6 @@ void init_builtin_funcs()
var_sizes = internal_type("var_sizes")->AsTableType();
gap_info = internal_type("gap_info")->AsRecordType();
#include "analyzer.bif.func_init"
#include "bro.bif.func_init"
#include "logging.bif.func_init"
#include "input.bif.func_init"

View file

@ -238,7 +238,6 @@ TableType* record_field_table;
StringVal* cmd_line_bpf_filter;
#include "analyzer.bif.netvar_def"
#include "const.bif.netvar_def"
#include "types.bif.netvar_def"
#include "event.bif.netvar_def"

View file

@ -248,7 +248,6 @@ extern void init_general_global_var();
extern void init_event_handlers();
extern void init_net_var();
#include "analyzer.bif.netvar_h"
#include "const.bif.netvar_h"
#include "types.bif.netvar_h"
#include "event.bif.netvar_h"

View file

@ -0,0 +1,16 @@
include_directories(BEFORE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
set(analyzer_SRCS
Analyzer.cc
Manager.cc
Component.cc
Tag.cc
)
bif_target_for_subdir(analyzer.bif)
add_library(bro_analyzer OBJECT ${analyzer_SRCS} ${BIF_OUTPUT_CC} ${BIF_OUTPUT_H})

View file

@ -89,12 +89,18 @@ void Manager::Init()
for ( std::list<Component*>::const_iterator i = analyzers.begin(); i != analyzers.end(); i++ )
RegisterAnalyzerComponent(*i);
// Caache these tags.
// Cache these tags.
analyzer_backdoor = GetAnalyzerTag("BACKDOOR");
analyzer_connsize = GetAnalyzerTag("CONNSIZE");
analyzer_interconn = GetAnalyzerTag("INTERCONN");
analyzer_stepping = GetAnalyzerTag("STEPPINGSTONE");
analyzer_tcpstats = GetAnalyzerTag("TCPSTATS");
}
void Manager::InitBifs()
{
#include "analyzer.bif.init.cc"
}
void Manager::DumpDebug()

View file

@ -29,6 +29,8 @@
#include "../net_util.h"
#include "../IP.h"
#include "analyzer/analyzer.bif.h"
namespace analyzer {
/**
@ -59,6 +61,12 @@ public:
*/
void Init();
/**
* Initializes the analyze-related BiFs. Must be called after scripts
* are parsed.
*/
void InitBifs();
/**
* Finished the manager's operations.
*/

View file

@ -139,6 +139,7 @@ extern int yyparse();
char* input_filename = 0;
char* input_filename_with_path = 0;
char* plugin = 0;
int alternative_mode = 0;
FILE* fp_bro_init = 0;
FILE* fp_func_def = 0;
@ -176,7 +177,7 @@ void usage()
exit(1);
}
void init_plugin_mode()
void init_alternative_mode()
{
fp_bro_init = open_output_file("bro");
fp_func_h = open_output_file("h");
@ -191,8 +192,8 @@ void init_plugin_mode()
char auto_gen_comment[n];
snprintf(auto_gen_comment, n,
"This file was automatically generated by bifcl from %s (plugin mode).",
input_filename_with_path);
"This file was automatically generated by bifcl from %s (%s mode).",
input_filename_with_path, plugin ? "plugin" : "subdir");
fprintf(fp_bro_init, "# %s\n\n", auto_gen_comment);
fprintf(fp_func_def, "// %s\n\n", auto_gen_comment);
@ -225,42 +226,53 @@ void init_plugin_mode()
if ( dot )
*dot = '\0';
fprintf(fp_func_init, "\n");
fprintf(fp_func_init, "#include <list>\n");
fprintf(fp_func_init, "#include <string>\n");
fprintf(fp_func_init, "#include \"%s.h\"\n", input_filename);
fprintf(fp_func_init, "\n");
fprintf(fp_func_init, "namespace plugin { namespace %s {\n", plugin);
fprintf(fp_func_init, "\n");
fprintf(fp_func_init, "std::list<std::pair<std::string, int> > __bif_%s_init()\n", name);
fprintf(fp_func_init, "\t{\n");
fprintf(fp_func_init, "\tstd::list<std::pair<std::string, int> > bifs;\n");
fprintf(fp_func_init, "\n");
if ( plugin )
{
fprintf(fp_func_init, "\n");
fprintf(fp_func_init, "#include <list>\n");
fprintf(fp_func_init, "#include <string>\n");
fprintf(fp_func_init, "#include \"%s.h\"\n", input_filename);
fprintf(fp_func_init, "\n");
fprintf(fp_func_init, "namespace plugin { namespace %s {\n", plugin);
fprintf(fp_func_init, "\n");
fprintf(fp_func_init, "std::list<std::pair<std::string, int> > __bif_%s_init()\n", name);
fprintf(fp_func_init, "\t{\n");
fprintf(fp_func_init, "\tstd::list<std::pair<std::string, int> > bifs;\n");
fprintf(fp_func_init, "\n");
}
}
void finish_plugin_mode()
void finish_alternative_mode()
{
fprintf(fp_func_h, "\n");
fprintf(fp_func_h, "#endif\n");
fprintf(fp_func_init, "\n");
fprintf(fp_func_init, "\treturn bifs;\n");
fprintf(fp_func_init, "\t}\n");
fprintf(fp_func_init, "} }\n");
fprintf(fp_func_init, "\n");
}
if ( plugin )
{
fprintf(fp_func_init, "\n");
fprintf(fp_func_init, "\treturn bifs;\n");
fprintf(fp_func_init, "\t}\n");
fprintf(fp_func_init, "} }\n");
fprintf(fp_func_init, "\n");
}
}
int main(int argc, char* argv[])
{
char opt;
while ( (opt = getopt(argc, argv, "p:")) != -1 )
while ( (opt = getopt(argc, argv, "p:s")) != -1 )
{
switch ( opt ) {
case 'p':
alternative_mode = 1;
plugin = optarg;
break;
case 's':
alternative_mode = 1;
break;
default:
usage();
}
@ -284,7 +296,7 @@ int main(int argc, char* argv[])
if ( slash )
input_filename = slash + 1;
if ( ! plugin )
if ( ! alternative_mode )
{
fp_bro_init = open_output_file("bro");
fp_func_h = open_output_file("func_h");
@ -311,13 +323,13 @@ int main(int argc, char* argv[])
}
else
init_plugin_mode();
init_alternative_mode();
yy_switch_to_buffer(yy_create_buffer(fp_input, YY_BUF_SIZE));
yyparse();
if ( plugin )
finish_plugin_mode();
if ( alternative_mode )
finish_alternative_mode();
fclose(fp_input);
close_all_output_files();
@ -339,7 +351,7 @@ void close_all_output_files(void)
close_if_open(&fp_func_def);
close_if_open(&fp_func_init);
if ( ! plugin )
if ( ! alternative_mode )
{
close_if_open(&fp_netvar_h);
close_if_open(&fp_netvar_def);

View file

@ -836,6 +836,7 @@ int main(int argc, char** argv)
yyparse();
analyzer_mgr->InitBifs();
plugin_mgr->InitPluginsBif();
if ( print_plugins )