Commit 682fa7e0 authored by Pavel Doležal's avatar Pavel Doležal

dnstap: Implement processing of dnstap data in DPDK version

parent 85b4bfdc
Pipeline #75505 passed with stages
in 8 minutes and 4 seconds
......@@ -40,6 +40,7 @@
#include "utils/Logger.h"
#include "dpdk/DpdkPort.h"
#include "dpdk/DpdkPcapPort.h"
#include "core/UnixSocket.h"
DDP::LogWriter logwriter;
......@@ -287,6 +288,7 @@ int main(int argc, char** argv)
}
std::vector<std::shared_ptr<DDP::Port>> ready_ports;
std::vector<std::shared_ptr<DDP::Port>> ready_sockets;
try {
// Port initialization
std::set<uint16_t> ports;
......@@ -318,6 +320,10 @@ int main(int argc, char** argv)
ready_ports.emplace_back(new DDP::DPDKPort(port, runner.slaves_cnt() - 1, interface_mempool));
}
for (auto& port : arguments.args.dnstap_sockets) {
ready_sockets.emplace_back(new DDP::UnixSocket(port.c_str()));
}
// Set up signal handlers to print stats on exit
struct sigaction sa{};
sa.sa_handler = &signal_handler;
......@@ -331,7 +337,7 @@ int main(int argc, char** argv)
// Poll on configuration core
try {
auto ret = static_cast<int>(runner.run(ready_ports));
auto ret = static_cast<int>(runner.run(ready_ports, ready_sockets));
try {
unbind_interfaces(arguments.args);
}
......
......@@ -26,7 +26,7 @@
#include "DpdkPacket.h"
#include "platform/Allocator.h"
DDP::DPDKPacket::DPDKPacket(rte_mbuf* mbuf) : m_payload(), m_used_mbuf(true), m_mbuf(mbuf)
DDP::DPDKPacket::DPDKPacket(rte_mbuf* mbuf, PacketType type) : m_payload(), m_used_mbuf(true), m_type(type), m_mbuf(mbuf)
{
if (mbuf->nb_segs > 1) {
auto buffer = reinterpret_cast<uint8_t*>(Alloc::malloc(mbuf->pkt_len));
......@@ -53,6 +53,7 @@ DDP::DPDKPacket::DPDKPacket(rte_mbuf* mbuf) : m_payload(), m_used_mbuf(true), m_
DDP::DPDKPacket::DPDKPacket(const DDP::DPDKPacket& packet) : m_payload(),
m_used_mbuf(false),
m_type(PacketType::NONE),
m_buffer(nullptr)
{
if (packet.used_mbuf()) {
......@@ -70,10 +71,12 @@ DDP::DPDKPacket::DPDKPacket(const DDP::DPDKPacket& packet) : m_payload(),
m_payload = MemView<uint8_t>(m_buffer, packet.m_payload.count());
}
m_type = packet.m_type;
}
DDP::DPDKPacket::DPDKPacket(const MemView<uint8_t>& data) : m_payload(),
DDP::DPDKPacket::DPDKPacket(const MemView<uint8_t>& data, PacketType type) : m_payload(),
m_used_mbuf(false),
m_type(PacketType::NONE),
m_buffer(nullptr)
{
m_buffer = reinterpret_cast<uint8_t*>(Alloc::malloc(data.count()));
......@@ -83,12 +86,29 @@ DDP::DPDKPacket::DPDKPacket(const MemView<uint8_t>& data) : m_payload(),
std::copy(data.ptr(), data.ptr() + data.count(), m_buffer);
m_payload = MemView<uint8_t>(m_buffer, data.count());
m_type = type;
}
DDP::DPDKPacket::DPDKPacket(const uint8_t* packet, std::size_t size, bool, PacketType type) : m_payload(),
m_used_mbuf(false),
m_type(PacketType::NONE),
m_buffer(nullptr)
{
m_buffer = const_cast<uint8_t*>(packet);
m_payload = MemView<uint8_t>(m_buffer, size);
m_type = type;
}
void DDP::DPDKPacket::free()
{
if (!m_used_mbuf)
Alloc::free(m_buffer);
else
if (!m_used_mbuf) {
if (m_type != PacketType::DNSTAP)
Alloc::free(m_buffer);
m_buffer = nullptr;
}
else {
rte_pktmbuf_free(m_mbuf);
m_mbuf = nullptr;
}
}
......@@ -27,6 +27,7 @@
#include <cstring>
#include "utils/MemView.h"
#include "core/BasePacket.h"
#include <rte_mbuf.h>
#include <rte_malloc.h>
......@@ -43,13 +44,15 @@ namespace DDP {
*/
explicit DPDKPacket() : m_payload(),
m_used_mbuf(false),
m_type(PacketType::NONE),
m_mbuf(nullptr) {}
/**
* Creates DDP::DPDKPacket from DPDK mbuf.
* @param mbuf Mbuf used for initialisation od DDP::DPDKPacket.
* @param type Format of packet stored in buffer
*/
explicit DPDKPacket(rte_mbuf* mbuf);
explicit DPDKPacket(rte_mbuf* mbuf, PacketType type = PacketType::WIRE);
/**
* Copy constructor.
......@@ -63,13 +66,23 @@ namespace DDP {
*/
DPDKPacket(DPDKPacket&& packet) noexcept : m_payload(packet.m_payload),
m_used_mbuf(packet.m_used_mbuf),
m_type(packet.m_type),
m_mbuf(packet.m_mbuf) { packet.m_buffer = nullptr; }
/**
* Creates DDP::DPDKPacket from DDP::MemView.
* @param data Memview used for initialisation od the DDP:DDPKPacket.
* @param type Format of packet stored in buffer
*/
DPDKPacket(const MemView<uint8_t>& data);
DPDKPacket(const MemView<uint8_t>& data, PacketType type = PacketType::WIRE);
/**
* @brief Creates DDP::DPDKPacket from data buffer
* @param packet Pointer to packet data buffer
* @param size Size of packet data in bytes
* @param type Format of packet stored in buffer
*/
DPDKPacket(const uint8_t* packet, std::size_t size, bool, PacketType type = PacketType::WIRE);
/**
* Swap contents of two DDP:DPDKPackets.
......@@ -83,6 +96,7 @@ namespace DDP {
swap(packet1.m_used_mbuf, packet2.m_used_mbuf);
swap(packet1.m_buffer, packet2.m_buffer);
swap(packet1.m_payload, packet2.m_payload);
swap(packet1.m_type, packet2.m_type);
}
/**
......@@ -120,6 +134,11 @@ namespace DDP {
*/
uint64_t size() const { return m_payload.count(); }
/**
* @brief Get type of packet
*/
PacketType type() const { return m_type; }
/**
* Destructor.
*/
......@@ -135,6 +154,7 @@ namespace DDP {
void free();
bool m_used_mbuf; //!< True if instance of DDP::DPDKPacket using mbuf otherwise false.
PacketType m_type; //!< Type of stored packet
union
{
rte_mbuf* m_mbuf; //!< Pointer to associated mbuf.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment