Skip to content

Commit 984db05

Browse files
author
Pavel Siska
committed
ipfixprobe - introduce process DNS plugin
1 parent 3f0e3d0 commit 984db05

File tree

5 files changed

+55
-66
lines changed

5 files changed

+55
-66
lines changed

src/plugins/process/CMakeLists.txt

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

src/plugins/process/dns/README.md

Whitespace-only changes.
Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,41 @@
11
/**
2-
* \file dns.cpp
3-
* \brief Plugin for parsing DNS traffic.
4-
* \author Jiri Havranek <[email protected]>
5-
* \date 2015
6-
* \date 2016
7-
*/
8-
/*
9-
* Copyright (C) 2014-2016 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.
25-
*
2+
* @file
3+
* @brief Plugin for parsing DNS traffic.
4+
* @author Jiri Havranek <[email protected]>
5+
* @author Pavel Siska <[email protected]>
6+
* @date 2025
267
*
8+
* Copyright (c) 2025 CESNET
279
*
10+
* SPDX-License-Identifier: BSD-3-Clause
2811
*/
2912

13+
#include "dns.hpp"
14+
3015
#include <iostream>
3116
#include <sstream>
3217

3318
#include <arpa/inet.h>
19+
#include <ipfixprobe/pluginFactory/pluginManifest.hpp>
20+
#include <ipfixprobe/pluginFactory/pluginRegistrar.hpp>
3421
#include <stdio.h>
3522
#include <stdlib.h>
3623

3724
#ifdef WITH_NEMEA
3825
#include <unirec/unirec.h>
3926
#endif
4027

41-
#include "dns.hpp"
42-
4328
namespace ipxp {
4429

45-
int RecordExtDNS::REGISTERED_ID = -1;
46-
47-
__attribute__((constructor)) static void register_this_plugin()
48-
{
49-
static PluginRecord rec = PluginRecord("dns", []() { return new DNSPlugin(); });
50-
register_plugin(&rec);
51-
RecordExtDNS::REGISTERED_ID = register_extension();
52-
}
30+
int RecordExtDNS::REGISTERED_ID = ProcessPluginIDGenerator::instance().generatePluginID();
5331

32+
static const PluginManifest dnsPluginManifest = {
33+
.name = "dns",
34+
.description = "Dns process plugin for parsing dns traffic.",
35+
.pluginVersion = "1.0.0",
36+
.apiVersion = "1.0.0",
37+
.usage = nullptr,
38+
};
5439
// #define DEBUG_DNS
5540

5641
// Print debug message if debugging is allowed.
@@ -79,13 +64,14 @@ __attribute__((constructor)) static void register_this_plugin()
7964
*/
8065
#define GET_OFFSET(half1, half2) ((((uint8_t) (half1) & 0x3F) << 8) | (uint8_t) (half2))
8166

82-
DNSPlugin::DNSPlugin()
67+
DNSPlugin::DNSPlugin(const std::string& params)
8368
: queries(0)
8469
, responses(0)
8570
, total(0)
8671
, data_begin(nullptr)
8772
, data_len(0)
8873
{
74+
init(params.c_str());
8975
}
9076

9177
DNSPlugin::~DNSPlugin()
@@ -690,4 +676,6 @@ int DNSPlugin::add_ext_dns(const char* data, unsigned int payload_len, bool tcp,
690676
return FLOW_FLUSH;
691677
}
692678

679+
static const PluginRegistrar<DNSPlugin, ProcessPluginFactory> dnsRegistrar(dnsPluginManifest);
680+
693681
} // namespace ipxp
Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,16 @@
11
/**
2-
* \file dns.hpp
3-
* \brief Plugin for parsing DNS traffic.
4-
* \author Jiri Havranek <[email protected]>
5-
* \date 2015
6-
* \date 2016
7-
*/
8-
/*
9-
* Copyright (C) 2014-2016 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.
25-
*
2+
* @file
3+
* @brief Plugin for parsing DNS traffic.
4+
* @author Jiri Havranek <[email protected]>
5+
* @author Pavel Siska <[email protected]>
6+
* @date 2025
267
*
8+
* Copyright (c) 2025 CESNET
279
*
10+
* SPDX-License-Identifier: BSD-3-Clause
2811
*/
2912

30-
#ifndef IPXP_PROCESS_DNS_HPP
31-
#define IPXP_PROCESS_DNS_HPP
13+
#pragma once
3214

3315
#include <cstring>
3416
#include <sstream>
@@ -38,12 +20,11 @@
3820
#include "fields.h"
3921
#endif
4022

41-
#include "dns-utils.hpp"
42-
23+
#include <dns-utils.hpp>
4324
#include <ipfixprobe/flowifc.hpp>
4425
#include <ipfixprobe/ipfix-elements.hpp>
4526
#include <ipfixprobe/packet.hpp>
46-
#include <ipfixprobe/process.hpp>
27+
#include <ipfixprobe/processPlugin.hpp>
4728

4829
namespace ipxp {
4930

@@ -169,7 +150,7 @@ struct RecordExtDNS : public RecordExt {
169150
*/
170151
class DNSPlugin : public ProcessPlugin {
171152
public:
172-
DNSPlugin();
153+
DNSPlugin(const std::string& params);
173154
~DNSPlugin();
174155
void init(const char* params);
175156
void close();
@@ -205,4 +186,3 @@ class DNSPlugin : public ProcessPlugin {
205186
};
206187

207188
} // namespace ipxp
208-
#endif /* IPXP_PROCESS_DNS_HPP */

0 commit comments

Comments
 (0)