--event-trace / -E option to generate event trace

This commit is contained in:
Vern Paxson 2022-02-08 17:09:13 -08:00 committed by Christian Kreibich
parent 39cbd7a9dc
commit ecd273c3ca
3 changed files with 16 additions and 5 deletions

View file

@ -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 <file> | generate a replayable event trace to "
"the given file\n");
fprintf(stderr, " -F|--force-dns | force DNS\n");
fprintf(stderr, " -G|--load-seeds <file> | load seeds from given file\n");
fprintf(stderr, " -H|--save-seeds <file> | 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);

View file

@ -73,6 +73,7 @@ struct Options
std::optional<std::string> process_status_file;
std::optional<std::string> zeekygen_config_file;
std::optional<std::string> unprocessed_output_file;
std::optional<std::string> event_trace_file;
std::set<std::string> plugins_to_load;
std::vector<std::string> scripts_to_load;

View file

@ -670,6 +670,9 @@ SetupResult setup(int argc, char** argv, Options* zopts)
};
auto ipbb = make_intrusive<BuiltinFunc>(init_bifs, ipbid->Name(), false);
if ( options.event_trace_file )
etm = make_unique<EventTraceMgr>(*options.event_trace_file);
run_state::is_parsing = true;
yyparse();
run_state::is_parsing = false;