42 #ifdef WITH_PLUGIN_SIXT
55 #define LEGACY_INTERVAL_CNT 60
61 #define HARD_SHUTDOWN 3
65 static libtrace_t *
trace = NULL;
67 static libtrace_packet_t *
packet = NULL;
69 static libtrace_filter_t *
filter = NULL;
71 #ifdef WITH_PLUGIN_SIXT
92 fprintf(stderr,
"caught %d SIGINT's. shutting down NOW\n",
97 fprintf(stderr,
"caught SIGINT, shutting down at the next opportunity\n");
114 trace_destroy_packet(
packet);
118 #ifdef WITH_PLUGIN_SIXT
137 (
packet = trace_create_packet()) == NULL) {
138 perror(
"Creating libtrace packet");
142 trace = trace_create(tracefile);
144 if (trace_is_err(
trace)) {
145 trace_perror(
trace,
"Opening trace file");
152 fprintf(stderr,
"WARNING: -l makes no sense when used with a pcap file\n");
159 "switching input to promiscuous mode");
161 trace_perror(
trace,
"ignoring: ");
165 if (trace_start(
trace) == -1) {
166 trace_perror(
trace,
"Starting trace");
178 trace_destroy(
trace);
189 "could not init trace for reading %s",
201 corsaro_log(__func__, corsaro,
"corsaro_per_packet failed");
206 if (trace_is_err(
trace)) {
207 trace_perror(
trace,
"Reading packets");
208 corsaro_log(__func__, corsaro,
"libtrace had an error reading packets");
212 if(trace_get_dropped_packets(
trace) != UINT64_MAX)
214 corsaro_log(__func__, corsaro,
"dropped pkt cnt: %"PRIu64
"\n",
215 trace_get_dropped_packets(
trace));
221 #ifdef WITH_PLUGIN_SIXT
229 "could not alloc corsaro_in to read %s",
237 corsaro_log(__func__, corsaro,
"could not alloc record");
244 corsaro_log(__func__, corsaro,
"could not start corsaro");
260 if(corsaro_in != NULL)
277 "could not init flowtuple reading for %s", corsuri);
311 "corsaro_in_read_record failed to read record\n");
329 fprintf(stderr,
"corsaro_get_plugin_names failed\n");
334 "usage: %s [-alP] -o outfile [-i interval] [-m mode] [-n name]\n"
335 " [-p plugin] [-f filter] [-r intervals]"
336 " trace_uri [trace_uri...]\n"
337 " -a align the end time of the first interval\n"
338 " -o <outfile> use <outfile> as a template for file names.\n"
339 " - %%P => plugin name\n"
340 " - %%N => monitor name\n"
341 " - see man strftime(3) for more options\n"
342 " -f <filter> BPF filter to apply to packets\n"
343 " -G disable the global metadata output file\n"
344 " -i <interval> distribution interval in seconds (default: %d)\n"
345 " -l the input file has legacy intervals (FlowTuple only)\n"
346 " -L disable logging to a file\n"
347 " -m <mode> output in 'ascii' or 'binary'. (default: binary)\n"
348 " -n <name> monitor name (default: "
349 STR(CORSARO_MONITOR_NAME)
")\n"
350 " -p <plugin> enable the given plugin, -p can be used "
351 "multiple times (default: all)\n"
352 " available plugins:\n",
355 for(i = 0; i < plugin_cnt; i++)
357 fprintf(stderr,
" - %s\n", plugin_names[i]);
360 " use -p \"<plugin_name> -?\" to see plugin options\n"
361 " -P enable promiscuous mode on the input"
363 " -r rotate output files after n intervals\n"
364 " -R rotate corsaro meta files after n intervals\n"
371 int main(
int argc,
char *argv[])
380 char *bpf_filter = NULL;
385 char *plugin_arg_ptr = NULL;
386 int tracefile_cnt = 0;
387 char *traceuri =
"Multiple Traces";
390 int meta_rotate = -1;
391 int logfile_disable = 0;
392 int global_file_disable = 0;
396 while(prevoptind = optind,
397 (opt = getopt(argc, argv,
":f:i:m:n:o:p:r:R:aGlLPv?")) >= 0)
399 if (optind == prevoptind + 2 && *optarg ==
'-' ) {
406 global_file_disable = 1;
422 if(strcmp(optarg,
"ascii") == 0)
427 else if(strcmp(optarg,
"binary") == 0)
434 "ERROR: mode parameter must be 'ascii' or 'binary'\n");
441 name = strdup(optarg);
445 tmpl = strdup(optarg);
449 plugins[plugin_cnt++] = strdup(optarg);
453 bpf_filter = strdup(optarg);
465 rotate = atoi(optarg);
469 meta_rotate = atoi(optarg);
473 fprintf(stderr,
"ERROR: Missing option argument for -%c\n", optopt);
480 fprintf(stderr,
"corsaro version %d.%d.%d\n", CORSARO_MAJOR_VERSION,
481 CORSARO_MID_VERSION, CORSARO_MINOR_VERSION);
502 if(lastopt > argc - 1)
504 fprintf(stderr,
"ERROR: At least one trace file must be specified\n");
509 tracefile_cnt = argc-lastopt;
514 if(tracefile_cnt == 1)
516 traceuri = argv[lastopt];
522 "ERROR: An output file template must be specified using -o\n");
535 if(bpf_filter != NULL)
537 corsaro_log(__func__, corsaro,
"compiling filter: \"%s\"",
539 filter = trace_create_filter(bpf_filter);
545 corsaro_log(__func__, corsaro,
"failed to set trace uri");
551 corsaro_log(__func__, corsaro,
"failed to set monitor name");
575 for(i=0;i<plugin_cnt;i++)
580 if((plugin_arg_ptr = strchr(plugins[i],
' ')) != NULL)
586 *plugin_arg_ptr =
'\0';
592 fprintf(stderr,
"ERROR: Could not enable plugin %s\n",
599 if(logfile_disable != 0)
604 if(global_file_disable != 0)
622 assert(
trace == NULL);
623 #ifdef WITH_PLUGIN_SIXT
624 assert(corsaro_in == NULL);
627 corsaro_log(__func__, corsaro,
"processing %s", argv[i]);
629 #ifdef WITH_PLUGIN_SIXT
653 #ifdef WITH_PLUGIN_SIXT
659 for(i=0;i<plugin_cnt;i++)
661 if(plugins[i] != NULL)
678 for(i=0;i<plugin_cnt;i++)
680 if(plugins[i] != NULL)
Structure representing the start or end of an interval.
static int init_flowtuple(const char *tuplefile)
Prepare for processing a FlowTuple file.
int main(int argc, char *argv[])
Entry point for the Corsaro tool.
void corsaro_in_free_record(corsaro_in_record_t *record)
Free an corsaro record object.
int corsaro_finalize_output(corsaro_t *corsaro)
Write the final interval and free resources allocated by corsaro.
void corsaro_disable_globalfile(corsaro_t *corsaro)
Accessor function to disable the global metadata file.
int corsaro_per_record(corsaro_t *corsaro, corsaro_in_record_type_t type, corsaro_in_record_t *record)
Perform corsaro processing on a given corsaro record.
static void close_flowtuple()
Close a flowtuple input file.
corsaro_in_t * corsaro_alloc_input(const char *corsarouri)
Allocate an corsaro object for reading an corsaro file.
Header file which exports the public libcorsaro API.
int corsaro_get_plugin_names(char ***plugin_names)
Return an array of the names of plugins which are compiled into corsaro.
static int process_corsaro(const char *corsuri)
Process a FlowTuple input file.
Header file dealing with the corsaro logging sub-system.
A reusable opaque structure for corsaro to read an input record into.
void corsaro_free_plugin_names(char **plugin_names, int plugin_cnt)
Free the array of plugin names returned by corsaro_get_plugin_names.
int corsaro_start_output(corsaro_t *corsaro)
Initialize an corsaro object that has already been allocated.
int corsaro_set_trace(corsaro_t *corsaro, libtrace_t *trace)
Accessor function to set the trace pointer.
#define LEGACY_INTERVAL_CNT
The number of intervals in CAIDA's legacy flowtuple files.
Header file which exports corsaro_flowtuple plugin API.
static void clean()
Clean up all state before exit.
static libtrace_packet_t * packet
A pointer to a libtrace packet.
uint16_t number
The interval number (starts at 0)
int corsaro_finalize_input(corsaro_in_t *corsaro)
Close the input file and free resources allocated by corsaro.
Header file for common utility functions.
static void usage(const char *name)
Print usage information to stderr.
void corsaro_set_output_rotation(corsaro_t *corsaro, int intervals)
Accessor function to set the rotation frequency of output files.
int corsaro_flowtuple_probe_file(corsaro_in_t *corsaro, const char *fturi)
Check if an input file is a FlowTuple file.
#define STR(a)
Stringify a macro value.
int corsaro_start_input(corsaro_in_t *corsaro)
Initialize an corsaro input object that has already been allocated.
static void catch_sigint(int sig)
Handles SIGINT gracefully and shuts down.
static corsaro_in_record_t * record
A pointer to a corsaro record.
static libtrace_t * trace
A pointer to a libtrace object.
corsaro_in_record_t * corsaro_in_alloc_record(corsaro_in_t *corsaro)
Allocate a reusable corsaro record object.
#define CORSARO_INTERVAL_DEFAULT
The interval after which we will end an interval.
int corsaro_per_packet(corsaro_t *corsaro, libtrace_packet_t *ltpacket)
Perform corsaro processing on a given libtrace packet.
static void close_trace()
Close a trace file.
uint32_t time
The time this interval started/ended.
void corsaro_set_interval_alignment(corsaro_t *corsaro, corsaro_interval_align_t align)
Accessor function to enable/disable the alignment of the initial interval.
static int process_trace(char *traceuri)
Process a trace file.
int corsaro_set_monitorname(corsaro_t *corsaro, char *name)
Accessor function to set the monitor name.
static int init_trace(char *tracefile)
Prepare a new trace file for reading.
#define HARD_SHUTDOWN
The number of SIGINTs to catch before aborting.
static int promisc
Should a live interface be set to promiscuous mode?
Maximum plugin ID assigned.
corsaro_t * corsaro_alloc_output(char *template, corsaro_file_mode_t mode)
Allocate an corsaro object.
volatile sig_atomic_t corsaro_shutdown
Indicates that Corsaro is waiting to shutdown.
The null type used for wildcard matching.
void * corsaro_in_get_record_data(corsaro_in_record_t *record)
Get a pointer data in a record.
void corsaro_set_interval(corsaro_t *corsaro, unsigned int i)
Accessor function to set the interval length.
static int legacy_intervals
The number of legacy intervals we have processed.
int corsaro_enable_plugin(corsaro_t *corsaro, const char *plugin_name, const char *plugin_args)
Attempt to enable a plugin using the given plugin name.
int corsaro_set_traceuri(corsaro_t *corsaro, char *uri)
Accessor function to set the trace uri string.
void corsaro_log(const char *func, corsaro_t *corsaro, const char *format,...)
Write a formatted string to the logfile associated with an corsaro object.
off_t corsaro_in_read_record(corsaro_in_t *corsaro, corsaro_in_record_type_t *record_type, corsaro_in_record_t *record)
Read the next corsaro record from the given corsaro input file.
void corsaro_set_meta_output_rotation(corsaro_t *corsaro, int intervals)
Accessor function to set the rotation frequency of meta output files.
enum corsaro_in_record_type corsaro_in_record_type_t
Corsaro input record types.
void corsaro_disable_logfile(corsaro_t *corsaro)
Accessor function to disable logging to a file.
static libtrace_filter_t * filter
A pointer to a libtrace BPF filter.