Skip to content

Commit 17fa6eb

Browse files
hynekkarPavel Siska
authored andcommitted
Refactor: Fixed coding style in QUIC and TLS process plugins, parsers
1 parent 8e931d7 commit 17fa6eb

File tree

8 files changed

+1134
-1202
lines changed

8 files changed

+1134
-1202
lines changed

process/quic.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@
4242
*/
4343

4444
#ifdef WITH_NEMEA
45-
#include <unirec/unirec.h>
45+
# include <unirec/unirec.h>
4646
#endif
4747

4848

4949
#include "quic.hpp"
5050

5151
namespace ipxp {
52-
5352
int RecordExtQUIC::REGISTERED_ID = -1;
5453

5554
__attribute__((constructor)) static void register_this_plugin()
5655
{
57-
static PluginRecord rec = PluginRecord("quic", [](){return new QUICPlugin();});
56+
static PluginRecord rec = PluginRecord("quic", [](){
57+
return new QUICPlugin();
58+
});
59+
5860
register_plugin(&rec);
5961
RecordExtQUIC::REGISTERED_ID = register_extension();
6062
}
63+
6164
QUICPlugin::QUICPlugin()
6265
{
6366
quic_ptr = nullptr;
@@ -69,8 +72,7 @@ QUICPlugin::~QUICPlugin()
6972
}
7073

7174
void QUICPlugin::init(const char *params)
72-
{
73-
}
75+
{ }
7476

7577
void QUICPlugin::close()
7678
{
@@ -87,15 +89,11 @@ ProcessPlugin *QUICPlugin::copy()
8789

8890
bool QUICPlugin::process_quic(RecordExtQUIC *quic_data, const Packet &pkt)
8991
{
90-
9192
QUICParser process_quic;
9293

93-
if (!process_quic.quic_start(pkt))
94-
{
94+
if (!process_quic.quic_start(pkt)) {
9595
return false;
96-
}
97-
else
98-
{
96+
} else {
9997
process_quic.quic_get_sni(quic_data->sni);
10098
process_quic.quic_get_user_agent(quic_data->user_agent);
10199
process_quic.quic_get_version(quic_data->quic_version);
@@ -104,7 +102,7 @@ bool QUICPlugin::process_quic(RecordExtQUIC *quic_data, const Packet &pkt)
104102
} // QUICPlugin::process_quic
105103

106104
int QUICPlugin::pre_create(Packet &pkt)
107-
{
105+
{
108106
return 0;
109107
}
110108

@@ -150,5 +148,4 @@ void QUICPlugin::finish(bool print_stats)
150148
std::cout << " Parsed SNI: " << parsed_initial << std::endl;
151149
}
152150
}
153-
154151
}

process/quic.hpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@
4545
#define IPXP_PROCESS_QUIC_HPP
4646

4747

48-
4948
#ifdef WITH_NEMEA
50-
#include "fields.h"
49+
# include "fields.h"
5150
#endif
5251

5352

@@ -58,7 +57,6 @@
5857

5958

6059
namespace ipxp {
61-
6260
#define QUIC_UNIREC_TEMPLATE "QUIC_SNI,QUIC_USER_AGENT,QUIC_VERSION"
6361
UR_FIELDS(
6462
string QUIC_SNI,
@@ -71,15 +69,15 @@ UR_FIELDS(
7169
*/
7270
struct RecordExtQUIC : public RecordExt {
7371
static int REGISTERED_ID;
74-
char sni[BUFF_SIZE] = { 0 };
75-
char user_agent[BUFF_SIZE] = { 0 };
76-
uint32_t quic_version;
72+
char sni[BUFF_SIZE] = { 0 };
73+
char user_agent[BUFF_SIZE] = { 0 };
74+
uint32_t quic_version;
7775

7876
RecordExtQUIC() : RecordExt(REGISTERED_ID)
7977
{
80-
sni[0] = 0;
78+
sni[0] = 0;
8179
user_agent[0] = 0;
82-
quic_version = 0;
80+
quic_version = 0;
8381
}
8482

8583
#ifdef WITH_NEMEA
@@ -94,22 +92,23 @@ struct RecordExtQUIC : public RecordExt {
9492
{
9593
return QUIC_UNIREC_TEMPLATE;
9694
}
97-
#endif
95+
96+
#endif // ifdef WITH_NEMEA
9897

9998
virtual int fill_ipfix(uint8_t *buffer, int size)
10099
{
101-
uint16_t len_sni = strlen(sni);
100+
uint16_t len_sni = strlen(sni);
102101
uint16_t len_user_agent = strlen(user_agent);
103-
uint16_t len_version = sizeof(quic_version);
102+
uint16_t len_version = sizeof(quic_version);
104103
int pos = 0;
105104

106105
if ((len_sni + 3) + (len_user_agent + 3) + len_version > size) {
107106
return -1;
108107
}
109108

110-
pos += variable2ipfix_buffer(buffer + pos, (uint8_t*) sni, len_sni);
111-
pos += variable2ipfix_buffer(buffer + pos, (uint8_t*) user_agent, len_user_agent);
112-
*(uint32_t *)(buffer + pos) = htonl(quic_version);
109+
pos += variable2ipfix_buffer(buffer + pos, (uint8_t *) sni, len_sni);
110+
pos += variable2ipfix_buffer(buffer + pos, (uint8_t *) user_agent, len_user_agent);
111+
*(uint32_t *) (buffer + pos) = htonl(quic_version);
113112
pos += len_version;
114113
return pos;
115114
}
@@ -120,13 +119,16 @@ struct RecordExtQUIC : public RecordExt {
120119
IPFIX_QUIC_TEMPLATE(IPFIX_FIELD_NAMES)
121120
nullptr
122121
};
122+
123123
return ipfix_template;
124124
}
125125

126126
std::string get_text() const
127127
{
128128
std::ostringstream out;
129-
out << "quicsni=\"" << sni << "\"" << "quicuseragent=\"" << user_agent << "\"" << "quicversion=\"" << quic_version << "\"";
129+
130+
out << "quicsni=\"" << sni << "\"" << "quicuseragent=\"" << user_agent << "\"" << "quicversion=\"" <<
131+
quic_version << "\"";
130132
return out.str();
131133
}
132134
};
@@ -142,8 +144,11 @@ class QUICPlugin : public ProcessPlugin
142144
void init(const char *params);
143145
void close();
144146
RecordExt *get_ext() const { return new RecordExtQUIC(); }
147+
145148
OptionsParser *get_parser() const { return new OptionsParser("quic", "Parse QUIC traffic"); }
149+
146150
std::string get_name() const { return "quic"; }
151+
147152
ProcessPlugin *copy();
148153

149154
int pre_create(Packet &pkt);
@@ -158,6 +163,5 @@ class QUICPlugin : public ProcessPlugin
158163
int parsed_initial;
159164
RecordExtQUIC *quic_ptr;
160165
};
161-
162166
}
163167
#endif /* IPXP_PROCESS_QUIC_HPP */

0 commit comments

Comments
 (0)