33 #include "parse_cmd.h"
41 #ifdef WITH_PLUGIN_PCAP
42 #include "corsaro_pcap.h"
45 #ifdef WITH_PLUGIN_SIXT
49 #ifdef WITH_PLUGIN_DOS
50 #include "corsaro_dos.h"
53 #ifdef WITH_PLUGIN_SMEE
54 #include "corsaro_smee.h"
57 #ifdef WITH_PLUGIN_ANON
58 #include "corsaro_anon.h"
61 #ifdef WITH_PLUGIN_GEODB
62 #include "corsaro_geodb.h"
65 #ifdef WITH_PLUGIN_PFX2AS
66 #include "corsaro_pfx2as.h"
69 #ifdef WITH_PLUGIN_FILTERGEO
70 #include "corsaro_filtergeo.h"
73 #ifdef WITH_PLUGIN_FILTERPFX
74 #include "corsaro_filterpfx.h"
87 #define LOG(manager) (manager->logfile)
91 #define PLUGIN_INIT_ADD(plugin) \
93 tail = add_plugin(manager, tail, plugin##_alloc(), \
103 #ifdef ED_PLUGIN_INIT_ALL_ENABLED
108 assert(plugin != NULL);
109 assert(plugin->
name != NULL);
111 assert(plugin->
magic > 0x010101);
125 assert(plugin->
next == NULL);
130 #ifdef ED_PLUGIN_INIT_ALL_ENABLED
157 "%s plugin failed to initialize", name);
162 corsaro_plugin_verify(plugin);
168 if((plugin->
argv = malloc(
sizeof(
char*) * (plugin->
argc+1))) == NULL)
173 plugin->
argv[0] = strndup(plugin->
name, strlen(plugin->
name));
174 plugin->
argv[1] = NULL;
178 assert(tail->
next == NULL);
195 "WARNING: No plugins are initialized");
204 "could not malloc plugin array");
212 "could not malloc plugin state array");
215 for(tmp=plugin_list;tmp!=NULL;tmp=tmp->
next)
231 if((plugin->
argv = malloc(
sizeof(
char*) * (plugin->
argc+1))) == NULL)
236 for (i = 0; i < plugin->
argc; i++) {
237 if((plugin->
argv[i] = malloc(strlen(argv[i]) + 1)) == NULL)
241 strncpy(plugin->
argv[i], argv[i], strlen(argv[i]) + 1);
259 #ifdef ED_PLUGIN_INIT_ALL_ENABLED
283 #ifdef ED_PLUGIN_INIT_ALL_ENABLED
284 ED_PLUGIN_INIT_ALL_ENABLED
287 if(populate_plugin_arrays(manager, plugin_cnt, list) != 0)
345 assert(manager != NULL);
352 if(manager->
plugins[i] != NULL)
398 assert(manager != NULL);
410 assert(manager != NULL);
414 if(p->
magic == magic)
428 if(strlen(name) == strlen(p->
name) &&
429 strncasecmp(name, p->
name, strlen(p->
name)) == 0)
441 assert(manager != NULL && manager->
plugins != NULL
458 assert(manager != NULL);
459 assert(plugin != NULL);
460 assert(state != NULL);
468 assert(manager != NULL);
469 assert(plugin != NULL);
477 assert(fname != NULL);
478 assert(plugin != NULL && plugin->
name != NULL);
480 if(strstr(fname, plugin->
name) != NULL)
533 const char *plugin_name,
534 const char *plugin_args)
538 char *local_args = NULL;
539 char *process_argv[MAXOPTS];
540 int process_argc = 0;
542 assert(manager != NULL);
548 "No plugin found with the name '%s'", plugin_name);
550 "Is corsaro compiled with all necessary plugins?");
554 corsaro_log(__func__, NULL,
"enabling %s", plugin_name);
559 if(plugin_args != NULL && strlen(plugin_args) > 0)
562 local_args = strdup(plugin_args);
563 parse_cmd(local_args, &process_argc, process_argv, MAXOPTS, plugin_name);
568 assert(plugin->
argv != NULL && plugin->
argc == 1);
571 free(plugin->
argv[0]);
575 if(copy_argv(plugin, process_argc, process_argv) != 0)
577 if(local_args != NULL)
585 if(local_args != NULL)
608 "could not extend the enabled plugins array");
int corsaro_plugin_is_enabled(corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin)
Determine whether this plugin is enabled for use.
const char * name
The name of this plugin used in the ascii output and eventually to allow plugins to be enabled and di...
Header file dealing with the corsaro plugin manager.
Header file dealing with the corsaro logging sub-system.
An opaque structure defining an corsaro output file.
int(* close_input)(struct corsaro_in *corsaro)
Concludes an input file and cleans up the plugin data.
char ** argv
Array of plugin arguments This is populated by the plugin manager in corsaro_plugin_enable_plugin.
int(* close_output)(struct corsaro *corsaro)
Concludes an output file and cleans up the plugin data.
int corsaro_plugin_enable_plugin(corsaro_plugin_manager_t *manager, const char *plugin_name, const char *plugin_args)
Attempt to enable a plugin by its name.
corsaro_plugin_t * corsaro_plugin_next(corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin)
Retrieve the next plugin in the list.
uint16_t plugins_cnt
The number of active plugins.
Header file which exports corsaro_flowtuple plugin API.
void corsaro_plugin_free_state(corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin)
Free the state for a plugin.
corsaro_plugin_t * corsaro_plugin_get_by_magic(corsaro_plugin_manager_t *manager, uint32_t id)
Attempt to retrieve a plugin by magic number (not by using magic)
void ** plugins_state
A pointer to the array of plugin states.
uint16_t * plugins_enabled
An array of plugin ids that have been enabled by the user.
Header file for common utility functions.
void corsaro_plugin_manager_free(corsaro_plugin_manager_t *manager)
Free the plugin manager and all in-use plugins.
Holds the metadata for the plugin manager.
int corsaro_plugin_manager_start(corsaro_plugin_manager_t *manager)
Start the plugin manager.
const char * corsaro_plugin_get_name_by_id(corsaro_plugin_manager_t *manager, int id)
Get the name of a plugin given it's ID number.
void corsaro_plugin_register_state(corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin, void *state)
Register the state for a plugin.
int corsaro_plugin_probe_filename(const char *fname, corsaro_plugin_t *plugin)
Check a filename to see if it contains a plugin's name.
const char * corsaro_plugin_get_name_by_magic(corsaro_plugin_manager_t *manager, uint32_t magic)
Get the name of a plugin given it's magic number.
void * malloc_zero(const size_t size)
Allocate memory and set it to zero.
int(* init_output)(struct corsaro *corsaro)
Initialises an output file using the plugin.
int argc
Count of arguments in argv.
corsaro_plugin_manager_t * corsaro_plugin_manager_init()
Initialize the plugin manager and all in-use plugins.
int(* probe_filename)(const char *fname)
Given a filename, return if this is the most likely plugin.
int(* start_interval)(struct corsaro *corsaro, struct corsaro_interval *int_start)
Starts a new interval.
const corsaro_plugin_id_t id
The corsaro plugin id for this plugin.
corsaro_plugin_t * corsaro_plugin_get_by_id(corsaro_plugin_manager_t *manager, int id)
Attempt to retrieve a plugin by id.
struct corsaro_plugin * next
Next pointer, should always be NULL - used by the plugin manager.
corsaro_plugin_t * corsaro_plugin_get_by_name(corsaro_plugin_manager_t *manager, const char *name)
Attempt to retrieve a plugin by name.
void corsaro_log_file(const char *func, corsaro_file_t *logfile, const char *format,...)
Write a formatted string to a generic log file.
int(* end_interval)(struct corsaro *corsaro, struct corsaro_interval *int_end)
Ends an interval.
corsaro_plugin_t ** plugins
A pointer to the array of plugins in use.
int(* process_packet)(struct corsaro *corsaro, struct corsaro_packet *packet)
Process a packet.
uint16_t plugins_enabled_cnt
The number of plugin ids in the plugins_enabled array.
Maximum plugin ID assigned.
off_t(* read_global_data_record)(struct corsaro_in *corsaro, enum corsaro_in_record_type *record_type, struct corsaro_in_record *record)
Reads a plugin global data block from an input file.
int(* init_input)(struct corsaro_in *corsaro)
Initialises an input file using the plugin.
void corsaro_log(const char *func, corsaro_t *corsaro, const char *format,...)
Write a formatted string to the logfile associated with an corsaro object.
const uint32_t magic
The magic number for this plugin's data.
corsaro_file_t * logfile
A pointer to the logfile to use.
corsaro_plugin_t * first_plugin
A pointer to the first plugin in the list.
An corsaro packet processing plugin.
int(* probe_magic)(struct corsaro_in *corsaro, corsaro_file_in_t *file)
Given a file, looks at next 4 bytes to determine if this is the right plugin.
off_t(* read_record)(struct corsaro_in *corsaro, enum corsaro_in_record_type *record_type, struct corsaro_in_record *record)
Reads the next block of plugin data from an input file.
Header file dealing with the internal corsaro functions.