Skip to content

Commit ea2cc3c

Browse files
committed
ipfixprobe - introduce input RAW plugin
1 parent f0840fa commit ea2cc3c

File tree

5 files changed

+67
-62
lines changed

5 files changed

+67
-62
lines changed

src/plugins/input/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
add_subdirectory(parser)
22
add_subdirectory(pcap)
3+
add_subdirectory(raw)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
project(ipfixprobe-input-raw VERSION 1.0.0 DESCRIPTION "ipfixprobe-input-raw plugin")
2+
3+
add_library(ipfixprobe-input-raw MODULE
4+
src/raw.cpp
5+
src/raw.hpp
6+
)
7+
8+
set_target_properties(ipfixprobe-input-raw PROPERTIES
9+
CXX_VISIBILITY_PRESET hidden
10+
VISIBILITY_INLINES_HIDDEN YES
11+
)
12+
13+
target_include_directories(ipfixprobe-input-raw PRIVATE
14+
${CMAKE_SOURCE_DIR}/include/
15+
${CMAKE_SOURCE_DIR}/src/plugins/input/parser
16+
)
17+
18+
target_link_libraries(ipfixprobe-input-raw PRIVATE ipfixprobe-parser)
19+
20+
install(
21+
TARGETS ipfixprobe-input-raw
22+
LIBRARY DESTINATION "${INSTALL_DIR_LIB}/ipfixprobe/input/"
23+
)

src/plugins/input/raw/README.md

Whitespace-only changes.
Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,19 @@
11
/**
2-
* \file raw.cpp
3-
* \brief Packet reader using raw sockets.
4-
* More info at https://www.kernel.org/doc/html/latest/networking/packet_mmap.html
5-
* \author Jiri Havranek <[email protected]>
6-
* \date 2021
7-
*/
8-
/*
9-
* Copyright (C) 2021 CESNET
10-
*
11-
* LICENSE TERMS
12-
*
13-
* Redistribution and use in source and binary forms, with or without
14-
* modification, are permitted provided that the following conditions
15-
* are met:
16-
* 1. Redistributions of source code must retain the above copyright
17-
* notice, this list of conditions and the following disclaimer.
18-
* 2. Redistributions in binary form must reproduce the above copyright
19-
* notice, this list of conditions and the following disclaimer in
20-
* the documentation and/or other materials provided with the
21-
* distribution.
22-
* 3. Neither the name of the Company nor the names of its contributors
23-
* may be used to endorse or promote products derived from this
24-
* software without specific prior written permission.
2+
* @file
3+
* @brief Packet reader using raw sockets
4+
* @author Jiri Havranek <[email protected]>
5+
* @author Pavel Siska <[email protected]>
6+
* @date 2025
257
*
8+
* https://www.kernel.org/doc/html/latest/networking/packet_mmap.html
269
*
10+
* Copyright (c) 2025 CESNET
2711
*
12+
* SPDX-License-Identifier: BSD-3-Clause
2813
*/
2914

30-
#include "raw.hpp"
31-
3215
#include "parser.hpp"
16+
#include "raw.hpp"
3317

3418
#include <cstdlib>
3519
#include <cstring>
@@ -38,10 +22,10 @@
3822

3923
#include <arpa/inet.h>
4024
#include <ifaddrs.h>
41-
#include <linux/if_packet.h>
25+
#include <ipfixprobe/pluginFactory/pluginManifest.hpp>
26+
#include <ipfixprobe/pluginFactory/pluginRegistrar.hpp>
4227
#include <net/ethernet.h>
4328
#include <net/if.h>
44-
#include <poll.h>
4529
#include <sys/ioctl.h>
4630
#include <sys/mman.h>
4731
#include <sys/socket.h>
@@ -57,13 +41,19 @@ namespace ipxp {
5741
// Read only 1 packet into packet block
5842
constexpr size_t RAW_PACKET_BLOCK_SIZE = 1;
5943

60-
__attribute__((constructor)) static void register_this_plugin()
61-
{
62-
static PluginRecord rec = PluginRecord("raw", []() { return new RawReader(); });
63-
register_plugin(&rec);
64-
}
65-
66-
RawReader::RawReader()
44+
static const PluginManifest rawPluginManifest = {
45+
.name = "raw",
46+
.description = "Raw input plugin for reading packets from a raw socket.",
47+
.pluginVersion = "1.0.0",
48+
.apiVersion = "1.0.0",
49+
.usage =
50+
[]() {
51+
RawOptParser parser;
52+
parser.usage(std::cout);
53+
},
54+
};
55+
56+
RawReader::RawReader(const std::string& params)
6757
: m_sock(-1)
6858
, m_fanout(0)
6959
, m_rd(nullptr)
@@ -78,6 +68,7 @@ RawReader::RawReader()
7868
, m_pbd(nullptr)
7969
, m_pkts_left(0)
8070
{
71+
init(params.c_str());
8172
}
8273

8374
RawReader::~RawReader()
@@ -383,4 +374,6 @@ InputPlugin::Result RawReader::get(PacketBlock& packets)
383374
return packets.cnt ? Result::PARSED : Result::NOT_PARSED;
384375
}
385376

377+
static const PluginRegistrar<RawReader, InputPluginFactory> rawRegistrar(rawPluginManifest);
378+
386379
} // namespace ipxp
Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
11
/**
2-
* \file raw.hpp
3-
* \brief Packet reader using raw sockets
4-
* \author Jiri Havranek <[email protected]>
5-
* \date 2021
6-
*/
7-
/*
8-
* Copyright (C) 2021 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-
*
2+
* @file
3+
* @brief Packet reader using raw sockets
4+
* @author Jiri Havranek <[email protected]>
5+
* @author Pavel Siska <[email protected]>
6+
* @date 2025
257
*
8+
* Copyright (c) 2025 CESNET
269
*
10+
* SPDX-License-Identifier: BSD-3-Clause
2711
*/
2812

29-
#ifndef IPXP_INPUT_RAW_HPP
30-
#define IPXP_INPUT_RAW_HPP
13+
#pragma once
14+
15+
#include <cstdint>
16+
#include <exception>
17+
#include <string>
3118

32-
#include <ipfixprobe/input.hpp>
19+
#include <ipfixprobe/inputPlugin.hpp>
3320
#include <ipfixprobe/options.hpp>
3421
#include <ipfixprobe/packet.hpp>
3522
#include <ipfixprobe/utils.hpp>
23+
#include <linux/if_packet.h>
24+
#include <poll.h>
3625

3726
namespace ipxp {
3827

@@ -126,7 +115,7 @@ class RawOptParser : public OptionsParser {
126115

127116
class RawReader : public InputPlugin {
128117
public:
129-
RawReader();
118+
RawReader(const std::string& params);
130119
~RawReader();
131120
void init(const char* params);
132121
void close();
@@ -163,4 +152,3 @@ class RawReader : public InputPlugin {
163152
void packet_handler(u_char* arg, const struct pcap_pkthdr* h, const u_char* data);
164153

165154
} // namespace ipxp
166-
#endif /* IPXP_INPUT_RAW_HPP */

0 commit comments

Comments
 (0)