|
| 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