Skip to content

Commit 86e7af1

Browse files
committed
generate empty icmp plugin
1 parent 0868e0a commit 86e7af1

File tree

4 files changed

+241
-3
lines changed

4 files changed

+241
-3
lines changed

Makefile.am

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,16 @@ ipfixprobe_process_src=\
126126
process/md5.cpp \
127127
process/common.hpp \
128128
process/ssadetector.hpp \
129-
process/ssadetector.cpp
129+
process/ssadetector.cpp \
130+
process/icmp.hpp \
131+
process/icmp.cpp
130132

131133
if WITH_QUIC
132134
ipfixprobe_process_src+=\
133135
process/quic.hpp \
134136
process/quic.cpp \
135137
process/quic_parser.cpp \
136-
process/quic_parser.hpp
138+
process/quic_parser.hpp
137139

138140
endif
139141

include/ipfixprobe/ipfix-elements.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ namespace ipxp {
502502
F(OSQUERY_KERNEL_VERSION) \
503503
F(OSQUERY_SYSTEM_HOSTNAME)
504504

505+
#define IPFIX_ICMP_TEMPLATE(F) \
506+
F(L4_ICMP_TYPE_CODE)
507+
505508
#ifdef WITH_FLEXPROBE
506509
#define IPFIX_FLEXPROBE_DATA_TEMPLATE(F) F(FX_FRAME_SIGNATURE) F(FX_INPUT_INTERFACE)
507510
#define IPFIX_FLEXPROBE_TCP_TEMPLATE(F) F(FX_TCP_TRACKING)
@@ -544,7 +547,8 @@ namespace ipxp {
544547
IPFIX_FLEXPROBE_DATA_TEMPLATE(F) \
545548
IPFIX_FLEXPROBE_TCP_TEMPLATE(F) \
546549
IPFIX_FLEXPROBE_ENCR_TEMPLATE(F) \
547-
IPFIX_SSADETECTOR_TEMPLATE(F)
550+
IPFIX_SSADETECTOR_TEMPLATE(F) \
551+
IPFIX_ICMP_TEMPLATE(F)
548552

549553
/**
550554
* Helper macro, convert FIELD into its name as a C literal.

process/icmp.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* \file icmp.cpp
3+
* \brief Plugin for parsing icmp traffic.
4+
* \author Jakub Antonín Štigler xstigl00@[email protected]
5+
* \date 2023
6+
*/
7+
/*
8+
* Copyright (C) 2023 CESNET
9+
*
10+
* LICENSE TERMS
11+
*
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions
14+
* are met:
15+
* 1. Redistributions of source code must retain the above copyright
16+
* notice, this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright
18+
* notice, this list of conditions and the following disclaimer in
19+
* the documentation and/or other materials provided with the
20+
* distribution.
21+
* 3. Neither the name of the Company nor the names of its contributors
22+
* may be used to endorse or promote products derived from this
23+
* software without specific prior written permission.
24+
*
25+
* ALTERNATIVELY, provided that this notice is retained in full, this
26+
* product may be distributed under the terms of the GNU General Public
27+
* License (GPL) version 2 or later, in which case the provisions
28+
* of the GPL apply INSTEAD OF those given above.
29+
*
30+
* This software is provided as is'', and any express or implied
31+
* warranties, including, but not limited to, the implied warranties of
32+
* merchantability and fitness for a particular purpose are disclaimed.
33+
* In no event shall the company or contributors be liable for any
34+
* direct, indirect, incidental, special, exemplary, or consequential
35+
* damages (including, but not limited to, procurement of substitute
36+
* goods or services; loss of use, data, or profits; or business
37+
* interruption) however caused and on any theory of liability, whether
38+
* in contract, strict liability, or tort (including negligence or
39+
* otherwise) arising in any way out of the use of this software, even
40+
* if advised of the possibility of such damage.
41+
*
42+
*/
43+
44+
#include <iostream>
45+
46+
#include "icmp.hpp"
47+
48+
namespace ipxp {
49+
50+
int RecordExtICMP::REGISTERED_ID = -1;
51+
52+
__attribute__((constructor)) static void register_this_plugin()
53+
{
54+
static PluginRecord rec = PluginRecord("icmp", [](){return new ICMPPlugin();});
55+
register_plugin(&rec);
56+
RecordExtICMP::REGISTERED_ID = register_extension();
57+
}
58+
59+
ICMPPlugin::ICMPPlugin()
60+
{
61+
}
62+
63+
ICMPPlugin::~ICMPPlugin()
64+
{
65+
}
66+
67+
void ICMPPlugin::init(const char *params)
68+
{
69+
}
70+
71+
void ICMPPlugin::close()
72+
{
73+
}
74+
75+
ProcessPlugin *ICMPPlugin::copy()
76+
{
77+
return new ICMPPlugin(*this);
78+
}
79+
80+
int ICMPPlugin::pre_create(Packet &pkt)
81+
{
82+
return 0;
83+
}
84+
85+
int ICMPPlugin::post_create(Flow &rec, const Packet &pkt)
86+
{
87+
return 0;
88+
}
89+
90+
int ICMPPlugin::pre_update(Flow &rec, Packet &pkt)
91+
{
92+
return 0;
93+
}
94+
95+
int ICMPPlugin::post_update(Flow &rec, const Packet &pkt)
96+
{
97+
return 0;
98+
}
99+
100+
void ICMPPlugin::pre_export(Flow &rec)
101+
{
102+
}
103+
104+
}
105+

process/icmp.hpp

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* \file icmp.hpp
3+
* \brief Plugin for parsing icmp traffic.
4+
* \author Jakub Antonín Štigler xstigl00@[email protected]
5+
* \date 2023
6+
*/
7+
/*
8+
* Copyright (C) 2023 CESNET
9+
*
10+
* LICENSE TERMS
11+
*
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions
14+
* are met:
15+
* 1. Redistributions of source code must retain the above copyright
16+
* notice, this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright
18+
* notice, this list of conditions and the following disclaimer in
19+
* the documentation and/or other materials provided with the
20+
* distribution.
21+
* 3. Neither the name of the Company nor the names of its contributors
22+
* may be used to endorse or promote products derived from this
23+
* software without specific prior written permission.
24+
*
25+
* ALTERNATIVELY, provided that this notice is retained in full, this
26+
* product may be distributed under the terms of the GNU General Public
27+
* License (GPL) version 2 or later, in which case the provisions
28+
* of the GPL apply INSTEAD OF those given above.
29+
*
30+
* This software is provided as is'', and any express or implied
31+
* warranties, including, but not limited to, the implied warranties of
32+
* merchantability and fitness for a particular purpose are disclaimed.
33+
* In no event shall the company or contributors be liable for any
34+
* direct, indirect, incidental, special, exemplary, or consequential
35+
* damages (including, but not limited to, procurement of substitute
36+
* goods or services; loss of use, data, or profits; or business
37+
* interruption) however caused and on any theory of liability, whether
38+
* in contract, strict liability, or tort (including negligence or
39+
* otherwise) arising in any way out of the use of this software, even
40+
* if advised of the possibility of such damage.
41+
*
42+
*/
43+
44+
#ifndef IPXP_PROCESS_ICMP_HPP
45+
#define IPXP_PROCESS_ICMP_HPP
46+
47+
#include <cstring>
48+
49+
#ifdef WITH_NEMEA
50+
#include "fields.h"
51+
#endif
52+
53+
#include <ipfixprobe/process.hpp>
54+
#include <ipfixprobe/flowifc.hpp>
55+
#include <ipfixprobe/packet.hpp>
56+
#include <ipfixprobe/ipfix-elements.hpp>
57+
58+
namespace ipxp {
59+
60+
#define ICMP_UNIREC_TEMPLATE "ICMP_TYPE,ICMP_CODE"
61+
62+
UR_FIELDS (
63+
uint8 ICMP_TYPE,
64+
uint8 ICMP_CODE
65+
)
66+
67+
/**
68+
* \brief Flow record extension header for storing parsed ICMP data.
69+
*/
70+
struct RecordExtICMP : public RecordExt {
71+
static int REGISTERED_ID;
72+
73+
RecordExtICMP() : RecordExt(REGISTERED_ID)
74+
{
75+
}
76+
77+
#ifdef WITH_NEMEA
78+
virtual void fill_unirec(ur_template_t *tmplt, void *record)
79+
{
80+
}
81+
82+
const char *get_unirec_tmplt() const
83+
{
84+
return ICMP_UNIREC_TEMPLATE;
85+
}
86+
#endif
87+
88+
virtual int fill_ipfix(uint8_t *buffer, int size)
89+
{
90+
return 0;
91+
}
92+
93+
const char **get_ipfix_tmplt() const
94+
{
95+
static const char *ipfix_template[] = {
96+
IPFIX_ICMP_TEMPLATE(IPFIX_FIELD_NAMES)
97+
NULL
98+
};
99+
return ipfix_template;
100+
}
101+
};
102+
103+
/**
104+
* \brief Process plugin for parsing ICMP packets.
105+
*/
106+
class ICMPPlugin : public ProcessPlugin
107+
{
108+
public:
109+
ICMPPlugin();
110+
~ICMPPlugin();
111+
void init(const char *params);
112+
void close();
113+
OptionsParser *get_parser() const { return new OptionsParser("icmp", "Parse ICMP traffic"); }
114+
std::string get_name() const { return "icmp"; }
115+
RecordExt *get_ext() const { return new RecordExtICMP(); }
116+
ProcessPlugin *copy();
117+
118+
int pre_create(Packet &pkt);
119+
int post_create(Flow &rec, const Packet &pkt);
120+
int pre_update(Flow &rec, Packet &pkt);
121+
int post_update(Flow &rec, const Packet &pkt);
122+
void pre_export(Flow &rec);
123+
};
124+
125+
}
126+
#endif /* IPXP_PROCESS_ICMP_HPP */
127+

0 commit comments

Comments
 (0)