Skip to content

Commit d4ab52a

Browse files
author
Pavel Siska
committed
ipfixprobe - introduce process PASSIVEDNS plugin
1 parent 8113f18 commit d4ab52a

File tree

5 files changed

+64
-72
lines changed

5 files changed

+64
-72
lines changed

src/plugins/process/CMakeLists.txt

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

src/plugins/process/passiveDns/README.md

Whitespace-only changes.

src/plugins/process/passivedns.cpp renamed to src/plugins/process/passiveDns/src/passivedns.cpp

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,47 @@
11
/**
2-
* \file passivedns.cpp
3-
* \brief Plugin for exporting DNS A and AAAA records.
4-
* \author Jiri Havranek <[email protected]>
5-
* \date 2017
6-
*/
7-
/*
8-
* Copyright (C) 2017 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 Plugin for parsing DNS A and AAAA records.
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-
#include <cstring>
30-
#include <iostream>
31-
#include <sstream>
32-
#include <type_traits>
33-
34-
#include <arpa/inet.h>
35-
#include <stdio.h>
36-
#include <stdlib.h>
13+
#include "passivedns.hpp"
3714

3815
#ifdef WITH_NEMEA
3916
#include <unirec/unirec.h>
4017
#endif
4118

42-
#include "passivedns.hpp"
43-
19+
#include <cstdlib>
20+
#include <cstring>
21+
#include <iostream>
4422
#include <limits>
23+
#include <sstream>
24+
#include <type_traits>
4525

26+
#include <arpa/inet.h>
4627
#include <errno.h>
28+
#include <ipfixprobe/pluginFactory/pluginManifest.hpp>
29+
#include <ipfixprobe/pluginFactory/pluginRegistrar.hpp>
4730
#include <ipfixprobe/utils.hpp>
4831
#include <stdint.h>
49-
#include <stdlib.h>
32+
#include <stdio.h>
5033

5134
namespace ipxp {
5235

53-
int RecordExtPassiveDNS::REGISTERED_ID = -1;
36+
int RecordExtPassiveDNS::REGISTERED_ID = ProcessPluginIDGenerator::instance().generatePluginID();
5437

55-
__attribute__((constructor)) static void register_this_plugin()
56-
{
57-
static PluginRecord rec = PluginRecord("passivedns", []() { return new PassiveDNSPlugin(); });
58-
register_plugin(&rec);
59-
RecordExtPassiveDNS::REGISTERED_ID = register_extension();
60-
}
38+
static const PluginManifest passivednsPluginManifest = {
39+
.name = "passivedns",
40+
.description = "Passivedns process plugin for parsing DNS A and AAAA records.",
41+
.pluginVersion = "1.0.0",
42+
.apiVersion = "1.0.0",
43+
.usage = nullptr,
44+
};
6145

6246
// #define DEBUG_PASSIVEDNS
6347

@@ -87,14 +71,15 @@ __attribute__((constructor)) static void register_this_plugin()
8771
*/
8872
#define GET_OFFSET(half1, half2) ((((uint8_t) (half1) & 0x3F) << 8) | (uint8_t) (half2))
8973

90-
PassiveDNSPlugin::PassiveDNSPlugin()
74+
PassiveDNSPlugin::PassiveDNSPlugin(const std::string& params)
9175
: total(0)
9276
, parsed_a(0)
9377
, parsed_aaaa(0)
9478
, parsed_ptr(0)
9579
, data_begin(nullptr)
9680
, data_len(0)
9781
{
82+
init(params.c_str());
9883
}
9984

10085
PassiveDNSPlugin::~PassiveDNSPlugin()
@@ -526,4 +511,7 @@ int PassiveDNSPlugin::add_ext_dns(const char* data, unsigned int payload_len, bo
526511
return FLOW_FLUSH;
527512
}
528513

514+
static const PluginRegistrar<PassiveDNSPlugin, ProcessPluginFactory>
515+
passivednsRegistrar(passivednsPluginManifest);
516+
529517
} // namespace ipxp

src/plugins/process/passivedns.hpp renamed to src/plugins/process/passiveDns/src/passivedns.hpp

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,30 @@
11
/**
2-
* \file passivedns.h
3-
* \brief Plugin for exporting DNS A and AAAA records.
4-
* \author Jiri Havranek <[email protected]>
5-
* \date 2017
6-
*/
7-
/*
8-
* Copyright (C) 2017 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 Plugin for parsing DNS A and AAAA records.
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_PROCESS_PASSIVEDNS_HPP
30-
#define IPXP_PROCESS_PASSIVEDNS_HPP
13+
#pragma once
3114

15+
#include <cstring>
3216
#include <sstream>
3317
#include <string>
3418

3519
#ifdef WITH_NEMEA
3620
#include "fields.h"
3721
#endif
3822

39-
#include "dns-utils.hpp"
40-
23+
#include <dns-utils.hpp>
4124
#include <ipfixprobe/flowifc.hpp>
4225
#include <ipfixprobe/ipfix-elements.hpp>
4326
#include <ipfixprobe/packet.hpp>
44-
#include <ipfixprobe/process.hpp>
27+
#include <ipfixprobe/processPlugin.hpp>
4528

4629
namespace ipxp {
4730

@@ -145,7 +128,7 @@ struct RecordExtPassiveDNS : public RecordExt {
145128
*/
146129
class PassiveDNSPlugin : public ProcessPlugin {
147130
public:
148-
PassiveDNSPlugin();
131+
PassiveDNSPlugin(const std::string& params);
149132
~PassiveDNSPlugin();
150133
void init(const char* params);
151134
void close();
@@ -179,4 +162,3 @@ class PassiveDNSPlugin : public ProcessPlugin {
179162
};
180163

181164
} // namespace ipxp
182-
#endif /* IPXP_PROCESS_PASSIVEDNS_HPP */

0 commit comments

Comments
 (0)