Skip to content

Commit f439840

Browse files
Zainullin DamirZainullin Damir
authored andcommitted
++
1 parent 0855f7b commit f439840

File tree

17 files changed

+510
-317
lines changed

17 files changed

+510
-317
lines changed

src/plugins/process/mqtt/README.md

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,18 @@ The **MQTT Plugin** extends flow records with MQTT (Message Queuing Telemetry Tr
1616

1717
## Output Fields
1818

19-
MQTT_TYPE_CUMULATIVE = 0,
20-
MQTT_VERSION,
21-
MQTT_CONNECTION_FLAGS,
22-
MQTT_KEEP_ALIVE,
23-
MQTT_CONNECTION_RETURN_CODE,
24-
MQTT_PUBLISH_FLAGS,
25-
MQTT_TOPICS,
26-
27-
2819
| Field Name | Data Type | Description |
2920
|-----------------|-----------|----------------------------------------|
30-
| `MQQT_TYPE_CUMULATIVE`| `uint16_t` | Bitfield of messages that were detected during the communication.
31-
DISCONNECT \| PINGRESP(1b) \| PINGREQ(1b) \| UNSUBACK(1b) \| UNSUBSCRIBE(1b) /|
32-
SUBACK(1b) | SUBSCRIBE(1b) | PUBCOMP(1b) | PUBREL(1b) | PUBREC(1b) | PUBACK(1b) | PUBLISH(1b) |
33-
CONNACK(1b) | CONNECT(1b) | session present(1b) |
34-
| `MQTT_VERSION`| `uint8_t` | |
35-
| `MQTT_CONNECTION_FLAGS`| `uint8_t` | |
36-
| `MQTT_KEEP_ALIVE`| `uint8_t` | |
37-
| `MQTT_VERSION`| `uint8_t` | |
21+
| `MQQT_TYPE_CUMULATIVE`| `uint16_t` | Bitfield of messages that were detected during the communication. Each value takes 1 bit.
22+
DISCONNECT \| PINGRESP \| PINGREQ \| UNSUBACK \| UNSUBSCRIBE \|
23+
SUBACK \| SUBSCRIBE \| PUBCOMP \| PUBREL \| PUBREC \| PUBACK \| PUBLISH \|
24+
CONNACK \| CONNECT \| session present flag from *connection* message\|
25+
| `MQTT_VERSION`| `uint8_t` | Identifies the MQTT version being used. |
26+
| `MQTT_CONNECTION_FLAGS`| `uint8_t` | Flags of *connection* message. |
27+
| `MQTT_KEEP_ALIVE`| `uint16_t` | MQTT connection keep alive |
28+
| `MQTT_CONNECTION_RETURN_CODE`| `uint8_t` | Return code value from *connack* message. |
29+
| `MQTT_PUBLISH_FLAGS`| `uint8_t` | Cumulative of *publish* message flags. |
30+
| `MQTT_TOPICS`| `string` | Concatenation of **topiccount** topics from *publish* messages. |
3831

3932
## Usage
4033

@@ -44,13 +37,12 @@ Add the plugin to your ipfixprobe YAML configuration:
4437

4538
```yaml
4639
process_plugins:
47-
- dnssd
40+
- mqtt
4841
```
4942
5043
### CLI Usage
5144
5245
You can also enable the plugin directly from the command line:
5346
54-
```ipfixprobe -p dnssd ...```
55-
```ipfixprobe -p "dnssd;txt" ...```
56-
```ipfixprobe -p "dnssd;txt=<path_to_file>" ...```
47+
```ipfixprobe -p mqtt ...```
48+
```ipfixprobe -p "mqtt;tc=<topic_count>" ...```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# NetBIOS Plugin
2+
3+
This plugin provides in-depth analysis of NetBIOS traffic by capturing and exporting fields from NetBIOS packets.
4+
5+
## Features
6+
7+
- Extracts and exports NetBIOS name and suffix fields from NetBIOS packets.
8+
- Expects traffic to be on port 137.
9+
10+
## Output Fields
11+
12+
| Field Name | Data Type | Description |
13+
|-----------------|-----------|-------------------------------------------------------------|
14+
| `NB_NAME` | `string` | NetBIOS name extracted from the packet |
15+
| `NB_SUFFIX` | `char` | NetBIOS suffix extracted from the packet |
16+
17+
## Usage
18+
19+
### YAML Configuration
20+
21+
Add the plugin to your ipfixprobe YAML configuration:
22+
23+
```yaml
24+
process_plugins:
25+
- netbios
26+
```
27+
28+
### CLI Usage
29+
30+
You can also enable the plugin directly from the command line:
31+
32+
```ipfixprobe -p netbios ...```
33+

src/plugins/process/netbios/src/netbios.cpp

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
*
88
* Provides a plugin that extracts NetBIOS suffix and name from packets,
99
* stores them in per-flow plugin data, and exposes fields via FieldManager.
10-
*
10+
*
1111
* @copyright Copyright (c) 2025 CESNET, z.s.p.o.
1212
*/
1313

1414
#include "netbios.hpp"
1515

16-
#include <iostream>
1716
#include <cmath>
17+
#include <iostream>
1818

19-
#include <pluginManifest.hpp>
20-
#include <pluginRegistrar.hpp>
21-
#include <pluginFactory.hpp>
19+
#include <dns-utils.hpp>
2220
#include <fieldGroup.hpp>
2321
#include <fieldManager.hpp>
24-
#include <dns-utils.hpp>
22+
#include <ipfixprobe/options.hpp>
23+
#include <pluginFactory.hpp>
24+
#include <pluginManifest.hpp>
25+
#include <pluginRegistrar.hpp>
2526
#include <utils/spanUtils.hpp>
2627
#include <utils/stringViewUtils.hpp>
27-
#include <ipfixprobe/options.hpp>
2828

2929
namespace ipxp {
3030

@@ -40,34 +40,41 @@ static const PluginManifest netbiosPluginManifest = {
4040
},
4141
};
4242

43-
static FieldGroup createNetBIOSSchema(FieldManager& fieldManager, FieldHandlers<NetBIOSFields>& fieldHandlers)
43+
static FieldGroup
44+
createNetBIOSSchema(FieldManager& fieldManager, FieldHandlers<NetBIOSFields>& fieldHandlers)
4445
{
4546
FieldGroup schema = fieldManager.createFieldGroup("netbios");
4647

47-
fieldHandlers.insert(NetBIOSFields::NB_SUFFIX, schema.addScalarField(
48-
"NB_SUFFIX",
49-
[] (const void* context) { return static_cast<uint8_t>(static_cast<const NetBIOSData*>(context)->suffix); }
50-
));
48+
fieldHandlers.insert(
49+
NetBIOSFields::NB_SUFFIX,
50+
schema.addScalarField("NB_SUFFIX", [](const void* context) {
51+
return static_cast<uint8_t>(static_cast<const NetBIOSData*>(context)->suffix);
52+
}));
5153

52-
fieldHandlers.insert(NetBIOSFields::NB_NAME, schema.addScalarField(
53-
"NB_NAME",
54-
[] (const void* context) { return toStringView(static_cast<const NetBIOSData*>(context)->name); }
55-
));
54+
fieldHandlers.insert(
55+
NetBIOSFields::NB_NAME,
56+
schema.addScalarField("NB_NAME", [](const void* context) {
57+
return toStringView(static_cast<const NetBIOSData*>(context)->name);
58+
}));
5659

5760
return schema;
5861
}
5962

60-
NetBIOSPlugin::NetBIOSPlugin([[maybe_unused]]const std::string& params, FieldManager& manager)
63+
NetBIOSPlugin::NetBIOSPlugin([[maybe_unused]] const std::string& params, FieldManager& manager)
6164
{
6265
createNetBIOSSchema(manager, m_fieldHandlers);
6366
}
6467

6568
PluginInitResult NetBIOSPlugin::onInit(const FlowContext& flowContext, void* pluginContext)
6669
{
6770
constexpr uint8_t NETBIOS_PORT = 137;
68-
if (flowContext.packet.src_port == NETBIOS_PORT || flowContext.packet.dst_port == NETBIOS_PORT) {
71+
if (flowContext.packet.src_port == NETBIOS_PORT
72+
|| flowContext.packet.dst_port == NETBIOS_PORT) {
6973
auto* pluginData = std::construct_at(reinterpret_cast<NetBIOSData*>(pluginContext));
70-
parseNetBIOS(flowContext.flowRecord, toSpan<const std::byte>(flowContext.packet.payload, flowContext.packet.payload_len), *pluginData);
74+
parseNetBIOS(
75+
flowContext.flowRecord,
76+
toSpan<const std::byte>(flowContext.packet.payload, flowContext.packet.payload_len),
77+
*pluginData);
7178
return {
7279
.constructionState = ConstructionState::Constructed,
7380
.updateRequirement = UpdateRequirement::NoUpdateNeeded,
@@ -82,19 +89,21 @@ PluginInitResult NetBIOSPlugin::onInit(const FlowContext& flowContext, void* plu
8289
};
8390
}
8491

85-
constexpr static
86-
char compressCharPair(const char first, const char second)
92+
constexpr static char compressCharPair(const char first, const char second)
8793
{
8894
return static_cast<char>(((first - 'A') << 4) | (second - 'A'));
8995
}
9096

91-
void NetBIOSPlugin::parseNetBIOS(FlowRecord& flowRecord, std::span<const std::byte> payload, NetBIOSData& pluginData) noexcept
97+
void NetBIOSPlugin::parseNetBIOS(
98+
FlowRecord& flowRecord,
99+
std::span<const std::byte> payload,
100+
NetBIOSData& pluginData) noexcept
92101
{
93102
if (payload.size() < sizeof(dns_hdr) || !pluginData.name.empty()) {
94103
return;
95104
}
96105

97-
const std::size_t queryCount
106+
const std::size_t queryCount
98107
= reinterpret_cast<const dns_hdr*>(payload.data())->question_rec_cnt;
99108
if (queryCount == 0) {
100109
return;
@@ -107,8 +116,8 @@ void NetBIOSPlugin::parseNetBIOS(FlowRecord& flowRecord, std::span<const std::by
107116
}
108117

109118
auto nameIt = reinterpret_cast<const std::pair<char, char>*>(payload.data());
110-
for (; reinterpret_cast<const std::byte*>(nameIt)
111-
!= payload.data() + payload.size() - 2; nameIt++) {
119+
for (; reinterpret_cast<const std::byte*>(nameIt) != payload.data() + payload.size() - 2;
120+
nameIt++) {
112121
pluginData.name.push_back(compressCharPair(nameIt->first, nameIt->second));
113122
}
114123
m_fieldHandlers[NetBIOSFields::NB_NAME].setAsAvailable(flowRecord);
@@ -130,7 +139,9 @@ PluginDataMemoryLayout NetBIOSPlugin::getDataMemoryLayout() const noexcept
130139
};
131140
}
132141

133-
static const PluginRegistrar<NetBIOSPlugin, PluginFactory<ProcessPlugin, const std::string&, FieldManager&>>
142+
static const PluginRegistrar<
143+
NetBIOSPlugin,
144+
PluginFactory<ProcessPlugin, const std::string&, FieldManager&>>
134145
netbiosRegistrar(netbiosPluginManifest);
135146

136147
} // namespace ipxp

src/plugins/process/netbios/src/netbios.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
*
88
* Provides a plugin that extracts NetBIOS suffix and name from packets,
99
* stores them in per-flow plugin data, and exposes fields via FieldManager.
10-
*
10+
*
1111
* @copyright Copyright (c) 2025 CESNET, z.s.p.o.
1212
*/
1313

1414
#pragma once
1515

16+
#include "netbiosData.hpp"
17+
#include "netbiosFields.hpp"
18+
1619
#include <sstream>
1720
#include <string>
18-
#include <processPlugin.hpp>
19-
#include <fieldManager.hpp>
20-
#include <fieldHandlersEnum.hpp>
2121

22-
#include "netbiosData.hpp"
23-
#include "netbiosFields.hpp"
22+
#include <fieldHandlersEnum.hpp>
23+
#include <fieldManager.hpp>
24+
#include <processPlugin.hpp>
2425

2526
namespace ipxp {
2627

@@ -30,7 +31,6 @@ namespace ipxp {
3031
*/
3132
class NetBIOSPlugin : public ProcessPlugin {
3233
public:
33-
3434
/**
3535
* @brief Constructs the NetBIOS plugin.
3636
*
@@ -39,7 +39,6 @@ class NetBIOSPlugin : public ProcessPlugin {
3939
*/
4040
NetBIOSPlugin(const std::string& params, FieldManager& manager);
4141

42-
4342
/**
4443
* @brief Initializes plugin data for a new flow.
4544
*
@@ -66,8 +65,11 @@ class NetBIOSPlugin : public ProcessPlugin {
6665
PluginDataMemoryLayout getDataMemoryLayout() const noexcept override;
6766

6867
private:
69-
void parseNetBIOS(FlowRecord& flowRecord, std::span<const std::byte> payload, NetBIOSData& pluginData) noexcept;
70-
68+
void parseNetBIOS(
69+
FlowRecord& flowRecord,
70+
std::span<const std::byte> payload,
71+
NetBIOSData& pluginData) noexcept;
72+
7173
FieldHandlers<NetBIOSFields> m_fieldHandlers;
7274
};
7375

src/plugins/process/netbios/src/netbiosData.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
#include <string>
1313

14-
namespace ipxp
15-
{
14+
namespace ipxp {
1615

1716
/**
1817
* @struct NetBIOSData
@@ -21,7 +20,6 @@ namespace ipxp
2120
struct NetBIOSData {
2221
std::string name;
2322
char suffix;
24-
};
23+
};
2524

2625
} // namespace ipxp
27-

src/plugins/process/netbios/src/netbiosFields.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
#include <cstddef>
1313

14-
namespace ipxp
15-
{
14+
namespace ipxp {
1615

1716
/**
1817
* @enum NetBIOSFields
@@ -24,6 +23,6 @@ enum class NetBIOSFields : std::size_t {
2423
NB_NAME = 0,
2524
NB_SUFFIX,
2625
FIELDS_SIZE,
27-
};
28-
26+
};
27+
2928
} // namespace ipxp
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# NetTimeSeries Plugin
2+
3+
This plugin analyzes network data as time series, enabling more comprehensive and insightful analysis.
4+
5+
## Features
6+
7+
- Calculates and exports statistical properties of the flow based on packet lengths.
8+
9+
## Output Fields
10+
11+
| Field Name | Data Type | Description |
12+
|-----------------|-----------|----------------------------------------|
13+
| `NTS_MEAN` | `float` | Mean packet length over the flow duration. |
14+
| `NTS_MIN` | `uint16_t` | Minimum packet length over the flow duration. |
15+
| `NTS_MAX` | `uint16_t` | Maximum packet length over the flow duration. |
16+
| `NTS_STDEV` | `float` | Standard deviation of packet lengths over the flow duration. |
17+
| `NTS_KURTOSIS` | `float` | Kurtosis of packet lengths over the flow duration. |
18+
| `NTS_ROOT_MEAN_SQUARE` | `float` | Root mean square of packet lengths over the flow duration. |
19+
| `NTS_AVERAGE_DISPERSION` | `float` | Average dispersion of packet lengths over the flow duration. |
20+
| `NTS_MEAN_SCALED_TIME` | `float` | Mean of packet lengths scaled by time over the flow duration. |
21+
| `NTS_MEAN_DIFFTIMES` | `float` | Mean of time differences between packets over the flow duration. |
22+
| `NTS_MIN_DIFFTIMES` | `float` | Minimum of time differences between packets over the flow duration. |
23+
| `NTS_MAX_DIFFTIMES` | `float` | Maximum of time differences between packets over the flow duration. |
24+
| `NTS_TIME_DISTRIBUTION` | `float` | Sum of deviations from mean interpacket arrival times. |
25+
| `NTS_SWITCHING_RATIO` | `float` | Ratio of packets when payload length changed in comparison to previous packet. |
26+
27+
## Usage
28+
29+
### YAML Configuration
30+
31+
Add the plugin to your ipfixprobe YAML configuration:
32+
33+
```yaml
34+
process_plugins:
35+
- nettisa
36+
```
37+
38+
### CLI Usage
39+
40+
You can also enable the plugin directly from the command line:
41+
42+
```ipfixprobe -p nettisa ...```
43+

0 commit comments

Comments
 (0)