Skip to content

Commit 1a02e97

Browse files
committed
++
1 parent 33f58d2 commit 1a02e97

File tree

304 files changed

+32013
-17
lines changed

Some content is hidden

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

304 files changed

+32013
-17
lines changed

new-process-api/Makefile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
CXX := g++
22
CXXFLAGS := -std=c++20 -Wall -Wextra -pedantic -Wunused -Wconversion -Wsign-conversion -g -fsanitize=address
3-
INCLUDES := -I/usr/include
4-
LDFLAGS := -lboost_system -lboost_filesystem
5-
63
TARGET := ipx
7-
SRC := main.cpp fieldManager.cpp icmp.cpp
4+
SRC := main.cpp \
5+
$(wildcard process/common/*/*/*.cpp) \
6+
$(wildcard process/common/*/*.cpp) \
7+
$(wildcard process/*/src/*.cpp)
8+
9+
INCLUDE := -I. -I../include/ipfixprobe/pluginFactory -Iprocess/common
10+
11+
OBJ := $(SRC:.cpp=.o)
812

913
.PHONY: all clean
1014

1115
all: $(TARGET)
1216

13-
$(TARGET): $(SRC)
14-
$(CXX) $(CXXFLAGS) $(INCLUDES) $^ -o $@ $(LDFLAGS)
17+
$(TARGET): $(OBJ)
18+
$(CXX) $(CXXFLAGS) $(INCLUDE) $^ -o $@
19+
20+
%.o: %.cpp
21+
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
1522

1623
clean:
1724
rm -f $(TARGET)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
enum Direction : std::size_t { Forward = 0, Reverse = 1 };
6+
7+
template<typename T>
8+
struct DirectionalField {
9+
T values[2]{};
10+
11+
constexpr T& operator[](Direction d) { return values[static_cast<std::size_t>(d)]; }
12+
constexpr const T& operator[](Direction d) const { return values[static_cast<std::size_t>(d)]; }
13+
};

new-process-api/fieldSupportedTypes.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using NumericFieldTypes = std::
4444
*
4545
* Contains specialized types like Timestamp, IP and MAC addresses.
4646
*/
47-
using CustomFieldTypes = std::tuple<Timestamp, IpAddress, MacAddress>;
47+
using CustomFieldTypes = std::tuple<Timestamp, IPAddress, MacAddress>;
4848

4949
/**
5050
* @brief Helper alias for compile-time concatenation of multiple `std::tuple` type lists.

new-process-api/flowKey.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
#include "ipAddress.hpp"
6+
7+
namespace ipxp {
8+
9+
struct FlowKey {
10+
IPAddress srcIp;
11+
IPAddress dstIp;
12+
uint16_t srcPort;
13+
uint16_t dstPort;
14+
uint8_t l4Protocol;
15+
16+
constexpr inline
17+
std::size_t hash() const noexcept
18+
{
19+
return 0; //XXH3_64bits(this, sizeof(*this), 0);
20+
}
21+
};
22+
23+
struct FlowKeyLayout {
24+
std::size_t size;
25+
std::size_t alignment;
26+
};
27+
28+
} // namespace ipxp

new-process-api/flowRecord.hpp

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

33
#include "timestamp.hpp"
4+
#include "flowKey.hpp"
5+
#include "directionalField.hpp"
46

57
#include <array>
68
#include <bitset>
@@ -45,6 +47,15 @@ struct DirectionalData {
4547

4648
class FlowRecord {
4749
public:
50+
uint64_t hash;
51+
52+
uint64_t timeCreation;
53+
uint64_t timeLastUpdate;
54+
55+
FlowKey flowKey;
56+
57+
DirectionalField<DirectionalData> directionalData;
58+
4859
// Bitset of flow fields that were specified as present
4960
mutable FieldsBitset fieldsAvailable = {};
5061
// Bitset of successfully constructed plugins (constructor accepted packet)

new-process-api/ipAddress.hpp

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,97 @@
11
#pragma once
22

33
#include <iostream>
4+
#include <array>
5+
#include <cstdint>
6+
#include <cstring>
7+
#include <limits>
8+
#include <compare>
9+
#include <algorithm>
10+
#include <format>
411

512
namespace ipxp {
613

7-
struct IpAddress {};
14+
union IPAddress {
15+
std::array<uint8_t, 16> u8;
16+
std::array<uint16_t, 8> u16;
17+
std::array<uint32_t, 4> u32;
18+
std::array<uint64_t, 2> u64;
819

9-
inline std::ostream& operator<<(std::ostream& os, const IpAddress& ip)
10-
{
11-
(void) ip;
20+
constexpr IPAddress() noexcept
21+
{
22+
std::memset(&u8, 0, sizeof(IPAddress));
23+
}
24+
25+
constexpr IPAddress(const uint32_t ipv4) noexcept
26+
{
27+
u32[0] = ipv4;
28+
u32[1] = 0;
29+
u32[2] = u32[3] = std::numeric_limits<uint32_t>::max();
30+
}
31+
32+
constexpr IPAddress(const std::span<const std::byte, 16>& ipv6) noexcept
33+
{
34+
std::copy(
35+
ipv6.begin(), ipv6.end(), reinterpret_cast<std::byte*>(u8.data()));
36+
}
37+
38+
constexpr bool isIPv4() const noexcept
39+
{
40+
return u32[1] == 0 &&
41+
u32[2] == std::numeric_limits<uint32_t>::max() &&
42+
u32[3] == std::numeric_limits<uint32_t>::max();
43+
}
44+
45+
constexpr bool isIPv6() const noexcept
46+
{
47+
return !isIPv4();
48+
}
49+
50+
constexpr bool operator==(const IPAddress& other) const noexcept
51+
{
52+
return u8 == other.u8;
53+
}
1254

13-
os << "IpAddress{}";
14-
return os;
55+
//constexpr std::strong_ordering operator<=>(const IPAddress& other) const noexcept = default;
56+
57+
constexpr IPAddress& operator=(const IPAddress& other) noexcept
58+
{
59+
if (this != &other) {
60+
u8 = other.u8;
61+
}
62+
return *this;
63+
}
64+
65+
constexpr std::size_t size() const noexcept
66+
{
67+
return isIPv4() ? 4 : 16;
68+
}
69+
70+
std::string toString() const noexcept
71+
{
72+
std::string res;
73+
constexpr std::size_t MAX_IP_AS_TEXT_SIZE = 30;
74+
res.reserve(MAX_IP_AS_TEXT_SIZE);
75+
76+
if (isIPv4()) {
77+
std::for_each_n(reinterpret_cast<const std::byte*>(u8.data()), size(),
78+
[&](const std::byte ipByte) {
79+
std::format_to(std::back_inserter(res), "{}.", static_cast<int>(ipByte));
80+
});
81+
} else {
82+
std::for_each_n(reinterpret_cast<const std::byte*>(u8.data()), size(),
83+
[&](const std::byte ipByte) {
84+
std::format_to(std::back_inserter(res), "{:02x}:", static_cast<int>(ipByte));
85+
});
86+
}
87+
res.pop_back();
88+
return res;
89+
}
90+
};
91+
92+
inline std::ostream& operator<<(std::ostream& os, const IPAddress& ip)
93+
{
94+
return os << ip.toString();
1595
}
1696

1797
} // namespace ipxp

new-process-api/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int main()
1919
processPlugins.disableProcessPlugin("TestDummy");
2020
processPlugins.enableProcessPlugin("TestDummy");
2121

22+
const FlowKeyLayout VlanFlowKeyLayout{20, 4};
2223
FlowRecordBuilder builder(processPlugins.getEntries(), VlanFlowKeyLayout);
2324

2425
builder.printLayoutInfo();

new-process-api/main.o

2.73 MB
Binary file not shown.

new-process-api/packet.hpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,36 @@
11
#pragma once
22

3-
namespace ipxp {
3+
#include <cstdint>
4+
#include <sys/time.h>
5+
#include <span>
6+
#include <optional>
7+
8+
#include "directionalField.hpp"
9+
#include "tcpData.hpp"
10+
#include "flowKey.hpp"
11+
12+
namespace ipxp
13+
{
414

515
struct Packet {
6-
void* payload;
16+
FlowKey flowKey{};
17+
18+
uint64_t timestamp{0};
19+
uint8_t ipTTL{0};
20+
uint8_t ipFlags{0};
21+
uint16_t ipLength{0};
22+
23+
std::optional<TCPData> tcpData{std::nullopt};
24+
25+
uint32_t realLength{0};
26+
//uint32_t receivedLength{0};
27+
28+
Direction direction{Direction::Forward};
29+
30+
std::span<const std::byte> payload;
31+
std::optional<uint32_t> mplsTopLabel;
32+
std::optional<uint16_t> vlanId;
33+
734
};
835

936
struct PacketFeatures {};

0 commit comments

Comments
 (0)