Skip to content

Commit 0c4bc43

Browse files
author
Damir Zainullin
committed
++
1 parent c52a883 commit 0c4bc43

File tree

4 files changed

+52
-48
lines changed

4 files changed

+52
-48
lines changed

include/ipfixprobe/flowifc.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
#include <sys/time.h>
4040

4141
#ifdef WITH_NEMEA
42-
#include <unirec/unirec.h>
42+
//#include <unirec/unirec.h>
4343
#else
44-
#define UR_FIELDS(...)
44+
//#define UR_FIELDS(...)
4545
#endif
4646

4747
#include "ipaddr.hpp"
@@ -80,17 +80,17 @@ struct RecordExt {
8080
* \param [in] tmplt Unirec template.
8181
* \param [out] record Pointer to the unirec record.
8282
*/
83-
virtual void fill_unirec(ur_template_t* tmplt, void* record)
83+
/*virtual void fill_unirec(ur_template_t* tmplt, void* record)
8484
{
8585
(void) tmplt;
8686
(void) record;
87-
}
87+
}*/
8888

8989
/**
9090
* \brief Get unirec template string.
9191
* \return Unirec template string.
9292
*/
93-
virtual const char* get_unirec_tmplt() const { return ""; }
93+
//virtual const char* get_unirec_tmplt() const { return ""; }
9494
#endif
9595

9696
/**

include/ipfixprobe/processPlugin/flowRecord.hpp

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -124,44 +124,38 @@ class FlowRecord {
124124
return hash == value;
125125
}*/
126126

127-
void createFrom(const Packet& packet)
127+
// TODO remove hashval
128+
void createFrom(const Packet& packet, uint64_t hashval)
128129
{
129-
m_flow.directionalData[Direction::Forward].packets = 1;
130-
131-
m_hash = hash;
132-
133-
m_flow.time_first = pkt.ts;
134-
m_flow.time_last = pkt.ts;
135-
m_flow.flow_hash = hash;
136-
137-
memcpy(m_flow.src_mac, pkt.src_mac, 6);
138-
memcpy(m_flow.dst_mac, pkt.dst_mac, 6);
139-
140-
if (pkt.ip_version == IP::v4) {
141-
m_flow.ip_version = pkt.ip_version;
142-
m_flow.ip_proto = pkt.ip_proto;
143-
m_flow.src_ip.v4 = pkt.src_ip.v4;
144-
m_flow.dst_ip.v4 = pkt.dst_ip.v4;
145-
m_flow.src_bytes = pkt.ip_len;
146-
} else if (pkt.ip_version == IP::v6) {
147-
m_flow.ip_version = pkt.ip_version;
148-
m_flow.ip_proto = pkt.ip_proto;
149-
memcpy(m_flow.src_ip.v6, pkt.src_ip.v6, 16);
150-
memcpy(m_flow.dst_ip.v6, pkt.dst_ip.v6, 16);
151-
m_flow.src_bytes = pkt.ip_len;
130+
directionalData[Direction::Forward].packets = 1;
131+
directionalData[Direction::Forward].bytes = packet.ip_len;
132+
133+
134+
flowKey.srcPort = packet.src_port;
135+
flowKey.dstPort = packet.dst_port;
136+
flowKey.l4Protocol = packet.ip_proto;
137+
138+
hash = hashval;
139+
140+
timeCreation = packet.ts;
141+
timeLastUpdate = packet.ts;
142+
143+
macAddress[Direction::Forward]
144+
= std::span<const std::byte, 6>(
145+
reinterpret_cast<const std::byte*>(packet.src_mac), 6);
146+
macAddress[Direction::Reverse]
147+
= std::span<const std::byte, 6>(
148+
reinterpret_cast<const std::byte*>(packet.dst_mac), 6);
149+
150+
if (packet.ip_version == IP::v4) {
151+
flowKey.srcIp = packet.src_ip.v4;
152+
flowKey.dstIp = packet.dst_ip.v4;
153+
} else if (packet.ip_version == IP::v6) {
154+
flowKey.srcIp = std::span<const std::byte, 16>(
155+
reinterpret_cast<const std::byte*>(packet.src_ip.v6), 16);
156+
flowKey.dstIp = std::span<const std::byte, 16>(
157+
reinterpret_cast<const std::byte*>(packet.dst_ip.v6), 16);
152158
}
153-
154-
if (pkt.ip_proto == IPPROTO_TCP) {
155-
m_flow.src_port = pkt.src_port;
156-
m_flow.dst_port = pkt.dst_port;
157-
m_flow.src_tcp_flags = pkt.tcp_flags;
158-
} else if (pkt.ip_proto == IPPROTO_UDP) {
159-
m_flow.src_port = pkt.src_port;
160-
m_flow.dst_port = pkt.dst_port;
161-
} else if (pkt.ip_proto == IPPROTO_ICMP || pkt.ip_proto == IPPROTO_ICMPV6) {
162-
m_flow.src_port = pkt.src_port;
163-
m_flow.dst_port = pkt.dst_port;
164-
}*/
165159
}
166160

167161
void update(const Packet& packet, bool src)

include/ipfixprobe/processPlugin/macAddress.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ struct MACAddress {
2121
{
2222
std::ranges::copy(address, this->address.begin());
2323
}
24+
25+
constexpr MACAddress& operator=(std::span<const std::byte, 6> address) noexcept
26+
{
27+
if (address.data() == this->address.data()) {
28+
return *this;
29+
}
30+
31+
std::ranges::copy(address, this->address.begin());
32+
return *this;
33+
}
2434
};
2535

2636
inline std::ostream& operator<<(std::ostream& os, const MACAddress& mac)

src/plugins/storage/cache/src/cache.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void NHTFlowCache::export_flow(size_t index)
180180
void NHTFlowCache::finish()
181181
{
182182
for (decltype(m_cache_size) i = 0; i < m_cache_size; i++) {
183-
if (!m_flow_table[i]->is_empty()) {
183+
if (!m_flow_table[i]->isEmpty()) {
184184
//plugins_pre_export(m_flow_table[i]->m_flow);
185185
m_flow_table[i]->endReason = FlowEndReason::FLOW_END_FORCED;
186186
export_flow(i);
@@ -250,7 +250,7 @@ int NHTFlowCache::put_pkt(Packet& pkt)
250250

251251
/* Find existing flow record in flow cache. */
252252
for (flow_index = line_index; flow_index < next_line; flow_index++) {
253-
if (m_flow_table[flow_index]->belongs(hashval)) {
253+
if (m_flow_table[flow_index]->hash == hashval) {
254254
found = true;
255255
break;
256256
}
@@ -262,7 +262,7 @@ int NHTFlowCache::put_pkt(Packet& pkt)
262262
uint64_t line_index_inv = hashval_inv & m_line_mask;
263263
uint64_t next_line_inv = line_index_inv + m_line_size;
264264
for (flow_index = line_index_inv; flow_index < next_line_inv; flow_index++) {
265-
if (m_flow_table[flow_index]->belongs(hashval_inv)) {
265+
if (m_flow_table[flow_index]->hash == hashval_inv) {
266266
found = true;
267267
source_flow = false;
268268
hashval = hashval_inv;
@@ -292,7 +292,7 @@ int NHTFlowCache::put_pkt(Packet& pkt)
292292
} else {
293293
/* Existing flow record was not found. Find free place in flow line. */
294294
for (flow_index = line_index; flow_index < next_line; flow_index++) {
295-
if (m_flow_table[flow_index]->is_empty()) {
295+
if (m_flow_table[flow_index]->isEmpty()) {
296296
found = true;
297297
break;
298298
}
@@ -337,9 +337,9 @@ int NHTFlowCache::put_pkt(Packet& pkt)
337337
return 0;
338338
}
339339

340-
if (flow->is_empty()) {
340+
if (flow->isEmpty()) {
341341
m_flows_in_cache++;
342-
flow->create(pkt, hashval);
342+
flow->createFrom(pkt, hashval);
343343
ret = 0; //plugins_post_create(flow->m_flow, pkt);
344344

345345
//if (ret & FLOW_FLUSH) {
@@ -408,7 +408,7 @@ uint8_t NHTFlowCache::get_export_reason(FlowRecord& flow)
408408
void NHTFlowCache::export_expired(time_t ts)
409409
{
410410
for (decltype(m_timeout_idx) i = m_timeout_idx; i < m_timeout_idx + m_line_new_idx; i++) {
411-
if (!m_flow_table[i]->is_empty()
411+
if (!m_flow_table[i]->isEmpty()
412412
&& ts - m_flow_table[i]->timeLastUpdate.toSeconds() >= m_inactive) {
413413
m_flow_table[i]->endReason = static_cast<FlowEndReason>(get_export_reason(*m_flow_table[i]));
414414
m_manager.exportFlowRecord(*m_flow_table[i]);

0 commit comments

Comments
 (0)