Skip to content

Commit b9bd047

Browse files
committed
++
1 parent 9e25a75 commit b9bd047

File tree

100 files changed

+1572
-1105
lines changed

Some content is hidden

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

100 files changed

+1572
-1105
lines changed

new-process-api/flowRecord.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class FlowRecord {
5050
public:
5151
uint64_t hash;
5252

53-
uint64_t timeCreation;
54-
uint64_t timeLastUpdate;
53+
Timestamp timeCreation;
54+
Timestamp timeLastUpdate;
5555

5656
FlowKey flowKey;
5757

new-process-api/ipAddress.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <algorithm>
1010
#include <format>
1111

12+
#include <ipfixprobe/ipaddr.hpp>
13+
1214
namespace ipxp {
1315

1416
union IPAddress {
@@ -35,6 +37,11 @@ union IPAddress {
3537
ipv6.begin(), ipv6.end(), reinterpret_cast<std::byte*>(u8.data()));
3638
}
3739

40+
constexpr IPAddress(const ipaddr_t address) noexcept
41+
{
42+
// TODO
43+
}
44+
3845
constexpr bool isIPv4() const noexcept
3946
{
4047
return u32[1] == 0 &&
-480 Bytes
Binary file not shown.

new-process-api/process/bstats/src/burst.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ namespace ipxp
2121
* @brief Structure representing one packet burst. Contains packets, bytes which belong to that burst with begin and end timestamps.
2222
*/
2323
struct Burst {
24-
constexpr static uint64_t MAX_INTERPACKET_TIMEDIFF = 1'000'000;
24+
constexpr static timeval MAX_INTERPACKET_TIMEDIFF = {1, 0}; ///< Maximum time difference between packets in one burst (1 second).
2525

2626
std::reference_wrapper<uint32_t> packets;
2727
std::reference_wrapper<uint32_t> bytes;
28-
std::reference_wrapper<uint64_t> start;
29-
std::reference_wrapper<uint64_t> end;
28+
std::reference_wrapper<Timestamp> start;
29+
std::reference_wrapper<Timestamp> end;
3030

3131
/**
3232
* @brief Checks if the given timestamp belongs to the burst.
@@ -35,11 +35,10 @@ struct Burst {
3535
* @return true if the timestamp belongs to the burst, false otherwise.
3636
*/
3737
constexpr
38-
bool belongs(const uint64_t time) const noexcept
38+
bool belongs(const timeval time) const noexcept
3939
{
40-
return time - end < MAX_INTERPACKET_TIMEDIFF;
40+
return Timestamp(time) - end < MAX_INTERPACKET_TIMEDIFF;
4141
}
4242
};
4343

44-
4544
} // namespace ipxp

new-process-api/process/bstats/src/burstStats.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,20 @@ void BurstStatsPlugin::updateBursts(Burst& burst, FlowRecord& flowRecord,
101101
const Packet& packet) noexcept
102102
{
103103
burst.packets++;
104-
burst.bytes += packet.realLength;
105-
burst.end.get() = packet.timestamp;
104+
burst.bytes += packet.ip_payload_len;
105+
burst.end.get() = packet.ts;
106106
if (burst.packets == 1) {
107-
burst.start.get() = packet.timestamp;
107+
burst.start.get() = packet.ts;
108108
}
109109
}
110110

111111
PluginUpdateResult BurstStatsPlugin::onUpdate(const FlowContext& flowContext, void* pluginContext)
112112
{
113113
auto* pluginData = reinterpret_cast<BurstStatsData*>(pluginContext);
114114

115-
std::optional<Burst> burst = pluginData->back(flowContext.packet.direction);
116-
if (!burst.has_value() || !burst->belongs(flowContext.packet.timestamp)) {
117-
burst = pluginData->push(flowContext.packet.direction);
115+
std::optional<Burst> burst = pluginData->back(flowContext.packet.source_pkt);
116+
if (!burst.has_value() || !burst->belongs(flowContext.packet.ts)) {
117+
burst = pluginData->push(flowContext.packet.source_pkt);
118118
}
119119
if (!burst.has_value()) {
120120
return {
13.9 KB
Binary file not shown.

new-process-api/process/bstats/src/burstStatsData.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <optional>
1515
#include <span>
1616

17+
#include <timestamp.hpp>
18+
1719
#include "burst.hpp"
1820

1921
namespace ipxp
@@ -30,8 +32,8 @@ class BurstStatsData {
3032

3133
DirectionalField<boost::container::static_vector<uint32_t, MAX_BURST_COUNT>> packets;
3234
DirectionalField<boost::container::static_vector<uint32_t, MAX_BURST_COUNT>> bytes;
33-
DirectionalField<boost::container::static_vector<uint64_t, MAX_BURST_COUNT>> start;
34-
DirectionalField<boost::container::static_vector<uint64_t, MAX_BURST_COUNT>> end;
35+
DirectionalField<boost::container::static_vector<Timestamp, MAX_BURST_COUNT>> start;
36+
DirectionalField<boost::container::static_vector<Timestamp, MAX_BURST_COUNT>> end;
3537

3638
public:
3739

@@ -63,9 +65,9 @@ class BurstStatsData {
6365
* @param direction The direction for which to retrieve the start timestamps span.
6466
* @return A span over the start timestamps.
6567
*/
66-
std::span<const uint64_t> getStartTimestamps(const Direction direction) const noexcept
68+
std::span<const Timestamp> getStartTimestamps(const Direction direction) const noexcept
6769
{
68-
return std::span<const uint64_t>(start[direction].data(), static_cast<std::size_t>(start[direction].size()));
70+
return std::span<const Timestamp>(start[direction].data(), static_cast<std::size_t>(start[direction].size()));
6971
}
7072

7173
/**
@@ -74,9 +76,9 @@ class BurstStatsData {
7476
* @param direction The direction for which to retrieve the end timestamps span.
7577
* @return A span over the end timestamps.
7678
*/
77-
std::span<const uint64_t> getEndTimestamps(const Direction direction) const noexcept
79+
std::span<const Timestamp> getEndTimestamps(const Direction direction) const noexcept
7880
{
79-
return std::span<const uint64_t>(&*end[direction].begin(), static_cast<std::size_t>(end[direction].size()));
81+
return std::span<const Timestamp>(end[direction].data(), static_cast<std::size_t>(end[direction].size()));
8082
}
8183

8284
/**
@@ -112,8 +114,8 @@ class BurstStatsData {
112114

113115
packets[direction].push_back(0);
114116
bytes[direction].push_back(0);
115-
start[direction].push_back(0);
116-
end[direction].push_back(0);
117+
start[direction].push_back({});
118+
end[direction].push_back({});
117119

118120
return back(direction);
119121
}

new-process-api/process/common/utils/stringViewUtils.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ std::string_view toStringView(const T& container) noexcept
1717
reinterpret_cast<const char*>(container.data()), container.size());
1818
}
1919

20+
constexpr static inline
21+
std::string_view toStringView(const auto* data, const std::size_t size) noexcept
22+
{
23+
return std::string_view(
24+
reinterpret_cast<const char*>(data), size);
25+
}
26+
2027
constexpr static inline
2128
auto split(std::string_view view, const char delimiter) noexcept
2229
{

new-process-api/process/dns/src/dns.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#include <utils.hpp>
2525
#include <dnsParser/dnsParser.hpp>
2626
#include <utils/stringViewUtils.hpp>
27+
#include <utils/spanUtils.hpp>
2728

2829
namespace ipxp {
2930

30-
3131
static const PluginManifest dnsPluginManifest = {
3232
.name = "dns",
3333
.description = "Dns process plugin for parsing dns traffic.",
@@ -89,7 +89,7 @@ DNSPlugin::DNSPlugin([[maybe_unused]]const std::string& params, FieldManager& ma
8989
PluginInitResult DNSPlugin::onInit(const FlowContext& flowContext, void* pluginContext)
9090
{
9191
constexpr uint16_t DNS_PORT = 53;
92-
if (flowContext.packet.flowKey.srcPort != DNS_PORT && flowContext.packet.flowKey.dstPort != DNS_PORT) {
92+
if (flowContext.packet.src_port != DNS_PORT && flowContext.packet.dst_port != DNS_PORT) {
9393
return {
9494
.constructionState = ConstructionState::NotConstructed,
9595
.updateRequirement = UpdateRequirement::NoUpdateNeeded,
@@ -100,8 +100,8 @@ PluginInitResult DNSPlugin::onInit(const FlowContext& flowContext, void* pluginC
100100
auto* pluginData = std::construct_at(reinterpret_cast<DNSData*>(pluginContext));
101101
// TODO USE VALUES FROM DISSECTOR
102102
constexpr uint8_t TCP = 6;
103-
const bool isDNSOverTCP = flowContext.packet.flowKey.l4Protocol == TCP;
104-
if (parseDNS(flowContext.packet.payload, isDNSOverTCP, flowContext.flowRecord, *pluginData)) {
103+
const bool isDNSOverTCP = flowContext.packet.ip_proto == TCP;
104+
if (parseDNS(toSpan<const std::byte>(flowContext.packet.payload, flowContext.packet.payload_len), isDNSOverTCP, flowContext.flowRecord, *pluginData)) {
105105
return {
106106
.constructionState = ConstructionState::Constructed,
107107
.updateRequirement = UpdateRequirement::NoUpdateNeeded,
@@ -122,8 +122,8 @@ PluginUpdateResult DNSPlugin::onUpdate(const FlowContext& flowContext, void* plu
122122

123123
// TODO USE VALUES FROM DISSECTOR
124124
constexpr uint8_t TCP = 6;
125-
const bool isDNSOverTCP = flowContext.packet.flowKey.l4Protocol == TCP;
126-
if (parseDNS(flowContext.packet.payload, isDNSOverTCP, flowContext.flowRecord, *pluginData)) {
125+
const bool isDNSOverTCP = flowContext.packet.ip_proto == TCP;
126+
if (parseDNS(toSpan<const std::byte>(flowContext.packet.payload, flowContext.packet.payload_len), isDNSOverTCP, flowContext.flowRecord, *pluginData)) {
127127
return {
128128
.updateRequirement = UpdateRequirement::NoUpdateNeeded,
129129
.flowAction = FlowAction::Flush,
-11.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)