Skip to content

Commit 9c5d414

Browse files
author
Pavel Siska
committed
ipfixprobe: register process plugin ID at runtime
1 parent 8af188c commit 9c5d414

File tree

56 files changed

+263
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+263
-339
lines changed

include/ipfixprobe/processPlugin.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ namespace ipxp {
4141
*/
4242
class IPXP_API ProcessPlugin : public Plugin {
4343
public:
44-
ProcessPlugin() {}
44+
ProcessPlugin(int pluginID)
45+
: m_pluginID(pluginID)
46+
{
47+
}
48+
4549
virtual ~ProcessPlugin() {}
4650
virtual ProcessPlugin* copy() = 0;
4751

@@ -102,6 +106,9 @@ class IPXP_API ProcessPlugin : public Plugin {
102106
* \param [in,out] rec Reference to flow record.
103107
*/
104108
virtual void pre_export(Flow& rec) { (void) rec; }
109+
110+
protected:
111+
int m_pluginID;
105112
};
106113

107114
/**
@@ -167,6 +174,6 @@ class IPXP_API PluginFactory;
167174
*
168175
* Provides a factory for creating ProcessPlugin instances using a string-based constructor.
169176
*/
170-
using ProcessPluginFactory = PluginFactory<ProcessPlugin, const std::string&>;
177+
using ProcessPluginFactory = PluginFactory<ProcessPlugin, const std::string&, int>;
171178

172179
} // namespace ipxp

src/core/ipfixprobe.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ bool process_plugin_args(ipxp_conf_t& conf, IpfixprobeOptParser& parser)
297297

298298
try {
299299
auto& processPluginFactory = ProcessPluginFactory::getInstance();
300-
processPlugin = processPluginFactory.createShared(process_name, process_params);
300+
const int pluginID = ProcessPluginIDGenerator::instance().generatePluginID();
301+
processPlugin
302+
= processPluginFactory.createShared(process_name, process_params, pluginID);
301303
if (processPlugin == nullptr) {
302304
throw IPXPError("invalid process plugin " + process_name);
303305
}

src/plugins/process/basicplus/src/basicplus.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
namespace ipxp {
2121

22-
int RecordExtBASICPLUS::REGISTERED_ID = ProcessPluginIDGenerator::instance().generatePluginID();
23-
2422
static const PluginManifest basicplusPluginManifest = {
2523
.name = "basicplus",
2624
.description = "Basicplus process plugin for parsing basicplus traffic.",
@@ -29,7 +27,8 @@ static const PluginManifest basicplusPluginManifest = {
2927
.usage = nullptr,
3028
};
3129

32-
BASICPLUSPlugin::BASICPLUSPlugin(const std::string& params)
30+
BASICPLUSPlugin::BASICPLUSPlugin(const std::string& params, int pluginID)
31+
: ProcessPlugin(pluginID)
3332
{
3433
(void) params;
3534
}
@@ -53,7 +52,7 @@ ProcessPlugin* BASICPLUSPlugin::copy()
5352

5453
int BASICPLUSPlugin::post_create(Flow& rec, const Packet& pkt)
5554
{
56-
RecordExtBASICPLUS* p = new RecordExtBASICPLUS();
55+
RecordExtBASICPLUS* p = new RecordExtBASICPLUS(m_pluginID);
5756

5857
rec.add_extension(p);
5958

@@ -71,8 +70,7 @@ int BASICPLUSPlugin::post_create(Flow& rec, const Packet& pkt)
7170

7271
int BASICPLUSPlugin::pre_update(Flow& rec, Packet& pkt)
7372
{
74-
RecordExtBASICPLUS* p
75-
= (RecordExtBASICPLUS*) rec.get_extension(RecordExtBASICPLUS::REGISTERED_ID);
73+
RecordExtBASICPLUS* p = (RecordExtBASICPLUS*) rec.get_extension(m_pluginID);
7674
uint8_t dir = pkt.source_pkt ? 0 : 1;
7775

7876
if (p->ip_ttl[dir] < pkt.ip_ttl) {

src/plugins/process/basicplus/src/basicplus.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ UR_FIELDS(
4848
* \brief Flow record extension header for storing parsed BASICPLUS packets.
4949
*/
5050
struct RecordExtBASICPLUS : public RecordExt {
51-
static int REGISTERED_ID;
52-
5351
uint8_t ip_ttl[2];
5452
uint8_t ip_flg[2];
5553
uint16_t tcp_win[2];
@@ -59,8 +57,8 @@ struct RecordExtBASICPLUS : public RecordExt {
5957

6058
bool dst_filled;
6159

62-
RecordExtBASICPLUS()
63-
: RecordExt(REGISTERED_ID)
60+
RecordExtBASICPLUS(int pluginID)
61+
: RecordExt(pluginID)
6462
{
6563
ip_ttl[0] = 0;
6664
ip_ttl[1] = 0;
@@ -140,7 +138,7 @@ struct RecordExtBASICPLUS : public RecordExt {
140138
*/
141139
class BASICPLUSPlugin : public ProcessPlugin {
142140
public:
143-
BASICPLUSPlugin(const std::string& params);
141+
BASICPLUSPlugin(const std::string& params, int pluginID);
144142
~BASICPLUSPlugin();
145143
void init(const char* params);
146144
void close();
@@ -151,7 +149,7 @@ class BASICPLUSPlugin : public ProcessPlugin {
151149
"Extend basic fields with TTL, TCP window, options, MSS and SYN size");
152150
}
153151
std::string get_name() const { return "basicplus"; }
154-
RecordExt* get_ext() const { return new RecordExtBASICPLUS(); }
152+
RecordExt* get_ext() const { return new RecordExtBASICPLUS(m_pluginID); }
155153
ProcessPlugin* copy();
156154

157155
int post_create(Flow& rec, const Packet& pkt);

src/plugins/process/bstats/src/bstats.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
namespace ipxp {
2121

22-
int RecordExtBSTATS::REGISTERED_ID = ProcessPluginIDGenerator::instance().generatePluginID();
23-
2422
static const PluginManifest bstatsPluginManifest = {
2523
.name = "bstats",
2624
.description = "Bstats process plugin for computing packet bursts stats.",
@@ -32,7 +30,8 @@ static const PluginManifest bstatsPluginManifest = {
3230
const struct timeval BSTATSPlugin::min_packet_in_burst
3331
= {MAXIMAL_INTERPKT_TIME / 1000, (MAXIMAL_INTERPKT_TIME % 1000) * 1000};
3432

35-
BSTATSPlugin::BSTATSPlugin(const std::string& params)
33+
BSTATSPlugin::BSTATSPlugin(const std::string& params, int pluginID)
34+
: ProcessPlugin(pluginID)
3635
{
3736
init(params.c_str());
3837
}
@@ -132,7 +131,7 @@ void BSTATSPlugin::update_record(RecordExtBSTATS* bstats_record, const Packet& p
132131

133132
int BSTATSPlugin::post_create(Flow& rec, const Packet& pkt)
134133
{
135-
RecordExtBSTATS* bstats_record = new RecordExtBSTATS();
134+
RecordExtBSTATS* bstats_record = new RecordExtBSTATS(m_pluginID);
136135

137136
rec.add_extension(bstats_record);
138137
update_record(bstats_record, pkt);
@@ -141,8 +140,7 @@ int BSTATSPlugin::post_create(Flow& rec, const Packet& pkt)
141140

142141
int BSTATSPlugin::pre_update(Flow& rec, Packet& pkt)
143142
{
144-
RecordExtBSTATS* bstats_record
145-
= static_cast<RecordExtBSTATS*>(rec.get_extension(RecordExtBSTATS::REGISTERED_ID));
143+
RecordExtBSTATS* bstats_record = static_cast<RecordExtBSTATS*>(rec.get_extension(m_pluginID));
146144

147145
update_record(bstats_record, pkt);
148146
return 0;
@@ -159,12 +157,11 @@ void BSTATSPlugin::pre_export(Flow& rec)
159157
{
160158
uint32_t packets = rec.src_packets + rec.dst_packets;
161159
if (packets <= MINIMAL_PACKETS_IN_BURST) {
162-
rec.remove_extension(RecordExtBSTATS::REGISTERED_ID);
160+
rec.remove_extension(m_pluginID);
163161
return;
164162
}
165163

166-
RecordExtBSTATS* bstats_record
167-
= static_cast<RecordExtBSTATS*>(rec.get_extension(RecordExtBSTATS::REGISTERED_ID));
164+
RecordExtBSTATS* bstats_record = static_cast<RecordExtBSTATS*>(rec.get_extension(m_pluginID));
168165

169166
for (int direction = 0; direction < 2; direction++) {
170167
if (bstats_record->BCOUNT < BSTATS_MAXELENCOUNT

src/plugins/process/bstats/src/bstats.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ struct RecordExtBSTATS : public RecordExt {
6868
DStop = 1057
6969
} eHdrFieldID;
7070

71-
static int REGISTERED_ID;
72-
7371
uint16_t burst_count[2];
7472
uint8_t burst_empty[2];
7573

@@ -78,8 +76,8 @@ struct RecordExtBSTATS : public RecordExt {
7876
struct timeval brst_start[2][BSTATS_MAXELENCOUNT];
7977
struct timeval brst_end[2][BSTATS_MAXELENCOUNT];
8078

81-
RecordExtBSTATS()
82-
: RecordExt(REGISTERED_ID)
79+
RecordExtBSTATS(int pluginID)
80+
: RecordExt(pluginID)
8381
{
8482
memset(burst_count, 0, 2 * sizeof(uint16_t));
8583
memset(burst_empty, 0, 2 * sizeof(uint8_t));
@@ -243,7 +241,7 @@ struct RecordExtBSTATS : public RecordExt {
243241
*/
244242
class BSTATSPlugin : public ProcessPlugin {
245243
public:
246-
BSTATSPlugin(const std::string& params);
244+
BSTATSPlugin(const std::string& params, int pluginID);
247245
~BSTATSPlugin();
248246
void init(const char* params);
249247
void close();
@@ -252,7 +250,7 @@ class BSTATSPlugin : public ProcessPlugin {
252250
return new OptionsParser("bstats", "Compute packet bursts stats");
253251
}
254252
std::string get_name() const { return "bstats"; }
255-
RecordExt* get_ext() const { return new RecordExtBSTATS(); }
253+
RecordExt* get_ext() const { return new RecordExtBSTATS(m_pluginID); }
256254
ProcessPlugin* copy();
257255

258256
int pre_create(Packet& pkt);

src/plugins/process/dns/src/dns.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
namespace ipxp {
2929

30-
int RecordExtDNS::REGISTERED_ID = ProcessPluginIDGenerator::instance().generatePluginID();
31-
3230
static const PluginManifest dnsPluginManifest = {
3331
.name = "dns",
3432
.description = "Dns process plugin for parsing dns traffic.",
@@ -64,8 +62,9 @@ static const PluginManifest dnsPluginManifest = {
6462
*/
6563
#define GET_OFFSET(half1, half2) ((((uint8_t) (half1) & 0x3F) << 8) | (uint8_t) (half2))
6664

67-
DNSPlugin::DNSPlugin(const std::string& params)
68-
: queries(0)
65+
DNSPlugin::DNSPlugin(const std::string& params, int pluginID)
66+
: ProcessPlugin(pluginID)
67+
, queries(0)
6968
, responses(0)
7069
, total(0)
7170
, data_begin(nullptr)
@@ -107,7 +106,7 @@ int DNSPlugin::post_create(Flow& rec, const Packet& pkt)
107106
int DNSPlugin::post_update(Flow& rec, const Packet& pkt)
108107
{
109108
if (pkt.dst_port == 53 || pkt.src_port == 53) {
110-
RecordExt* ext = rec.get_extension(RecordExtDNS::REGISTERED_ID);
109+
RecordExt* ext = rec.get_extension(m_pluginID);
111110
if (ext == nullptr) {
112111
return add_ext_dns(
113112
reinterpret_cast<const char*>(pkt.payload),
@@ -669,7 +668,7 @@ bool DNSPlugin::parse_dns(const char* data, unsigned int payload_len, bool tcp,
669668
*/
670669
int DNSPlugin::add_ext_dns(const char* data, unsigned int payload_len, bool tcp, Flow& rec)
671670
{
672-
RecordExtDNS* ext = new RecordExtDNS();
671+
RecordExtDNS* ext = new RecordExtDNS(m_pluginID);
673672
if (!parse_dns(data, payload_len, tcp, ext)) {
674673
delete ext;
675674
return 0;

src/plugins/process/dns/src/dns.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ UR_FIELDS(
5050
* \brief Flow record extension header for storing parsed DNS packets.
5151
*/
5252
struct RecordExtDNS : public RecordExt {
53-
static int REGISTERED_ID;
54-
5553
uint16_t id;
5654
uint16_t answers;
5755
uint8_t rcode;
@@ -67,8 +65,8 @@ struct RecordExtDNS : public RecordExt {
6765
/**
6866
* \brief Constructor.
6967
*/
70-
RecordExtDNS()
71-
: RecordExt(REGISTERED_ID)
68+
RecordExtDNS(int pluginID)
69+
: RecordExt(pluginID)
7270
{
7371
id = 0;
7472
answers = 0;
@@ -150,13 +148,13 @@ struct RecordExtDNS : public RecordExt {
150148
*/
151149
class DNSPlugin : public ProcessPlugin {
152150
public:
153-
DNSPlugin(const std::string& params);
151+
DNSPlugin(const std::string& params, int pluginID);
154152
~DNSPlugin();
155153
void init(const char* params);
156154
void close();
157155
OptionsParser* get_parser() const { return new OptionsParser("dns", "Parse DNS packets"); }
158156
std::string get_name() const { return "dns"; }
159-
RecordExt* get_ext() const { return new RecordExtDNS(); }
157+
RecordExt* get_ext() const { return new RecordExtDNS(m_pluginID); }
160158
ProcessPlugin* copy();
161159

162160
int post_create(Flow& rec, const Packet& pkt);

src/plugins/process/dnssd/src/dnssd.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
namespace ipxp {
3030

31-
int RecordExtDNSSD::REGISTERED_ID = ProcessPluginIDGenerator::instance().generatePluginID();
32-
3331
static const PluginManifest dnssdPluginManifest = {
3432
.name = "dnssd",
3533
.description = "Dnssd process plugin for parsing dnssd traffic.",
@@ -70,8 +68,9 @@ static const PluginManifest dnssdPluginManifest = {
7068
*/
7169
#define GET_OFFSET(half1, half2) ((((uint8_t) (half1) & 0x3F) << 8) | (uint8_t) (half2))
7270

73-
DNSSDPlugin::DNSSDPlugin(const std::string& params)
74-
: txt_all_records(false)
71+
DNSSDPlugin::DNSSDPlugin(const std::string& params, int pluginID)
72+
: ProcessPlugin(pluginID)
73+
, txt_all_records(false)
7574
, queries(0)
7675
, responses(0)
7776
, total(0)
@@ -124,7 +123,7 @@ int DNSSDPlugin::post_create(Flow& rec, const Packet& pkt)
124123
int DNSSDPlugin::post_update(Flow& rec, const Packet& pkt)
125124
{
126125
if (pkt.dst_port == 5353 || pkt.src_port == 5353) {
127-
RecordExt* ext = rec.get_extension(RecordExtDNSSD::REGISTERED_ID);
126+
RecordExt* ext = rec.get_extension(m_pluginID);
128127

129128
if (ext == nullptr) {
130129
return add_ext_dnssd(
@@ -713,7 +712,7 @@ void DNSSDPlugin::filtered_append(
713712
*/
714713
int DNSSDPlugin::add_ext_dnssd(const char* data, unsigned int payload_len, bool tcp, Flow& rec)
715714
{
716-
RecordExtDNSSD* ext = new RecordExtDNSSD();
715+
RecordExtDNSSD* ext = new RecordExtDNSSD(m_pluginID);
717716

718717
if (!parse_dns(data, payload_len, tcp, ext)) {
719718
delete ext;

src/plugins/process/dnssd/src/dnssd.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,14 @@ struct DnsSdRr {
8787
* \brief Flow record extension header for storing parsed DNSSD packets.
8888
*/
8989
struct RecordExtDNSSD : public RecordExt {
90-
static int REGISTERED_ID;
91-
9290
std::list<std::string> queries;
9391
std::list<DnsSdRr> responses;
9492

9593
/**
9694
* \brief Constructor.
9795
*/
98-
RecordExtDNSSD()
99-
: RecordExt(REGISTERED_ID)
96+
RecordExtDNSSD(int pluginID)
97+
: RecordExt(pluginID)
10098
{
10199
}
102100

@@ -242,13 +240,13 @@ struct RecordExtDNSSD : public RecordExt {
242240
*/
243241
class DNSSDPlugin : public ProcessPlugin {
244242
public:
245-
DNSSDPlugin(const std::string& params);
243+
DNSSDPlugin(const std::string& params, int pluginID);
246244
~DNSSDPlugin();
247245
void init(const char* params);
248246
void close();
249247
OptionsParser* get_parser() const { return new DNSSDOptParser(); }
250248
std::string get_name() const { return "dnssd"; }
251-
RecordExt* get_ext() const { return new RecordExtDNSSD(); }
249+
RecordExt* get_ext() const { return new RecordExtDNSSD(m_pluginID); }
252250
ProcessPlugin* copy();
253251

254252
int post_create(Flow& rec, const Packet& pkt);

0 commit comments

Comments
 (0)