Skip to content

Commit 09bdca9

Browse files
Zainullin DamirZainullin Damir
authored andcommitted
++
1 parent ba535e5 commit 09bdca9

Some content is hidden

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

43 files changed

+462
-145
lines changed

include/ipfixprobe/processPlugin/fieldHandlersEnum.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include "fieldHandler.hpp"
4+
35
#include <boost/container/static_vector.hpp>
46

57
namespace ipxp {

include/ipfixprobe/processPlugin/flowRecord.hpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#pragma once
22

3-
#include "timestamp.hpp"
4-
#include "flowKey.hpp"
53
#include "directionalField.hpp"
6-
#include "tcpFlags.hpp"
4+
#include "flowKey.hpp"
5+
#include "macAddress.hpp"
76
#include "packet.hpp"
7+
#include "tcpFlags.hpp"
8+
#include "timestamp.hpp"
89
#include "xxhash.h"
910

1011
#include <array>
@@ -70,7 +71,6 @@ class FlowRecord {
7071

7172
FlowEndReason endReason;
7273

73-
7474
// Bitset of flow fields that were specified as present
7575
mutable FieldsBitset fieldsAvailable = {};
7676
// Bitset of successfully constructed plugins (constructor accepted packet)
@@ -80,13 +80,12 @@ class FlowRecord {
8080
// Bitset of plugins that are available for the flow
8181
const PluginsBitset pluginsAvailable;
8282

83-
8483
void erase()
8584
{
8685
hash = 0;
8786
timeCreation = timeLastUpdate = {};
8887
flowKey = {};
89-
//directionalData = {};
88+
// directionalData = {};
9089

9190
/*memset(&m_flow.time_first, 0, sizeof(m_flow.time_first));
9291
memset(&m_flow.time_last, 0, sizeof(m_flow.time_last));
@@ -116,10 +115,7 @@ class FlowRecord {
116115
m_flow.dst_tcp_flags = 0;*/
117116
}
118117

119-
constexpr bool isEmpty() const noexcept
120-
{
121-
return hash == 0;
122-
}
118+
constexpr bool isEmpty() const noexcept { return hash == 0; }
123119

124120
/*constexpr bool belongs(uint64_t value) const noexcept
125121
{
@@ -132,7 +128,6 @@ class FlowRecord {
132128
directionalData[Direction::Forward].packets = 1;
133129
directionalData[Direction::Forward].bytes = packet.ip_len;
134130

135-
136131
flowKey.srcPort = packet.src_port;
137132
flowKey.dstPort = packet.dst_port;
138133
flowKey.l4Protocol = packet.ip_proto;
@@ -142,21 +137,21 @@ class FlowRecord {
142137
timeCreation = packet.ts;
143138
timeLastUpdate = packet.ts;
144139

145-
macAddress[Direction::Forward]
146-
= std::span<const std::byte, 6>(
147-
reinterpret_cast<const std::byte*>(packet.src_mac), 6);
148-
macAddress[Direction::Reverse]
149-
= std::span<const std::byte, 6>(
150-
reinterpret_cast<const std::byte*>(packet.dst_mac), 6);
140+
macAddress[Direction::Forward]
141+
= std::span<const std::byte, 6>(reinterpret_cast<const std::byte*>(packet.src_mac), 6);
142+
macAddress[Direction::Reverse]
143+
= std::span<const std::byte, 6>(reinterpret_cast<const std::byte*>(packet.dst_mac), 6);
151144

152145
if (packet.ip_version == IP::v4) {
153146
flowKey.srcIp = packet.src_ip.v4;
154147
flowKey.dstIp = packet.dst_ip.v4;
155148
} else if (packet.ip_version == IP::v6) {
156149
flowKey.srcIp = std::span<const std::byte, 16>(
157-
reinterpret_cast<const std::byte*>(packet.src_ip.v6), 16);
150+
reinterpret_cast<const std::byte*>(packet.src_ip.v6),
151+
16);
158152
flowKey.dstIp = std::span<const std::byte, 16>(
159-
reinterpret_cast<const std::byte*>(packet.dst_ip.v6), 16);
153+
reinterpret_cast<const std::byte*>(packet.dst_ip.v6),
154+
16);
160155
}
161156
}
162157

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <directionalField.hpp>
1313
#include <sys/time.h>
14+
#include <timestamp.hpp>
1415
#include <utils.hpp>
1516

1617
namespace ipxp {

src/plugins/process/common/utils/stringUtils.hpp

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,48 @@
22

33
#include <ranges>
44

5-
namespace ipxp
6-
{
5+
namespace ipxp {
6+
7+
constexpr static inline auto integerToCharPtrView
8+
= std::views::transform([](const auto& value) mutable {
9+
static std::array<char, 100> buffer;
10+
auto [end, _] = std::to_chars(buffer.data(), buffer.end(), value);
11+
return std::string_view(buffer.data(), end);
12+
});
713

8-
constexpr static inline
9-
auto integerToCharPtrView = std::views::transform(
10-
[](const auto& value) mutable {
11-
static std::array<char, 100> buffer;
12-
auto [end, _] = std::to_chars(buffer.data(), buffer.end(), value);
13-
return std::string_view(buffer.data(), end);
14-
});
15-
16-
constexpr static inline
17-
bool pushBackWithDelimiter(
18-
auto&& value, auto&& outputContainer, const char delimiter) noexcept
14+
constexpr static inline bool
15+
pushBackWithDelimiter(auto&& value, auto&& outputContainer, const char delimiter) noexcept
1916
{
20-
if (outputContainer.size() + value.size() + sizeof(delimiter)
21-
> outputContainer.capacity()) {
22-
return true;
23-
}
17+
if (outputContainer.size() + value.size() + sizeof(delimiter) > outputContainer.capacity()) {
18+
return true;
19+
}
2420

25-
outputContainer.append(value.begin(), value.end());
26-
outputContainer.push_back(delimiter);
21+
outputContainer.append(value.begin(), value.end());
22+
outputContainer.push_back(delimiter);
2723

28-
return false;
24+
return false;
2925
}
3026

31-
constexpr static inline
32-
void concatenateRangeTo(
33-
auto&& inputRange,
34-
auto&& outputContainer,
35-
const char delimiter,
36-
const std::optional<char> terminator = std::nullopt) noexcept
27+
constexpr static inline void concatenateRangeTo(
28+
auto&& inputRange,
29+
auto&& outputContainer,
30+
const char delimiter,
31+
const std::optional<char> terminator = std::nullopt) noexcept
3732
{
38-
const bool overflowed = std::ranges::any_of(inputRange,
39-
[&](const auto& value) {
40-
return pushBackWithDelimiter(
41-
value, outputContainer, delimiter);
42-
});
43-
44-
if (overflowed) {
45-
return;
46-
}
47-
48-
if (terminator.has_value()) {
49-
outputContainer.back() = *terminator;
50-
} else {
51-
outputContainer.pop_back();
52-
}
53-
54-
33+
const bool overflowed
34+
= std::any_of(inputRange.begin(), inputRange.end(), [&](const auto& value) {
35+
return pushBackWithDelimiter(value, outputContainer, delimiter);
36+
});
37+
38+
if (overflowed) {
39+
return;
40+
}
41+
42+
if (terminator.has_value()) {
43+
outputContainer.back() = *terminator;
44+
} else {
45+
outputContainer.pop_back();
46+
}
5547
}
5648

5749
} // namespace ipxp

src/plugins/process/http/src/httpParser.cpp

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,7 @@ constexpr static bool isValidHTTPMethod(std::string_view payload) noexcept
4242
constexpr static bool hasHTTPVersionInRequest(std::string_view payload) noexcept
4343
{
4444
constexpr std::string_view httpLabel = "HTTP";
45-
46-
auto spaces = payload | std::views::filter([](const char c) { return c == ' '; });
47-
48-
auto httpLabelBegin = std::ranges::next(spaces.begin(), 2);
49-
auto httpLabelEnd = std::ranges::next(spaces.begin(), 3);
50-
if (httpLabelBegin == spaces.end() || httpLabelEnd == spaces.end()) {
51-
return false;
52-
}
53-
54-
return std::string_view(&*std::next(httpLabelBegin), &*httpLabelEnd) == httpLabel;
45+
return payload.contains(httpLabel);
5546
}
5647

5748
constexpr static bool isRequest(std::string_view payload) noexcept
@@ -62,6 +53,7 @@ constexpr static bool isRequest(std::string_view payload) noexcept
6253
constexpr static bool hasHttpVersionInResponse(std::string_view payload) noexcept
6354
{
6455
constexpr std::string_view httpLabel = "HTTP";
56+
6557
return payload.starts_with(httpLabel);
6658
}
6759

@@ -109,20 +101,16 @@ constexpr bool HTTPParser::parseRequest(std::string_view payload) noexcept
109101
if (methodEnd == std::string_view::npos) {
110102
return false;
111103
}
112-
auto methodBegin
113-
= std::ranges::find_if(payload, [](const unsigned char c) { return !std::isspace(c); });
114-
const std::size_t methodBeginPos = std::distance(payload.begin(), methodBegin);
115-
method = std::string_view(payload.substr(methodBeginPos, methodEnd - methodBeginPos));
104+
105+
auto methodBegin = payload.find_first_not_of(' ');
106+
method = payload.substr(methodBegin, methodEnd - methodBegin);
116107

117108
const std::size_t uriEnd = payload.find(' ', methodEnd + 1);
118109
if (uriEnd == std::string_view::npos) {
119110
return false;
120111
}
121-
auto uriBegin = std::ranges::find_if(payload.substr(methodEnd + 1), [](const unsigned char c) {
122-
return !std::isspace(c);
123-
});
124-
const std::size_t uriBeginPos = std::distance(payload.begin(), uriBegin);
125-
uri = std::string_view(payload.substr(uriBeginPos, uriEnd - uriBeginPos));
112+
auto uriBegin = payload.substr(methodEnd + 1).find_first_not_of(' ');
113+
uri = payload.substr(uriBegin, uriEnd - uriBegin);
126114

127115
const std::size_t httpVersionEnd = payload.find('\n', uriEnd + 1);
128116
if (httpVersionEnd == std::string_view::npos) {
@@ -147,7 +135,9 @@ bool HTTPParser::parseResponseHeaders(std::string_view payload) noexcept
147135
cookies.emplace();
148136
}
149137
std::ranges::copy(
150-
splitToVector(value) | std::views::transform(removeLeadingWhitespaces)
138+
value | std::views::split(' ') | std::views::transform([](auto&& rng) {
139+
return std::string_view(&*rng.begin(), std::ranges::distance(rng));
140+
}) | std::views::transform(removeLeadingWhitespaces)
151141
| std::views::take(cookies->capacity() - cookies->size()),
152142
std::back_inserter(*cookies));
153143
}
@@ -158,25 +148,24 @@ bool HTTPParser::parseResponseHeaders(std::string_view payload) noexcept
158148

159149
constexpr bool HTTPParser::parseResponse(std::string_view payload) noexcept
160150
{
161-
auto spaces = payload | std::views::filter([](const char c) { return c == ' '; });
162-
163-
auto statusCodeBegin = std::next(spaces.begin(), 1);
164-
auto statusCodeEnd = std::next(spaces.begin(), 2);
165-
if (statusCodeBegin == spaces.end() || statusCodeEnd == spaces.end()) {
166-
return false;
167-
}
168-
const auto [_, errorCode] = std::from_chars(&*statusCodeBegin, &*statusCodeEnd, *statusCode);
169-
if (errorCode != std::errc()) {
151+
auto firstLine = payload.substr(0, payload.find('\n'));
152+
if (firstLine.length() == payload.length()) {
170153
return false;
171154
}
172155

173-
const size_t statusMessageEnd
174-
= payload.find('\n', std::distance(spaces.begin(), statusCodeEnd) + 1);
175-
if (statusMessageEnd == std::string_view::npos) {
156+
const std::size_t statusCodeBegin = firstLine.find(' ');
157+
const std::size_t statusCodeEnd = firstLine.find(' ', statusCodeBegin + 1);
158+
if (statusCodeBegin == std::string_view::npos || statusCodeEnd == std::string_view::npos
159+
|| std::from_chars(
160+
firstLine.data() + statusCodeBegin + 1,
161+
firstLine.data() + statusCodeEnd,
162+
*statusCode)
163+
.ec
164+
!= std::errc()) {
176165
return false;
177166
}
178167

179-
return parseResponseHeaders(payload.substr(statusMessageEnd + 1));
168+
return parseResponseHeaders(payload.substr(firstLine.size() + 1));
180169
}
181170

182171
} // namespace ipxp

src/plugins/process/idpContent/src/idpContentData.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <span>
1515

1616
#include <boost/container/static_vector.hpp>
17+
#include <directionalField.hpp>
1718

1819
namespace ipxp {
1920

src/plugins/process/passiveDns/src/passivedns.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <sstream>
2121
#include <string>
2222

23+
#include <dnsParser/dnsRecord.hpp>
2324
#include <fieldHandlersEnum.hpp>
2425
#include <fieldManager.hpp>
2526
#include <processPlugin.hpp>

src/plugins/process/phists/src/packetHistogramData.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#pragma once
1111

1212
#include <array>
13+
#include <optional>
1314

1415
#include <directionalField.hpp>
1516

src/plugins/process/pstats/src/packetStatsStorage.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <boost/container/static_vector.hpp>
88
#include <tcpFlags.hpp>
9+
#include <timestamp.hpp>
910

1011
namespace ipxp {
1112

src/plugins/process/rtsp/src/rtsp.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**
22
* @file
3-
* @brief Plugin for parsing basicplus traffic.
3+
* @brief Plugin for parsing RTSP traffic.
44
* @author Jiri Havranek <[email protected]>
55
* @author Pavel Siska <[email protected]>
66
* @author Damir Zainullin <[email protected]>
77
* @date 2025
88
*
9-
* Copyright (c) 2025 CESNET
9+
* Provides a plugin that parses RTSP traffic,
10+
* stores it in per-flow plugin data, and exposes that field via FieldManager.
1011
*
11-
* SPDX-License-Identifier: BSD-3-Clause
12+
* @copyright Copyright (c) 2025 CESNET, z.s.p.o.
1213
*/
1314

1415
#include "rtsp.hpp"

0 commit comments

Comments
 (0)