10
10
11
11
#pragma once
12
12
13
- #include < sstream>
14
13
#include < limits>
15
14
#include < memory>
15
+ #include < sstream>
16
16
17
17
#include < ipfixprobe/flowifc.hpp>
18
18
#include < ipfixprobe/ipfix-basiclist.hpp>
@@ -34,45 +34,45 @@ UR_FIELDS(uint64 TCPRTT_TIME)
34
34
* @param timeval Timeval to convert
35
35
* @return Count of milliseconds since epoch
36
36
*/
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
39
38
{
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;
43
42
}
44
43
45
44
/* *
46
45
* \brief Flow record extension header for storing observed handshake timestamps.
47
46
*/
48
47
struct RecordExtTCPRTT : public RecordExt {
49
48
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
+ }
51
55
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
- }
56
56
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
59
59
60
- RecordExtTCPRTT (int pluginID)
60
+ RecordExtTCPRTT (int pluginID)
61
61
: RecordExt(pluginID)
62
62
{
63
63
}
64
64
65
65
#ifdef WITH_NEMEA
66
66
virtual void fill_unirec (ur_template_t * tmplt, void * record)
67
67
{
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 ));
76
76
ur_set (tmplt, record, F_TCPRTT_TIME, round_trip_time);
77
77
}
78
78
@@ -82,18 +82,18 @@ struct RecordExtTCPRTT : public RecordExt {
82
82
83
83
int fill_ipfix (uint8_t * buffer, int size) override
84
84
{
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;
97
97
return static_cast <int >(sizeof (round_trip_time));
98
98
}
99
99
@@ -108,29 +108,28 @@ struct RecordExtTCPRTT : public RecordExt {
108
108
{
109
109
std::ostringstream out;
110
110
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
+ }
117
117
118
118
return out.str ();
119
119
}
120
120
};
121
121
122
122
class TCPRTTPlugin : public ProcessPlugin {
123
123
public:
124
+ TCPRTTPlugin (const std::string& params, int pluginID);
124
125
125
- TCPRTTPlugin (const std::string& params, int pluginID);
126
-
127
- TCPRTTPlugin (const TCPRTTPlugin&) noexcept ;
126
+ TCPRTTPlugin (const TCPRTTPlugin&) noexcept ;
128
127
129
- ~TCPRTTPlugin () override = default ;
128
+ ~TCPRTTPlugin () override = default ;
130
129
131
- void init (const char * params) override ;
130
+ void init (const char * params) override ;
132
131
133
- OptionsParser* get_parser () const override ;
132
+ OptionsParser* get_parser () const override ;
134
133
135
134
std::string get_name () const override ;
136
135
@@ -143,9 +142,9 @@ class TCPRTTPlugin : public ProcessPlugin {
143
142
int pre_update (Flow& rec, Packet& pkt) override ;
144
143
145
144
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 ;
147
146
148
- std::unique_ptr<RecordExtTCPRTT> m_prealloced_extension{get_ext ()};
147
+ std::unique_ptr<RecordExtTCPRTT> m_prealloced_extension {get_ext ()};
149
148
};
150
149
151
- }
150
+ } // namespace ipxp
0 commit comments