40 #include "corsaro_libanon.h"
44 #ifdef WITH_PLUGIN_SIXT
48 #include "corsaro_anon.h"
59 #define CORSARO_ANON_MAGIC 0x414E4F4E
62 #define PLUGIN_NAME "anon"
65 #define ANON_ENC_TYPE CORSARO_ANON_ENC_CRYPTOPAN
68 #define ENC_TYPE_CRYPTOPAN "cryptopan"
71 #define ENC_TYPE_PREFIX "prefix"
84 #ifdef WITH_PLUGIN_SIXT
85 CORSARO_PLUGIN_GENERATE_PTRS_FT(corsaro_anon),
93 struct corsaro_anon_state_t {
95 corsaro_anon_enc_type_t encryption_type;
101 int encrypt_destination;
105 #define STATE(corsaro) \
106 (CORSARO_PLUGIN_STATE(corsaro, anon, CORSARO_PLUGIN_ID_ANON))
109 #define PLUGIN(corsaro) \
110 (CORSARO_PLUGIN_PLUGIN(corsaro, CORSARO_PLUGIN_ID_ANON))
116 "plugin usage: %s [-sd] [-t encryption_type] encryption_key[prefix]\n"
117 " -d enable destination address encryption\n"
118 " -s enable source address encryption\n"
119 " -t encryption type (default: %s)\n"
120 " must be either '%s', or '%s'\n",
131 struct corsaro_anon_state_t *state =
STATE(corsaro);
137 while((opt = getopt(plugin->
argc, plugin->
argv,
":dst:?")) >= 0)
142 state->encrypt_destination = 1;
146 state->encrypt_source = 1;
152 state->encryption_type = CORSARO_ANON_ENC_CRYPTOPAN;
156 state->encryption_type = CORSARO_ANON_ENC_PREFIX_SUBSTITUTION;
160 fprintf(stderr,
"ERROR: invalid encryption type (%s)\n",
176 if(optind != (plugin->
argc - 1))
178 fprintf(stderr,
"ERROR: missing encryption key\n");
183 state->encryption_key = plugin->
argv[optind];
185 if(state->encrypt_source == 0 && state->encrypt_destination == 0)
188 "WARNING: anon plugin is encrypting nothing\n");
219 struct corsaro_anon_state_t *state;
222 assert(plugin != NULL);
224 if((state =
malloc_zero(
sizeof(
struct corsaro_anon_state_t))) == NULL)
227 "could not malloc corsaro_anon_state_t");
233 state->encryption_type = CORSARO_ANON_ENC_CRYPTOPAN;
243 assert(state->encryption_key != NULL);
245 corsaro_anon_init(state->encryption_type, state->encryption_key);
311 struct corsaro_anon_state_t *state =
STATE(corsaro);
312 libtrace_ip_t *iphdr = trace_get_ip(
LT_PKT(packet));
314 if(iphdr != NULL && (state->encrypt_source || state->encrypt_destination))
316 corsaro_anon_ip_header(iphdr, state->encrypt_source,
317 state->encrypt_destination);
323 #ifdef WITH_PLUGIN_SIXT
326 corsaro_flowtuple_t *flowtuple,
332 uint32_t src_ip_anon = corsaro_anon_ip(ntohl(src_ip));
333 uint32_t dst_ip_anon = corsaro_anon_ip(ntohl(dst_ip));
335 flowtuple->src_ip = htonl(src_ip_anon);
342 int corsaro_anon_process_flowtuple_class_start(
corsaro_t *corsaro,
343 corsaro_flowtuple_class_start_t *
class)
350 int corsaro_anon_process_flowtuple_class_end(
corsaro_t *corsaro,
351 corsaro_flowtuple_class_end_t *
class)
Structure representing the start or end of an interval.
An opaque structure defining an corsaro input file.
Header file dealing with the corsaro plugin manager.
Header file dealing with the corsaro logging sub-system.
int corsaro_anon_close_input(corsaro_in_t *corsaro)
Implements the close_input function of the plugin API.
#define CORSARO_FLOWTUPLE_IP_TO_SIXT(n32, flowtuple)
Convert a 32bit network order IP address into the 3 byte flowtuple format.
int corsaro_anon_init_output(corsaro_t *corsaro)
Implements the init_output function of the plugin API.
static void usage(corsaro_plugin_t *plugin)
Print usage information to stderr.
off_t corsaro_anon_read_record(struct corsaro_in *corsaro, corsaro_in_record_type_t *record_type, corsaro_in_record_t *record)
Implements the read_record function of the plugin API.
A reusable opaque structure for corsaro to read an input record into.
char ** argv
Array of plugin arguments This is populated by the plugin manager in corsaro_plugin_enable_plugin.
uint32_t corsaro_flowtuple_get_destination_ip(corsaro_flowtuple_t *flowtuple)
Convenience function to get the destination IP address from a FlowTuple.
#define LT_PKT(corsaro_packet)
Convenience macro to get to the libtrace packet inside an corsaro packet.
static int parse_args(corsaro_t *corsaro)
Parse the arguments given to the plugin.
#define STATE(corsaro)
Extends the generic plugin state convenience macro in corsaro_plugin.h.
#define ANON_DEST
Anonymize the Destination IP by default?
int corsaro_anon_end_interval(corsaro_t *corsaro, corsaro_interval_t *int_end)
Implements the end_interval function of the plugin API.
Header file which exports corsaro_flowtuple plugin API.
static libtrace_packet_t * packet
A pointer to a libtrace packet.
Header file for common utility functions.
A lightweight wrapper around a libtrace packet.
corsaro_plugin_manager_t * plugin_manager
A pointer to the corsaro plugin manager state.
#define CORSARO_PLUGIN_GENERATE_PTRS(plugin)
Convenience macro that defines all the function pointers for the corsaro plugin API.
corsaro_in_record_type
Corsaro input record types.
void corsaro_plugin_register_state(corsaro_plugin_manager_t *manager, corsaro_plugin_t *plugin, void *state)
Register the state for a plugin.
uint32_t corsaro_flowtuple_get_source_ip(corsaro_flowtuple_t *flowtuple)
Convenience function to get the source IP address from a FlowTuple.
#define CORSARO_PLUGIN_GENERATE_TAIL
Convenience macro that defines all the 'remaining' blank fields in a corsaro plugin object...
void * malloc_zero(const size_t size)
Allocate memory and set it to zero.
int corsaro_anon_init_input(corsaro_in_t *corsaro)
Implements the init_input function of the plugin API.
static corsaro_in_record_t * record
A pointer to a corsaro record.
int corsaro_anon_close_output(corsaro_t *corsaro)
Implements the close_output function of the plugin API.
int argc
Count of arguments in argv.
int corsaro_anon_start_interval(corsaro_t *corsaro, corsaro_interval_t *int_start)
Implements the start_interval function of the plugin API.
static corsaro_plugin_t corsaro_anon_plugin
Common plugin information across all instances.
off_t corsaro_anon_read_global_data_record(struct corsaro_in *corsaro, enum corsaro_in_record_type *record_type, struct corsaro_in_record *record)
Implements the read_global_data_record function of the plugin API.
IP address anonymization plugin.
#define ENC_TYPE_CRYPTOPAN
The configuration string for the CORSARO_ANON_ENC_CRYPTOPAN type.
#define CORSARO_ANON_MAGIC
The magic number for this plugin - "ANON".
int corsaro_anon_process_packet(corsaro_t *corsaro, corsaro_packet_t *packet)
Implements the process_packet function of the plugin API.
corsaro_plugin_t * corsaro_anon_alloc(corsaro_t *corsaro)
Implements the alloc function of the plugin API.
#define PLUGIN(corsaro)
Extends the generic plugin plugin convenience macro in corsaro_plugin.h.
int corsaro_anon_probe_magic(corsaro_in_t *corsaro, corsaro_file_in_t *file)
Implements the probe_magic function of the plugin API.
Corsaro state for a packet.
#define PLUGIN_NAME
The name of this plugin.
int corsaro_anon_probe_filename(const char *fname)
Implements the probe_filename function of the plugin API.
void corsaro_log(const char *func, corsaro_t *corsaro, const char *format,...)
Write a formatted string to the logfile associated with an corsaro object.
#define ANON_SOURCE
Anonymize the Source IP by default?
enum corsaro_in_record_type corsaro_in_record_type_t
Corsaro input record types.
An corsaro packet processing plugin.
#define ENC_TYPE_PREFIX
The configuration string for the CORSARO_ANON_ENC_PREFIX type.
Header file dealing with the internal corsaro functions.