Skip to content

Commit a047978

Browse files
author
Damir Zainullin
committed
++
1 parent 8fc61c7 commit a047978

File tree

1 file changed

+48
-49
lines changed

1 file changed

+48
-49
lines changed

src/plugins/process/tcpRtt/src/tcpRtt.hpp

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
#pragma once
1212

13-
#include <sstream>
1413
#include <limits>
1514
#include <memory>
15+
#include <sstream>
1616

1717
#include <ipfixprobe/flowifc.hpp>
1818
#include <ipfixprobe/ipfix-basiclist.hpp>
@@ -34,45 +34,45 @@ UR_FIELDS(uint64 TCPRTT_TIME)
3434
* @param timeval Timeval to convert
3535
* @return Count of milliseconds since epoch
3636
*/
37-
constexpr static inline
38-
uint64_t timeval_to_msec(timeval timeval) noexcept
37+
constexpr static inline uint64_t timeval_to_msec(timeval timeval) noexcept
3938
{
40-
constexpr size_t MSEC_IN_SEC = 1'000;
41-
constexpr size_t USEC_IN_MSEC = 1'000;
42-
return timeval.tv_sec * MSEC_IN_SEC + timeval.tv_usec / USEC_IN_MSEC;
39+
constexpr size_t MSEC_IN_SEC = 1'000;
40+
constexpr size_t USEC_IN_MSEC = 1'000;
41+
return timeval.tv_sec * MSEC_IN_SEC + timeval.tv_usec / USEC_IN_MSEC;
4342
}
4443

4544
/**
4645
* \brief Flow record extension header for storing observed handshake timestamps.
4746
*/
4847
struct RecordExtTCPRTT : public RecordExt {
4948
private:
50-
constexpr static timeval NO_TIMESTAMP = timeval{std::numeric_limits<time_t>::min(), 0};
49+
constexpr static timeval NO_TIMESTAMP = timeval {std::numeric_limits<time_t>::min(), 0};
50+
51+
constexpr inline static bool has_no_value(timeval timeval) noexcept
52+
{
53+
return timeval.tv_sec == NO_TIMESTAMP.tv_sec && timeval.tv_usec == NO_TIMESTAMP.tv_usec;
54+
}
5155

52-
constexpr inline static bool has_no_value(timeval timeval) noexcept
53-
{
54-
return timeval.tv_sec == NO_TIMESTAMP.tv_sec && timeval.tv_usec == NO_TIMESTAMP.tv_usec;
55-
}
5656
public:
57-
timeval tcp_syn_timestamp{NO_TIMESTAMP}; ///< Timestamp of last observed TCP SYN packet
58-
timeval tcp_synack_timestamp{NO_TIMESTAMP}; ///< Timestamp of last observed TCP SYNACK packet
57+
timeval tcp_syn_timestamp {NO_TIMESTAMP}; ///< Timestamp of last observed TCP SYN packet
58+
timeval tcp_synack_timestamp {NO_TIMESTAMP}; ///< Timestamp of last observed TCP SYNACK packet
5959

60-
RecordExtTCPRTT(int pluginID)
60+
RecordExtTCPRTT(int pluginID)
6161
: RecordExt(pluginID)
6262
{
6363
}
6464

6565
#ifdef WITH_NEMEA
6666
virtual void fill_unirec(ur_template_t* tmplt, void* record)
6767
{
68-
if (has_no_value(tcp_syn_timestamp) || has_no_value(tcp_synack_timestamp)) {
69-
ur_set(tmplt, record, F_TCPRTT_TIME, std::numeric_limits<uint64_t>::max());
70-
return;
71-
}
72-
73-
const ur_time_t round_trip_time = ur_timediff(
74-
ur_time_from_sec_usec(tcp_synack_timestamp.tv_sec, tcp_synack_timestamp.tv_usec),
75-
ur_time_from_sec_usec(tcp_syn_timestamp.tv_sec, tcp_syn_timestamp.tv_usec));
68+
if (has_no_value(tcp_syn_timestamp) || has_no_value(tcp_synack_timestamp)) {
69+
ur_set(tmplt, record, F_TCPRTT_TIME, std::numeric_limits<uint64_t>::max());
70+
return;
71+
}
72+
73+
const ur_time_t round_trip_time = ur_timediff(
74+
ur_time_from_sec_usec(tcp_synack_timestamp.tv_sec, tcp_synack_timestamp.tv_usec),
75+
ur_time_from_sec_usec(tcp_syn_timestamp.tv_sec, tcp_syn_timestamp.tv_usec));
7676
ur_set(tmplt, record, F_TCPRTT_TIME, round_trip_time);
7777
}
7878

@@ -82,18 +82,18 @@ struct RecordExtTCPRTT : public RecordExt {
8282

8383
int fill_ipfix(uint8_t* buffer, int size) override
8484
{
85-
if (size < static_cast<ssize_t>(sizeof(uint64_t))) {
86-
return -1;
87-
}
88-
89-
if (has_no_value(tcp_syn_timestamp) || has_no_value(tcp_synack_timestamp)) {
90-
*reinterpret_cast<uint64_t*>(buffer) = std::numeric_limits<uint64_t>::max();
91-
return static_cast<int>(sizeof(uint64_t));
92-
}
93-
94-
const uint64_t round_trip_time =
95-
timeval_to_msec(tcp_synack_timestamp) - timeval_to_msec(tcp_syn_timestamp);
96-
*reinterpret_cast<uint64_t*>(buffer) = round_trip_time;
85+
if (size < static_cast<ssize_t>(sizeof(uint64_t))) {
86+
return -1;
87+
}
88+
89+
if (has_no_value(tcp_syn_timestamp) || has_no_value(tcp_synack_timestamp)) {
90+
*reinterpret_cast<uint64_t*>(buffer) = std::numeric_limits<uint64_t>::max();
91+
return static_cast<int>(sizeof(uint64_t));
92+
}
93+
94+
const uint64_t round_trip_time
95+
= timeval_to_msec(tcp_synack_timestamp) - timeval_to_msec(tcp_syn_timestamp);
96+
*reinterpret_cast<uint64_t*>(buffer) = round_trip_time;
9797
return static_cast<int>(sizeof(round_trip_time));
9898
}
9999

@@ -108,29 +108,28 @@ struct RecordExtTCPRTT : public RecordExt {
108108
{
109109
std::ostringstream out;
110110

111-
if (has_no_value(tcp_syn_timestamp) || has_no_value(tcp_synack_timestamp)) {
112-
out << "tcprtt = UNKNOWN";
113-
} else {
114-
out << "tcprtt = " <<
115-
timeval_to_msec(tcp_synack_timestamp) - timeval_to_msec(tcp_syn_timestamp);
116-
}
111+
if (has_no_value(tcp_syn_timestamp) || has_no_value(tcp_synack_timestamp)) {
112+
out << "tcprtt = UNKNOWN";
113+
} else {
114+
out << "tcprtt = "
115+
<< timeval_to_msec(tcp_synack_timestamp) - timeval_to_msec(tcp_syn_timestamp);
116+
}
117117

118118
return out.str();
119119
}
120120
};
121121

122122
class TCPRTTPlugin : public ProcessPlugin {
123123
public:
124+
TCPRTTPlugin(const std::string& params, int pluginID);
124125

125-
TCPRTTPlugin(const std::string& params, int pluginID);
126-
127-
TCPRTTPlugin(const TCPRTTPlugin&) noexcept;
126+
TCPRTTPlugin(const TCPRTTPlugin&) noexcept;
128127

129-
~TCPRTTPlugin() override = default;
128+
~TCPRTTPlugin() override = default;
130129

131-
void init(const char* params) override;
130+
void init(const char* params) override;
132131

133-
OptionsParser* get_parser() const override;
132+
OptionsParser* get_parser() const override;
134133

135134
std::string get_name() const override;
136135

@@ -143,9 +142,9 @@ class TCPRTTPlugin : public ProcessPlugin {
143142
int pre_update(Flow& rec, Packet& pkt) override;
144143

145144
private:
146-
void update_tcp_rtt_record(Flow& rec, const Packet& pkt) noexcept;
145+
void update_tcp_rtt_record(Flow& rec, const Packet& pkt) noexcept;
147146

148-
std::unique_ptr<RecordExtTCPRTT> m_prealloced_extension{get_ext()};
147+
std::unique_ptr<RecordExtTCPRTT> m_prealloced_extension {get_ext()};
149148
};
150149

151-
}
150+
} // namespace ipxp

0 commit comments

Comments
 (0)