-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbgpcorsaro_template.c
180 lines (133 loc) · 4.12 KB
/
bgpcorsaro_template.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "config.h"
#include "bgpcorsaro_int.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "utils.h"
#include "wandio_utils.h"
#include "bgpcorsaro_io.h"
#include "bgpcorsaro_log.h"
#include "bgpcorsaro_plugin.h"
#include "bgpcorsaro_template.h"
/** @file
*
* @brief Bgpcorsaro Elem Counter plugin implementation
*
*/
/** The name of this plugin */
#define PLUGIN_NAME "template"
/** The version of this plugin */
#define PLUGIN_VERSION "0.1"
/** Common plugin information across all instances */
static bgpcorsaro_plugin_t bgpcorsaro_template_plugin = {
PLUGIN_NAME, /* name */
PLUGIN_VERSION, /* version */
BGPCORSARO_PLUGIN_ID_TEMPLATE, /* id */
BGPCORSARO_PLUGIN_GENERATE_PTRS(bgpcorsaro_template), /* func ptrs */
BGPCORSARO_PLUGIN_GENERATE_TAIL,
};
/** Holds the state for an instance of this plugin */
struct bgpcorsaro_template_state_t {
/* useful variables HERE*/
};
/** Extends the generic plugin state convenience macro in bgpcorsaro_plugin.h */
#define STATE(bgpcorsaro) \
(BGPCORSARO_PLUGIN_STATE(bgpcorsaro, template, BGPCORSARO_PLUGIN_ID_TEMPLATE))
/** Extends the generic plugin plugin convenience macro in bgpcorsaro_plugin.h */
#define PLUGIN(bgpcorsaro) \
(BGPCORSARO_PLUGIN_PLUGIN(bgpcorsaro, BGPCORSARO_PLUGIN_ID_TEMPLATE))
/** Print usage information to stderr */
static void usage(bgpcorsaro_plugin_t *plugin)
{
fprintf(stderr,
"plugin usage: %s [options HERE]\n",
plugin->argv[0]);
}
/** Parse the arguments given to the plugin */
static int parse_args(bgpcorsaro_t *bgpcorsaro)
{
bgpcorsaro_plugin_t *plugin = PLUGIN(bgpcorsaro);
int opt;
if(plugin->argc <= 0)
{
return 0;
}
/* NB: remember to reset optind to 1 before using getopt! */
optind = 1;
while((opt = getopt(plugin->argc, plugin->argv, ":h?")) >= 0)
{
switch(opt)
{
case 'h':
case '?':
case ':':
default:
usage(plugin);
return -1;
}
}
return 0;
}
/* == PUBLIC PLUGIN FUNCS BELOW HERE == */
/** Implements the alloc function of the plugin API */
bgpcorsaro_plugin_t *bgpcorsaro_template_alloc(bgpcorsaro_t *bgpcorsaro)
{
return &bgpcorsaro_template_plugin;
}
/** Implements the init_output function of the plugin API */
int bgpcorsaro_template_init_output(bgpcorsaro_t *bgpcorsaro)
{
struct bgpcorsaro_template_state_t *state;
bgpcorsaro_plugin_t *plugin = PLUGIN(bgpcorsaro);
assert(plugin != NULL);
if((state = malloc_zero(sizeof(struct bgpcorsaro_template_state_t))) == NULL)
{
bgpcorsaro_log(__func__, bgpcorsaro,
"could not malloc bgpcorsaro_template_state_t");
goto err;
}
bgpcorsaro_plugin_register_state(bgpcorsaro->plugin_manager, plugin, state);
/* initialize state variables HERE */
/* parse the arguments */
if(parse_args(bgpcorsaro) != 0)
{
return -1;
}
return 0;
err:
bgpcorsaro_template_close_output(bgpcorsaro);
return -1;
}
/** Implements the close_output function of the plugin API */
int bgpcorsaro_template_close_output(bgpcorsaro_t *bgpcorsaro)
{
struct bgpcorsaro_template_state_t *state = STATE(bgpcorsaro);
if(state != NULL)
{
/* deallocate dynamic memory in state HERE */
bgpcorsaro_plugin_free_state(bgpcorsaro->plugin_manager, PLUGIN(bgpcorsaro));
}
return 0;
}
/** Implements the start_interval function of the plugin API */
int bgpcorsaro_template_start_interval(bgpcorsaro_t *bgpcorsaro,
bgpcorsaro_interval_t *int_start)
{
/* interval start operations HERE */
return 0;
}
/** Implements the end_interval function of the plugin API */
int bgpcorsaro_template_end_interval(bgpcorsaro_t *bgpcorsaro,
bgpcorsaro_interval_t *int_end)
{
/* interval end operations HERE */
return 0;
}
/** Implements the process_record function of the plugin API */
int bgpcorsaro_template_process_record(bgpcorsaro_t *bgpcorsaro,
bgpcorsaro_record_t *record)
{
/* interval process record operations HERE */
return 0;
}