Skip to content

Commit 3f0e3d0

Browse files
author
Pavel Siska
committed
ipfixprobe - introduce process MQTT plugin
1 parent 4f9d4b0 commit 3f0e3d0

File tree

5 files changed

+60
-53
lines changed

5 files changed

+60
-53
lines changed

src/plugins/process/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ add_subdirectory(ovpn)
1515
add_subdirectory(wg)
1616
add_subdirectory(ssdp)
1717
add_subdirectory(ssaDetector)
18+
add_subdirectory(mqtt)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
project(ipfixprobe-process-mqtt VERSION 1.0.0 DESCRIPTION "ipfixprobe-process-mqtt plugin")
2+
3+
add_library(ipfixprobe-process-mqtt MODULE
4+
src/mqtt.cpp
5+
src/mqtt.hpp
6+
)
7+
8+
set_target_properties(ipfixprobe-process-mqtt PROPERTIES
9+
CXX_VISIBILITY_PRESET hidden
10+
VISIBILITY_INLINES_HIDDEN YES
11+
)
12+
13+
target_include_directories(ipfixprobe-process-mqtt PRIVATE
14+
${CMAKE_SOURCE_DIR}/include/
15+
)
16+
17+
install(TARGETS ipfixprobe-process-mqtt
18+
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixprobe/process/"
19+
)

src/plugins/process/mqtt/README.md

Whitespace-only changes.
Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
/**
2-
* \file mqtt.hpp
3-
* \brief MQTT plugin for ipfixprobe
4-
* \author Damir Zainullin <[email protected]>
5-
* \date 2024
6-
*/
7-
/*
8-
* Copyright (C) 2023 CESNET
2+
* @file
3+
* @brief Plugin for parsing mqtt traffic.
4+
* @author Damir Zainullin <[email protected]>
5+
* @author Pavel Siska <[email protected]>
6+
* @date 2025
97
*
10-
* LICENSE TERMS
8+
* Copyright (c) 2025 CESNET
119
*
12-
* Redistribution and use in source and binary forms, with or without
13-
* modification, are permitted provided that the following conditions
14-
* are met:
15-
* 1. Redistributions of source code must retain the above copyright
16-
* notice, this list of conditions and the following disclaimer.
17-
* 2. Redistributions in binary form must reproduce the above copyright
18-
* notice, this list of conditions and the following disclaimer in
19-
* the documentation and/or other materials provided with the
20-
* distribution.
21-
* 3. Neither the name of the Company nor the names of its contributors
22-
* may be used to endorse or promote products derived from this
23-
* software without specific prior written permission.
10+
* SPDX-License-Identifier: BSD-3-Clause
2411
*/
2512

2613
#include "mqtt.hpp"
2714

2815
#include <cstring>
2916

17+
#include <ipfixprobe/pluginFactory/pluginManifest.hpp>
18+
#include <ipfixprobe/pluginFactory/pluginRegistrar.hpp>
19+
3020
#ifdef DEBUG_MQTT
3121
static const bool debug_mqtt = true;
3222
#else
3323
static const bool debug_mqtt = false;
3424
#endif
3525
namespace ipxp {
3626

37-
int RecordExtMQTT::REGISTERED_ID = -1;
38-
39-
__attribute__((constructor)) static void register_this_plugin()
27+
int RecordExtMQTT::REGISTERED_ID = ProcessPluginIDGenerator::instance().generatePluginID();
28+
29+
static const PluginManifest mqttPluginManifest = {
30+
.name = "mqtt",
31+
.description = "Mqtt process plugin for parsing mqtt traffic.",
32+
.pluginVersion = "1.0.0",
33+
.apiVersion = "1.0.0",
34+
.usage =
35+
[]() {
36+
MQTTOptionsParser parser;
37+
parser.usage(std::cout);
38+
},
39+
};
40+
41+
MQTTPlugin::MQTTPlugin(const std::string& params)
4042
{
41-
static PluginRecord rec = PluginRecord("mqtt", []() { return new MQTTPlugin(); });
42-
register_plugin(&rec);
43-
RecordExtMQTT::REGISTERED_ID = register_extension();
43+
init(params.c_str());
4444
}
4545

4646
int MQTTPlugin::post_create(Flow& rec, const Packet& pkt)
@@ -233,4 +233,6 @@ ProcessPlugin* MQTTPlugin::copy()
233233
return new MQTTPlugin(*this);
234234
}
235235

236+
static const PluginRegistrar<MQTTPlugin, ProcessPluginFactory> mqttRegistrar(mqttPluginManifest);
237+
236238
} // namespace ipxp
Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,30 @@
11
/**
2-
* \file mqtt.hpp
3-
* \brief MQTT plugin for ipfixprobe
4-
* \author Damir Zainullin <[email protected]>
5-
* \date 2024
6-
*/
7-
/*
8-
* Copyright (C) 2023 CESNET
2+
* @file
3+
* @brief Plugin for parsing mqtt traffic.
4+
* @author Damir Zainullin <[email protected]>
5+
* @author Pavel Siska <[email protected]>
6+
* @date 2025
97
*
10-
* LICENSE TERMS
8+
* Copyright (c) 2025 CESNET
119
*
12-
* Redistribution and use in source and binary forms, with or without
13-
* modification, are permitted provided that the following conditions
14-
* are met:
15-
* 1. Redistributions of source code must retain the above copyright
16-
* notice, this list of conditions and the following disclaimer.
17-
* 2. Redistributions in binary form must reproduce the above copyright
18-
* notice, this list of conditions and the following disclaimer in
19-
* the documentation and/or other materials provided with the
20-
* distribution.
21-
* 3. Neither the name of the Company nor the names of its contributors
22-
* may be used to endorse or promote products derived from this
23-
* software without specific prior written permission.
10+
* SPDX-License-Identifier: BSD-3-Clause
2411
*/
25-
#ifndef CACHE_CPP_TPLUGIN_HPP
26-
#define CACHE_CPP_TPLUGIN_HPP
12+
13+
#pragma once
2714

2815
#ifdef WITH_NEMEA
2916
#include "fields.h"
3017
#endif
3118

32-
#include "sstream"
33-
3419
#include <cstring>
3520
#include <numeric>
21+
#include <sstream>
3622

3723
#include <ipfixprobe/flowifc.hpp>
3824
#include <ipfixprobe/ipfix-basiclist.hpp>
3925
#include <ipfixprobe/ipfix-elements.hpp>
4026
#include <ipfixprobe/packet.hpp>
41-
#include <ipfixprobe/process.hpp>
27+
#include <ipfixprobe/processPlugin.hpp>
4228
#include <ipfixprobe/utils.hpp>
4329

4430
namespace ipxp {
@@ -171,6 +157,7 @@ struct RecordExtMQTT : public RecordExt {
171157

172158
class MQTTPlugin : public ProcessPlugin {
173159
public:
160+
MQTTPlugin(const std::string& params);
174161
int post_create(Flow& rec, const Packet& pkt) override;
175162
int pre_update(Flow& rec, Packet& pkt) override;
176163
int post_update(Flow& rec, const Packet& pkt) override;
@@ -195,5 +182,3 @@ class MQTTPlugin : public ProcessPlugin {
195182
};
196183

197184
} // namespace ipxp
198-
199-
#endif // CACHE_CPP_TPLUGIN_HPP

0 commit comments

Comments
 (0)