]>
Commit | Line | Data |
---|---|---|
82a91ddf CH |
1 | /* |
2 | * This file is part of PowerDNS or dnsdist. | |
3 | * Copyright -- PowerDNS.COM B.V. and its contributors | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * In addition, for the avoidance of any doubt, permission is granted to | |
10 | * link this program with OpenSSL and to (re)distribute the binaries | |
11 | * produced as the result of such linking. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | */ | |
22 | #pragma once | |
23 | #include "config.h" | |
24 | #include "remote_logger.hh" | |
25 | ||
26 | #ifdef HAVE_FSTRM | |
27 | ||
573f4ff0 | 28 | #include <unordered_map> |
82a91ddf CH |
29 | #include <fstrm.h> |
30 | #include <fstrm/iothr.h> | |
31 | #include <fstrm/unix_writer.h> | |
32 | #ifdef HAVE_FSTRM_TCP_WRITER_INIT | |
33 | #include <fstrm/tcp_writer.h> | |
34 | #endif | |
35 | ||
5c9334e7 | 36 | class FrameStreamLogger : public RemoteLoggerInterface |
82a91ddf CH |
37 | { |
38 | public: | |
5c9334e7 OM |
39 | FrameStreamLogger(int family, std::string address, bool connect, const std::unordered_map<string, unsigned>& options = std::unordered_map<string, unsigned>()); |
40 | FrameStreamLogger(const FrameStreamLogger&) = delete; | |
41 | FrameStreamLogger(FrameStreamLogger&&) = delete; | |
42 | FrameStreamLogger& operator=(const FrameStreamLogger&) = delete; | |
43 | FrameStreamLogger& operator=(FrameStreamLogger&&) = delete; | |
44 | ~FrameStreamLogger() override; | |
4d7db3d7 | 45 | [[nodiscard]] RemoteLoggerInterface::Result queueData(const std::string& data) override; |
9472436f | 46 | |
7c846157 | 47 | [[nodiscard]] std::string address() const override |
9472436f OM |
48 | { |
49 | return d_address; | |
50 | } | |
51 | ||
7c846157 | 52 | [[nodiscard]] std::string name() const override |
4d7db3d7 | 53 | { |
2b7a8236 | 54 | return "dnstap"; |
4d7db3d7 | 55 | } |
5c9334e7 | 56 | |
7c846157 | 57 | [[nodiscard]] std::string toString() override |
82a91ddf | 58 | { |
414a03e1 | 59 | return "FrameStreamLogger to " + d_address + " (" + std::to_string(d_framesSent) + " frames sent, " + std::to_string(d_queueFullDrops) + " dropped, " + std::to_string(d_permanentFailures) + " permanent failures)"; |
82a91ddf | 60 | } |
573f4ff0 | 61 | |
7c846157 | 62 | [[nodiscard]] RemoteLoggerInterface::Stats getStats() override |
2b7a8236 OM |
63 | { |
64 | return Stats{.d_queued = d_framesSent, | |
65 | .d_pipeFull = d_queueFullDrops, | |
b98b553a | 66 | .d_tooLarge = 0, |
5c9334e7 | 67 | .d_otherError = d_permanentFailures}; |
2b7a8236 OM |
68 | } |
69 | ||
82a91ddf CH |
70 | private: |
71 | const int d_family; | |
72 | const std::string d_address; | |
5c9334e7 OM |
73 | struct fstrm_iothr_queue* d_ioqueue{nullptr}; |
74 | struct fstrm_writer_options* d_fwopt{nullptr}; | |
75 | struct fstrm_unix_writer_options* d_uwopt{nullptr}; | |
82a91ddf | 76 | #ifdef HAVE_FSTRM_TCP_WRITER_INIT |
5c9334e7 | 77 | struct fstrm_tcp_writer_options* d_twopt{nullptr}; |
82a91ddf | 78 | #endif |
5c9334e7 OM |
79 | struct fstrm_writer* d_writer{nullptr}; |
80 | struct fstrm_iothr_options* d_iothropt{nullptr}; | |
81 | struct fstrm_iothr* d_iothr{nullptr}; | |
414a03e1 RG |
82 | std::atomic<uint64_t> d_framesSent{0}; |
83 | std::atomic<uint64_t> d_queueFullDrops{0}; | |
84 | std::atomic<uint64_t> d_permanentFailures{0}; | |
82a91ddf CH |
85 | |
86 | void cleanup(); | |
87 | }; | |
88 | ||
10ba6d01 | 89 | #else |
5c9334e7 OM |
90 | class FrameStreamLogger : public RemoteLoggerInterface |
91 | { | |
92 | FrameStreamLogger(const FrameStreamLogger&) = delete; | |
93 | FrameStreamLogger(FrameStreamLogger&&) = delete; | |
94 | FrameStreamLogger& operator=(const FrameStreamLogger&) = delete; | |
95 | FrameStreamLogger& operator=(FrameStreamLogger&&) = delete; | |
96 | }; | |
82a91ddf | 97 | #endif /* HAVE_FSTRM */ |