Skip to content

Commit 10cc914

Browse files
committed
ipfixprobe - introduce input PCAP plugin
1 parent 4a10df0 commit 10cc914

File tree

5 files changed

+58
-59
lines changed

5 files changed

+58
-59
lines changed

src/plugins/input/CMakeLists.txt

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

src/plugins/input/pcap/README.md

Whitespace-only changes.
Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,24 @@
11
/**
2-
* \file pcap.cpp
3-
* \brief Pcap reader based on libpcap
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 Pcap reader based on libpcap
4+
* @author Jiri Havranek <[email protected]>
5+
* @date 2025
256
*
7+
* Copyright (c) 2025 CESNET
268
*
9+
* SPDX-License-Identifier: BSD-3-Clause
2710
*/
2811

29-
#include "pcap.hpp"
30-
3112
#include "parser.hpp"
13+
#include "pcap.hpp"
3214

3315
#include <cstdio>
3416
#include <cstring>
3517
#include <iomanip>
3618
#include <iostream>
3719

20+
#include <ipfixprobe/pluginFactory/pluginManifest.hpp>
21+
#include <ipfixprobe/pluginFactory/pluginRegistrar.hpp>
3822
#include <pcap/pcap.h>
3923

4024
namespace ipxp {
@@ -47,11 +31,15 @@ struct UserData {
4731
ParserStats& stats;
4832
};
4933

50-
__attribute__((constructor)) static void register_this_plugin()
51-
{
52-
static PluginRecord rec = PluginRecord("pcap", []() { return new PcapReader(); });
53-
register_plugin(&rec);
54-
}
34+
static const PluginManifest pcapPluginManifest
35+
= {.name = "pcap",
36+
.description = "Pcap input plugin for reading packets from network interface or pcap file.",
37+
.pluginVersion = "1.0.0",
38+
.apiVersion = "1.0.0",
39+
.usage = []() {
40+
PcapOptParser parser;
41+
parser.usage(std::cout);
42+
}};
5543

5644
/**
5745
* \brief Parsing callback function for pcap_dispatch() call. Parse packets up to transport layer.
@@ -79,13 +67,14 @@ void packet_handler(u_char* arg, const struct pcap_pkthdr* h, const u_char* data
7967
#endif
8068
}
8169

82-
PcapReader::PcapReader()
70+
PcapReader::PcapReader(const std::string& params)
8371
: m_handle(nullptr)
8472
, m_snaplen(-1)
8573
, m_datalink(0)
8674
, m_live(false)
8775
, m_netmask(PCAP_NETMASK_UNKNOWN)
8876
{
77+
init(params.c_str());
8978
}
9079

9180
PcapReader::~PcapReader()
@@ -301,4 +290,6 @@ InputPlugin::Result PcapReader::get(PacketBlock& packets)
301290
return Result::NOT_PARSED;
302291
}
303292

293+
static const PluginRegistrar<PcapReader, InputPluginFactory> pcapRegistrar(pcapPluginManifest);
294+
304295
} // namespace ipxp
Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11
/**
2-
* \file pcap.hpp
3-
* \brief Pcap reader based on libpcap
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 Pcap reader based on libpcap
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_PCAP_HPP
30-
#define IPXP_INPUT_PCAP_HPP
13+
#pragma once
3114

32-
#include <ipfixprobe/input.hpp>
15+
#include <ipfixprobe/inputPlugin.hpp>
3316
#include <ipfixprobe/options.hpp>
3417
#include <ipfixprobe/packet.hpp>
3518
#include <ipfixprobe/utils.hpp>
@@ -132,7 +115,7 @@ class PcapOptParser : public OptionsParser {
132115
*/
133116
class PcapReader : public InputPlugin {
134117
public:
135-
PcapReader();
118+
PcapReader(const std::string& params);
136119
~PcapReader();
137120

138121
void init(const char* params);
@@ -159,4 +142,3 @@ class PcapReader : public InputPlugin {
159142
void packet_handler(u_char* arg, const struct pcap_pkthdr* h, const u_char* data);
160143

161144
} // namespace ipxp
162-
#endif /* IPXP_INPUT_PCAP_HPP */

0 commit comments

Comments
 (0)