From ecd273c3ca5aca388f346f244751922429003f16 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Tue, 8 Feb 2022 17:09:13 -0800 Subject: [PATCH] --event-trace / -E option to generate event trace --- src/Options.cc | 17 ++++++++++++----- src/Options.h | 1 + src/zeek-setup.cc | 3 +++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Options.cc b/src/Options.cc index ccc9ddae5e..0cf23a4fd6 100644 --- a/src/Options.cc +++ b/src/Options.cc @@ -114,6 +114,8 @@ void usage(const char* prog, int code) #endif fprintf(stderr, " -C|--no-checksums | ignore checksums\n"); fprintf(stderr, " -D|--deterministic | initialize random seeds to zero\n"); + fprintf(stderr, " -E|--event-trace | generate a replayable event trace to " + "the given file\n"); fprintf(stderr, " -F|--force-dns | force DNS\n"); fprintf(stderr, " -G|--load-seeds | load seeds from given file\n"); fprintf(stderr, " -H|--save-seeds | save seeds to given file\n"); @@ -380,6 +382,7 @@ Options parse_cmdline(int argc, char** argv) {"no-checksums", no_argument, nullptr, 'C'}, {"force-dns", no_argument, nullptr, 'F'}, {"deterministic", no_argument, nullptr, 'D'}, + {"event-trace", required_argument, nullptr, 'E'}, {"load-seeds", required_argument, nullptr, 'G'}, {"save-seeds", required_argument, nullptr, 'H'}, {"print-plugins", no_argument, nullptr, 'N'}, @@ -400,7 +403,7 @@ Options parse_cmdline(int argc, char** argv) {"mem-profile", no_argument, nullptr, 'M'}, #endif - {"pseudo-realtime", optional_argument, nullptr, 'E'}, + {"pseudo-realtime", optional_argument, nullptr, '~'}, {"jobs", optional_argument, nullptr, 'j'}, {"test", no_argument, nullptr, '#'}, @@ -408,7 +411,7 @@ Options parse_cmdline(int argc, char** argv) }; char opts[256]; - util::safe_strncpy(opts, "B:c:e:f:G:H:I:i:j::n:O:0:o:p:r:s:T:t:U:w:X:CDFMNPQSWabdhmuv", + util::safe_strncpy(opts, "B:c:E:e:f:G:H:I:i:j::n:O:0:o:p:r:s:T:t:U:w:X:CDFMNPQSWabdhmuv", sizeof(opts)); int op; @@ -523,9 +526,7 @@ Options parse_cmdline(int argc, char** argv) rval.deterministic_mode = true; break; case 'E': - rval.pseudo_realtime = 1.0; - if ( optarg ) - rval.pseudo_realtime = atof(optarg); + rval.event_trace_file = optarg; break; case 'F': if ( rval.dns_mode != detail::DNS_DEFAULT ) @@ -586,6 +587,12 @@ Options parse_cmdline(int argc, char** argv) break; #endif + case '~': + rval.pseudo_realtime = 1.0; + if ( optarg ) + rval.pseudo_realtime = atof(optarg); + break; + case '#': fprintf(stderr, "ERROR: --test only allowed as first argument.\n"); usage(zargs[0], 1); diff --git a/src/Options.h b/src/Options.h index b9bd1c5e9b..0065b527b9 100644 --- a/src/Options.h +++ b/src/Options.h @@ -73,6 +73,7 @@ struct Options std::optional process_status_file; std::optional zeekygen_config_file; std::optional unprocessed_output_file; + std::optional event_trace_file; std::set plugins_to_load; std::vector scripts_to_load; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 891479f8ff..561270c3c6 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -670,6 +670,9 @@ SetupResult setup(int argc, char** argv, Options* zopts) }; auto ipbb = make_intrusive(init_bifs, ipbid->Name(), false); + if ( options.event_trace_file ) + etm = make_unique(*options.event_trace_file); + run_state::is_parsing = true; yyparse(); run_state::is_parsing = false;