Skip to Content
[CAIDA - Cooperative Association for Internet Data Analysis logo]
The Cooperative Association for Internet Data Analysis
corsaro_plugin.h File Reference

Header file dealing with the corsaro plugin manager. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  corsaro_plugin
 An corsaro packet processing plugin. More...
struct  corsaro_plugin_manager
 Holds the metadata for the plugin manager. More...

Macros

#define CORSARO_PLUGIN_GENERATE_PROTOS(plugin)
 Convenience macro that defines all the function prototypes for the corsaro plugin API.
#define CORSARO_PLUGIN_GENERATE_PTRS(plugin)
 Convenience macro that defines all the function pointers for the corsaro plugin API.
#define CORSARO_PLUGIN_STATE(corsaro, type, id)
 Convenience macro to cast the state pointer in the plugin.
#define CORSARO_PLUGIN_PLUGIN(corsaro, id)   ((corsaro)->plugin_manager->plugins[(id)-1])
 Convenience macro to get this plugin from corsaro.

Typedefs

typedef enum corsaro_plugin_id corsaro_plugin_id_t
 A unique identifier for a plugin, used when writing binary data.
typedef struct corsaro_plugin corsaro_plugin_t
 An corsaro packet processing plugin.
typedef struct
corsaro_plugin_manager 
corsaro_plugin_manager_t
 Holds the metadata for the plugin manager.

Enumerations

enum  corsaro_plugin_id { CORSARO_PLUGIN_ID_PCAP = 1, CORSARO_PLUGIN_ID_FLOWTUPLE = 20, CORSARO_PLUGIN_ID_DOS = 30, CORSARO_PLUGIN_ID_MAX = CORSARO_PLUGIN_ID_DOS }
 A unique identifier for a plugin, used when writing binary data. More...

Functions

corsaro_plugin_manager_tcorsaro_plugin_manager_init ()
 Initialize the plugin manager and all in-use plugins.
int corsaro_plugin_manager_start (corsaro_plugin_manager_t *manager)
 Start the plugin manager.
void corsaro_plugin_manager_free (corsaro_plugin_manager_t *manager)
 Free the plugin manager and all in-use plugins.
corsaro_plugin_tcorsaro_plugin_get_by_id (corsaro_plugin_manager_t *manager, int id)
 Attempt to retrieve a plugin by id.
corsaro_plugin_tcorsaro_plugin_get_by_name (corsaro_plugin_manager_t *manager, const char *name)
 Attempt to retrieve a plugin by name.
corsaro_plugin_tcorsaro_plugin_next (corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin)
 Retrieve the next plugin in the list.
void corsaro_plugin_register_state (corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin, void *state)
 Register the state for a plugin.
void corsaro_plugin_free_state (corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin)
 Free 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 (corsaro_plugin_manager_t *manager, int id)
 Get the name of a plugin given it's ID number.
int corsaro_plugin_is_enabled (corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin)
 Determine whether this plugin is enabled for use.
int corsaro_plugin_enable_plugin (corsaro_plugin_manager_t *manager, const char *plugin_name)
 Attempt to enable a plugin by its name.

Detailed Description

Header file dealing with the corsaro plugin manager.

Author:
Alistair King

Definition in file corsaro_plugin.h.


Macro Definition Documentation

#define CORSARO_PLUGIN_GENERATE_PROTOS (   plugin)
Value:
corsaro_plugin_t * plugin##_alloc(); \
int plugin##_probe_filename(const char *fname); \
int plugin##_probe_magic(struct corsaro_in * corsaro, corsaro_file_in_t *file); \
int plugin##_init_input(struct corsaro_in *corsaro); \
int plugin##_init_output(struct corsaro *corsaro); \
int plugin##_close_input(struct corsaro_in *corsaro); \
int plugin##_close_output(struct corsaro *corsaro); \
off_t plugin##_read_record(struct corsaro_in *corsaro, \
enum corsaro_in_record_type *record_type, \
struct corsaro_in_record *record); \
off_t plugin##_read_global_data_record(struct corsaro_in *corsaro, \
enum corsaro_in_record_type *record_type, \
struct corsaro_in_record *record); \
int plugin##_start_interval(struct corsaro *corsaro, \
struct corsaro_interval *int_start); \
int plugin##_end_interval(struct corsaro *corsaro, \
struct corsaro_interval *int_end); \
int plugin##_process_packet(struct corsaro *corsaro, \
struct corsaro_packet *packet);

Convenience macro that defines all the function prototypes for the corsaro plugin API.

Todo:
split this into corsaro-out and corsaro-in macros

Definition at line 44 of file corsaro_plugin.h.

#define CORSARO_PLUGIN_GENERATE_PTRS (   plugin)
Value:
plugin##_probe_filename, \
plugin##_probe_magic, \
plugin##_init_input, \
plugin##_init_output, \
plugin##_close_input, \
plugin##_close_output, \
plugin##_read_record, \
plugin##_read_global_data_record, \
plugin##_start_interval, \
plugin##_end_interval, \
plugin##_process_packet

Convenience macro that defines all the function pointers for the corsaro plugin API.

Todo:
split this into corsaro-out and corsaro-in macros

Definition at line 70 of file corsaro_plugin.h.

#define CORSARO_PLUGIN_PLUGIN (   corsaro,
  id 
)    ((corsaro)->plugin_manager->plugins[(id)-1])

Convenience macro to get this plugin from corsaro.

Plugins should use extend this macro to provide access to themself

Definition at line 95 of file corsaro_plugin.h.

#define CORSARO_PLUGIN_STATE (   corsaro,
  type,
  id 
)
Value:
((struct corsaro_##type##_state_t*) \
((corsaro)->plugin_manager->plugins_state[(id)-1]))

Convenience macro to cast the state pointer in the plugin.

Plugins should use extend this macro to provide access to their state

Definition at line 87 of file corsaro_plugin.h.


Typedef Documentation

A unique identifier for a plugin, used when writing binary data.

Note:
this identifier does not affect the order in which plugins are passed packets. Plugin precedence is determined either by the order of the ED_WITH_PLUGIN macros in configure.ac, or by the order of the plugins that have been explicitly enabled using corsaro_enable_plugin

Holds the metadata for the plugin manager.

This allows both corsaro_t and corsaro_in_t objects to use the plugin infrastructure without needing to pass references to themselves

An corsaro packet processing plugin.


Enumeration Type Documentation

A unique identifier for a plugin, used when writing binary data.

Note:
this identifier does not affect the order in which plugins are passed packets. Plugin precedence is determined either by the order of the ED_WITH_PLUGIN macros in configure.ac, or by the order of the plugins that have been explicitly enabled using corsaro_enable_plugin
Enumerator:
CORSARO_PLUGIN_ID_PCAP 

Pass-through PCAP plugin.

Allows Corsaro to be used to capture PCAP files from a live interface. This should always be the highest priority plugin

CORSARO_PLUGIN_ID_FLOWTUPLE 

FlowTuple plugin.

CORSARO_PLUGIN_ID_DOS 

RS DoS plugin.

CORSARO_PLUGIN_ID_MAX 

Maximum plugin ID assigned.

Definition at line 106 of file corsaro_plugin.h.


Function Documentation

int corsaro_plugin_enable_plugin ( corsaro_plugin_manager_t manager,
const char *  plugin_name 
)

Attempt to enable a plugin by its name.

Parameters:
managerThe plugin manager associated with the state
plugin_nameThe name of the plugin to enable
Returns:
0 if the plugin was successfully enabled, -1 otherwise

See corsaro_enable_plugin for more details.

Definition at line 445 of file corsaro_plugin.c.

References corsaro_plugin::id, corsaro_plugin_manager::plugins_enabled, and corsaro_plugin_manager::plugins_enabled_cnt.

void corsaro_plugin_free_state ( corsaro_plugin_manager_t manager,
corsaro_plugin_t plugin 
)

Free the state for a plugin.

Parameters:
managerThe plugin manager associated with the state
pluginThe plugin to free state for

Definition at line 389 of file corsaro_plugin.c.

References corsaro_plugin::id, and corsaro_plugin_manager::plugins_state.

corsaro_plugin_t* corsaro_plugin_get_by_id ( corsaro_plugin_manager_t manager,
int  id 
)

Attempt to retrieve a plugin by id.

Parameters:
managerThe plugin manager to search with
idThe id of the plugin to get
Returns:
the plugin corresponding to the id if found, NULL otherwise

Definition at line 332 of file corsaro_plugin.c.

References CORSARO_PLUGIN_ID_MAX, and corsaro_plugin_manager::plugins.

corsaro_plugin_t* corsaro_plugin_get_by_name ( corsaro_plugin_manager_t manager,
const char *  name 
)

Attempt to retrieve a plugin by name.

Parameters:
managerThe plugin manager to search with
nameThe name of the plugin to get
Returns:
the plugin corresponding to the name if found, NULL otherwise

Definition at line 344 of file corsaro_plugin.c.

References corsaro_plugin::name.

const char* corsaro_plugin_get_name ( corsaro_plugin_manager_t manager,
int  id 
)

Get the name of a plugin given it's ID number.

Parameters:
managerThe plugin manager associated with the state
idThe plugin id to retrieve the name for
Returns:
the name of the plugin as a string, NULL if no plugin matches the given id

Definition at line 411 of file corsaro_plugin.c.

References corsaro_plugin::name.

int corsaro_plugin_is_enabled ( corsaro_plugin_manager_t manager,
corsaro_plugin_t plugin 
)

Determine whether this plugin is enabled for use.

Parameters:
managerThe plugin manager associated with the state
pluginThe plugin to check the status of
Returns:
1 if the plugin is enabled, 0 if it is disabled

A plugin is enabled either explicitly by the corsaro_enable_plugin() function, or implicitly because all plugins are enabled.

Definition at line 422 of file corsaro_plugin.c.

References corsaro_plugin::id, corsaro_plugin_manager::plugins_enabled, and corsaro_plugin_manager::plugins_enabled_cnt.

void corsaro_plugin_manager_free ( corsaro_plugin_manager_t manager)

Free the plugin manager and all in-use plugins.

Parameters:
managerThe plugin manager to free
Note:
the plugins registered with the manager MUST have already been closed (either plugin->close_output or plugin->close_input). Also, the logfile is NOT closed, as it is assumed to be shared with another object (corsaro_t or corsaro_in_t).

Definition at line 290 of file corsaro_plugin.c.

References CORSARO_PLUGIN_ID_MAX, corsaro_plugin_manager::first_plugin, corsaro_plugin_manager::plugins, corsaro_plugin_manager::plugins_cnt, and corsaro_plugin_manager::plugins_state.

corsaro_plugin_manager_t* corsaro_plugin_manager_init ( )

Initialize the plugin manager and all in-use plugins.

Returns:
A pointer to the plugin manager state or NULL if an error occurs
int corsaro_plugin_manager_start ( corsaro_plugin_manager_t manager)
corsaro_plugin_t* corsaro_plugin_next ( corsaro_plugin_manager_t manager,
corsaro_plugin_t plugin 
)

Retrieve the next plugin in the list.

Parameters:
managerThe plugin manager to get the next plugin for
pluginThe current plugin
Returns:
the plugin which follows the current plugin, NULL if the end of the plugin list has been reached. If plugin is NULL, the first plugin will be returned.

Definition at line 359 of file corsaro_plugin.c.

References corsaro_plugin_manager::first_plugin, corsaro_plugin::next, corsaro_plugin_manager::plugins, and corsaro_plugin_manager::plugins_cnt.

int corsaro_plugin_probe_filename ( const char *  fname,
corsaro_plugin_t plugin 
)

Check a filename to see if it contains a plugin's name.

Parameters:
fnameThe file name to check
pluginThe plugin to check for
Returns:
1 if the name matches the plugin, 0 otherwise

Definition at line 399 of file corsaro_plugin.c.

References corsaro_plugin::name.

void corsaro_plugin_register_state ( corsaro_plugin_manager_t manager,
corsaro_plugin_t plugin,
void *  state 
)

Register the state for a plugin.

Parameters:
managerThe plugin manager to register state with
pluginThe plugin to register state for
stateA pointer to the state object to register

Definition at line 378 of file corsaro_plugin.c.

References corsaro_plugin::id, and corsaro_plugin_manager::plugins_state.