Skip to Content
[CAIDA - Center for Applied Internet Data Analysis logo]
The Center for Applied Internet Data Analysis
corsaro_plugin.h
Go to the documentation of this file.
1 /*
2  * corsaro
3  *
4  * Alistair King, CAIDA, UC San Diego
5  * corsaro-info@caida.org
6  *
7  * Copyright (C) 2012 The Regents of the University of California.
8  *
9  * This file is part of corsaro.
10  *
11  * corsaro is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * corsaro is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with corsaro. If not, see <http://www.gnu.org/licenses/>.
23  *
24  */
25 
26 #ifndef __CORSARO_PLUGIN_H
27 #define __CORSARO_PLUGIN_H
28 
29 #include "corsaro_int.h"
30 
44 #define CORSARO_PLUGIN_GENERATE_PROTOS(plugin) \
45  corsaro_plugin_t * plugin##_alloc(); \
46  int plugin##_probe_filename(const char *fname); \
47  int plugin##_probe_magic(struct corsaro_in * corsaro, corsaro_file_in_t *file); \
48  int plugin##_init_input(struct corsaro_in *corsaro); \
49  int plugin##_init_output(struct corsaro *corsaro); \
50  int plugin##_close_input(struct corsaro_in *corsaro); \
51  int plugin##_close_output(struct corsaro *corsaro); \
52  off_t plugin##_read_record(struct corsaro_in *corsaro, \
53  enum corsaro_in_record_type *record_type, \
54  struct corsaro_in_record *record); \
55  off_t plugin##_read_global_data_record(struct corsaro_in *corsaro, \
56  enum corsaro_in_record_type *record_type, \
57  struct corsaro_in_record *record); \
58  int plugin##_start_interval(struct corsaro *corsaro, \
59  struct corsaro_interval *int_start); \
60  int plugin##_end_interval(struct corsaro *corsaro, \
61  struct corsaro_interval *int_end); \
62  int plugin##_process_packet(struct corsaro *corsaro, \
63  struct corsaro_packet *packet);
64 
65 #ifdef WITH_PLUGIN_SIXT
66 #define CORSARO_PLUGIN_GENERATE_FT_PROTO(plugin) \
67  int plugin##_process_flowtuple(struct corsaro *corsaro, \
68  corsaro_flowtuple_t *flowtuple, \
69  struct corsaro_packet_state *state); \
70  int plugin##_process_flowtuple_class_start(struct corsaro *corsaro, \
71  corsaro_flowtuple_class_start_t *class); \
72  int plugin##_process_flowtuple_class_end(struct corsaro *corsaro, \
73  corsaro_flowtuple_class_end_t *class);
74 #endif
75 
84 #ifdef WITH_PLUGIN_SIXT
85 #define CORSARO_PLUGIN_GENERATE_PTRS(plugin) \
86  plugin##_probe_filename, \
87  plugin##_probe_magic, \
88  plugin##_init_input, \
89  plugin##_init_output, \
90  plugin##_close_input, \
91  plugin##_close_output, \
92  plugin##_read_record, \
93  plugin##_read_global_data_record, \
94  plugin##_start_interval, \
95  plugin##_end_interval, \
96  plugin##_process_packet, \
97  NULL, \
98  NULL, \
99  NULL
100 
101 #define CORSARO_PLUGIN_GENERATE_PTRS_FT(plugin) \
102  plugin##_probe_filename, \
103  plugin##_probe_magic, \
104  plugin##_init_input, \
105  plugin##_init_output, \
106  plugin##_close_input, \
107  plugin##_close_output, \
108  plugin##_read_record, \
109  plugin##_read_global_data_record, \
110  plugin##_start_interval, \
111  plugin##_end_interval, \
112  plugin##_process_packet, \
113  plugin##_process_flowtuple, \
114  plugin##_process_flowtuple_class_start, \
115  plugin##_process_flowtuple_class_end
116 #else
117 #define CORSARO_PLUGIN_GENERATE_PTRS(plugin) \
118  plugin##_probe_filename, \
119  plugin##_probe_magic, \
120  plugin##_init_input, \
121  plugin##_init_output, \
122  plugin##_close_input, \
123  plugin##_close_output, \
124  plugin##_read_record, \
125  plugin##_read_global_data_record, \
126  plugin##_start_interval, \
127  plugin##_end_interval, \
128  plugin##_process_packet
129 #endif
130 
138 #define CORSARO_PLUGIN_GENERATE_TAIL \
139  NULL, /* next */ \
140  0, /* argc */ \
141  NULL /* argv */
142 
147 #define CORSARO_PLUGIN_STATE(corsaro, type, id) \
148  ((struct corsaro_##type##_state_t*) \
149  ((corsaro)->plugin_manager->plugins_state[(id)-1]))
150 
155 #define CORSARO_PLUGIN_PLUGIN(corsaro, id) \
156  ((corsaro)->plugin_manager->plugins[(id)-1])
157 
166 typedef enum corsaro_plugin_id
167 {
175 
178 
181 
184 
187 
190 
193 
196 
199 
203 
205 /* All functions should return -1, or NULL on failure */
206 typedef struct corsaro_plugin
207 {
210  const char *name;
211 
212 #if 0
213 
216  /*const char *version;*/
217 #endif
218 
221 
223  const uint32_t magic;
224 
231  int (*probe_filename)(const char *fname);
232 
241 
247  int (*init_input)(struct corsaro_in *corsaro);
248 
254  int (*init_output)(struct corsaro *corsaro);
255 
261  int (*close_input)(struct corsaro_in *corsaro);
262 
268  int (*close_output)(struct corsaro *corsaro);
269 
281  off_t (*read_record)(struct corsaro_in *corsaro,
282  enum corsaro_in_record_type *record_type,
283  struct corsaro_in_record *record);
284 
297  enum corsaro_in_record_type *record_type,
298  struct corsaro_in_record *record);
299 
306  int (*start_interval)(struct corsaro *corsaro, struct corsaro_interval *int_start);
307 
316  int (*end_interval)(struct corsaro *corsaro, struct corsaro_interval *int_end);
317 
331 
332 #ifdef WITH_PLUGIN_SIXT
333 
343  int (*process_flowtuple)(struct corsaro *corsaro,
344  corsaro_flowtuple_t *flowtuple,
345  struct corsaro_packet_state *state);
346 
357  int (*process_flowtuple_class_start)(struct corsaro *corsaro,
358  corsaro_flowtuple_class_start_t *class);
359 
370  int (*process_flowtuple_class_end)(struct corsaro *corsaro,
371  corsaro_flowtuple_class_end_t *class);
372 #endif
373 
377 
379  int argc;
380 
385  char **argv;
386 
388 
395 {
400  uint16_t *plugins_enabled;
401 
404 
407 
410 
413 
415  uint16_t plugins_cnt;
416 
419 
421 
427 
433 
444 
452  int id);
453 
461  uint32_t id);
462 
470  const char *name);
471 
481  corsaro_plugin_t *plugin);
482 
490  corsaro_plugin_t *plugin,
491  void *state);
492 
499  corsaro_plugin_t *plugin);
500 
507 int corsaro_plugin_probe_filename(const char *fname, corsaro_plugin_t *plugin);
508 
517  int id);
518 
527  uint32_t magic);
528 
539  corsaro_plugin_t *plugin);
540 
551  const char *plugin_name,
552  const char *plugin_args);
553 
554 #endif /* __CORSARO_PLUGIN_H */
Structure representing the start or end of an interval.
Definition: corsaro_int.h:156
An opaque structure defining an corsaro input file.
Definition: corsaro_file.h:86
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...
enum corsaro_plugin_id corsaro_plugin_id_t
A unique identifier for a plugin, used when writing binary data.
An opaque structure defining an corsaro output file.
Definition: corsaro_file.h:60
A reusable opaque structure for corsaro to read an input record into.
Definition: corsaro_int.h:350
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.
static libtrace_packet_t * packet
A pointer to a libtrace packet.
Definition: corsaro_main.c:67
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.
A lightweight wrapper around a libtrace packet.
Definition: corsaro_int.h:211
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.
corsaro_in_record_type
Corsaro input record types.
Definition: corsaro.h:97
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.
int(* init_output)(struct corsaro *corsaro)
Initialises an output file using the plugin.
static corsaro_in_record_t * record
A pointer to a corsaro record.
Definition: corsaro_main.c:76
int argc
Count of arguments in argv.
Geolocation Database Lookup Plugin.
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.
static corsaro_t * corsaro
A pointer to the instance of corsaro that we will drive.
Definition: corsaro_main.c:80
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.
CAIDA Prefix2AS lookup plugin.
struct corsaro_plugin corsaro_plugin_t
An corsaro packet processing 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.
static int process_flowtuple(corsaro_flowtuple_t *tuple)
Process a FlowTuple record.
IP address anonymization plugin.
corsaro_plugin_t * corsaro_plugin_get_by_name(corsaro_plugin_manager_t *manager, const char *name)
Attempt to retrieve a plugin by name.
int(* end_interval)(struct corsaro *corsaro, struct corsaro_interval *int_end)
Ends an interval.
Corsaro input state.
Definition: corsaro_int.h:323
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.
Corsaro state for a packet.
Definition: corsaro_int.h:194
uint16_t plugins_enabled_cnt
The number of plugin ids in the plugins_enabled array.
corsaro_plugin_id
A unique identifier for a plugin, used when writing binary data.
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.
Corsaro output state.
Definition: corsaro_int.h:230
int(* init_input)(struct corsaro_in *corsaro)
Initialises an input file using the plugin.
struct corsaro_plugin_manager corsaro_plugin_manager_t
Holds the metadata for the plugin manager.
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.
Pass-through PCAP plugin.
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.
corsaro_file_in_t * file
The corsaro input file to read data from.
Definition: corsaro_int.h:329
Header file dealing with the internal corsaro functions.