#include "rec-main.hh"
#include "aggressive_nsec.hh"
-#include "capabilities.hh"
#include "arguments.hh"
-#include "dns_random.hh"
-#include "rec_channel.hh"
-#include "rec-tcpout.hh"
-#include "version.hh"
-#include "query-local-address.hh"
-#include "validate-recursor.hh"
-#include "pubsuffix.hh"
-#include "opensslsigners.hh"
-#include "ws-recursor.hh"
-#include "rec-taskqueue.hh"
-#include "secpoll-recursor.hh"
-#include "logging.hh"
+#include "capabilities.hh"
#include "dnssec.hh"
+#include "opensslsigners.hh"
+#include "pubsuffix.hh"
+#include "query-local-address.hh"
#include "rec-rust-lib/cxxsettings.hh"
-#include "json.hh"
+#include "rec-snmp.hh"
#include "rec-system-resolve.hh"
+#include "rec-taskqueue.hh"
+#include "rec-tcpout.hh"
#include "root-dnssec.hh"
-#include "ratelimitedlog.hh"
-#include "rec-rust-lib/rust/web.rs.h"
+#include "secpoll-recursor.hh"
+#include "threadname.hh"
+#include "version.hh"
+#include "ws-recursor.hh"
#ifdef NOD_ENABLED
#include "nod.hh"
#ifdef HAVE_LIBSODIUM
#include <sodium.h>
-
-#include <cstddef>
-#include <utility>
#endif
#ifdef HAVE_SYSTEMD
// Static part: the FDs from the start, pipes, controlsocket, web socket, listen sockets
unsigned int staticPart = 25; // general allowance, including control socket, web, snmp
// Handler thread gets one pipe, the others all of them
- staticPart += 2 + (threads - 1) * (sizeof(RecThreadInfo::ThreadPipeSet) / sizeof(int)); // number of fd's in ThreadPipeSet
+ staticPart += 2 + ((threads - 1) * (sizeof(RecThreadInfo::ThreadPipeSet) / sizeof(int))); // number of fd's in ThreadPipeSet
// listen sockets
staticPart += listeningSockets;
// Another fd per thread for poll/kqueue
// plus each worker thread can have a number of idle outgoing TCP connections
perWorker += TCPOutConnectionManager::s_maxIdlePerThread;
- auto wantFDs = staticPart + workers * perWorker;
+ auto wantFDs = staticPart + (workers * perWorker);
if (wantFDs > availFDs) {
unsigned int hardlimit = getFilenumLimit(true);
__tsan_release(resp);
- if (write(RecThreadInfo::self().getPipes().writeFromThread, &resp, sizeof(resp)) != sizeof(resp)) {
+ if (write(RecThreadInfo::self().getPipes().writeFromThread, static_cast<void*>(&resp), sizeof(resp)) != sizeof(resp)) {
delete tmsg; // NOLINT: manual ownership handling
unixDie("write to thread pipe returned wrong size or error");
}
if (clientfd == -1) {
throw PDNSException("accept failed");
}
- string msg = g_rcc.recv(clientfd).d_str;
+ string msg = RecursorControlChannel::recv(clientfd).d_str;
log->info(Logr::Info, "Received rec_control command via control socket", "command", Logging::Loggable(msg));
RecursorControlParser::func_t* command = nullptr;
auto answer = RecursorControlParser::getAnswer(clientfd, msg, &command);
if (command != doExitNicely) {
- g_rcc.send(clientfd, answer);
+ RecursorControlChannel::send(clientfd, answer);
}
command();
if (command == doExitNicely) {
- g_rcc.send(clientfd, answer);
+ RecursorControlChannel::send(clientfd, answer);
}
}
catch (const std::exception& e) {
checkFrameStreamExport(luaconfsLocal, luaconfsLocal->nodFrameStreamExportConfig, t_nodFrameStreamServersInfo);
#endif
for (const auto& rpz : luaconfsLocal->rpzs) {
- string name = rpz.polName.empty() ? (rpz.zoneXFRParams.primaries.empty() ? "rpzFile" : rpz.zoneXFRParams.name) : rpz.polName;
+ string name = rpz.polName;
+ if (name.empty()) {
+ name = rpz.zoneXFRParams.primaries.empty() ? "rpzFile" : rpz.zoneXFRParams.name;
+ }
t_Counters.at(rec::PolicyNameHits::policyName).counts[name] = 0;
}
}
g_quiet = ::arg().mustDo("quiet");
s_logUrgency = (Logger::Urgency)::arg().asNum("loglevel");
- if (s_logUrgency < Logger::Error) {
- s_logUrgency = Logger::Error;
- }
+ s_logUrgency = std::max(s_logUrgency, Logger::Error);
if (!g_quiet && s_logUrgency < Logger::Info) { // Logger::Info=6, Logger::Debug=7
s_logUrgency = Logger::Info; // if you do --quiet=no, you need Info to also see the query log
}
if (fname.empty()) {
t_pdl.reset();
log->info(Logr::Info, "Unloaded current lua script");
- return new RecursorControlChannel::Answer{0, string("unloaded\n")};
+ return new RecursorControlChannel::Answer{0, string("unloaded\n")}; // NOLINT: manual ownership handling
}
t_pdl = std::make_shared<RecursorLua4>();
#pragma once
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
-#include "logger.hh"
#include "logr.hh"
+#include "iputils.hh"
#include "lua-recursor4.hh"
#include "mplexer.hh"
-#include "namespaces.hh"
#include "rec-lua-conf.hh"
#include "rec-protozero.hh"
#include "syncres.hh"
-#include "rec-snmp.hh"
#include "rec_channel.hh"
-#include "threadname.hh"
#include "recpacketcache.hh"
#include "ratelimitedlog.hh"
-#include "protozero-trace.hh"
#include "remote_logger.hh"
#ifdef NOD_ENABLED
}
// The address the query is coming from
- void setRemote(const ComboAddress& sa)
+ void setRemote(const ComboAddress& address)
{
- d_remote = sa;
+ d_remote = address;
}
// The address we assume the query is coming from, might be set by proxy protocol
- void setSource(const ComboAddress& sa)
+ void setSource(const ComboAddress& address)
{
- d_source = sa;
+ d_source = address;
}
- void setMappedSource(const ComboAddress& sa)
+ void setMappedSource(const ComboAddress& address)
{
- d_mappedSource = sa;
+ d_mappedSource = address;
}
- void setLocal(const ComboAddress& sa)
+ void setLocal(const ComboAddress& address)
{
- d_local = sa;
+ d_local = address;
}
// The address we assume the query is sent to, might be set by proxy protocol
- void setDestination(const ComboAddress& sa)
+ void setDestination(const ComboAddress& address)
{
- d_destination = sa;
+ d_destination = address;
}
void setSocket(int sock)
// but after you call 'returnSocket' on it, don't assume anything anymore
class UDPClientSocks
{
- unsigned int d_numsocks;
-
public:
- UDPClientSocks() :
- d_numsocks(0)
- {
- }
-
LWResult::Result getSocket(const ComboAddress& toaddr, const std::optional<ComboAddress>& localAddress, int* fileDesc);
// return a socket to the pool, or simply erase it
void returnSocket(int fileDesc);
private:
+ unsigned int d_numsocks{0};
// returns -1 for errors which might go away, throws for ones that won't
static int makeClientSocket(int family, const std::optional<ComboAddress>& localAddress);
};
-enum class PaddingMode
+enum class PaddingMode : uint8_t
{
Always,
PaddedQueries
};
-typedef MTasker<std::shared_ptr<PacketID>, PacketBuffer, PacketIDCompare> MT_t;
+using MT_t = MTasker<std::shared_ptr<PacketID>, PacketBuffer, PacketIDCompare>;
extern thread_local std::unique_ptr<MT_t> g_multiTasker; // the big MTasker
extern std::unique_ptr<RecursorPacketCache> g_packetCache;
extern std::vector<bool> g_avoidUdpSourcePorts;
/* without reuseport, all listeners share the same sockets */
-typedef vector<pair<int, std::function<void(int, boost::any&)>>> deferredAdd_t;
+using deferredAdd_t = vector<pair<int, std::function<void(int, boost::any&)>>>;
inline MT_t* getMT()
{
/* this function is called with both a string and a vector<uint8_t> representing a packet */
template <class T>
-static bool sendResponseOverTCP(const std::unique_ptr<DNSComboWriter>& dc, const T& packet)
+static bool sendResponseOverTCP(const std::unique_ptr<DNSComboWriter>& comboWriter, const T& packet)
{
- uint8_t buf[2];
+ std::array<uint8_t, 2> buf{};
buf[0] = packet.size() / 256;
buf[1] = packet.size() % 256;
- Utility::iovec iov[2];
- iov[0].iov_base = (void*)buf;
+ std::array<Utility::iovec, 2> iov{};
+ iov[0].iov_base = static_cast<void*>(buf.data());
iov[0].iov_len = 2;
- iov[1].iov_base = (void*)&*packet.begin();
+ iov[1].iov_base = static_cast<void*>(const_cast<typename T::value_type*>(packet.data()));
iov[1].iov_len = packet.size();
- int wret = Utility::writev(dc->d_socket, iov, 2);
+ int wret = Utility::writev(comboWriter->d_socket, iov.data(), iov.size());
bool hadError = true;
if (wret == 0) {
- g_log << Logger::Warning << "EOF writing TCP answer to " << dc->getRemote() << endl;
+ g_log << Logger::Warning << "EOF writing TCP answer to " << comboWriter->getRemote() << endl;
}
else if (wret < 0) {
int err = errno;
- g_log << Logger::Warning << "Error writing TCP answer to " << dc->getRemote() << ": " << strerror(err) << endl;
+ g_log << Logger::Warning << "Error writing TCP answer to " << comboWriter->getRemote() << ": " << stringerror(err) << endl;
}
else if ((unsigned int)wret != 2 + packet.size()) {
- g_log << Logger::Warning << "Oops, partial answer sent to " << dc->getRemote() << " for " << dc->d_mdp.d_qname << " (size=" << (2 + packet.size()) << ", sent " << wret << ")" << endl;
+ g_log << Logger::Warning << "Oops, partial answer sent to " << comboWriter->getRemote() << " for " << comboWriter->d_mdp.d_qname << " (size=" << (2 + packet.size()) << ", sent " << wret << ")" << endl;
}
else {
hadError = false;
return deferredAdds;
}
- const ThreadPipeSet& getPipes() const
+ [[nodiscard]] const ThreadPipeSet& getPipes() const
{
return pipes;
}
RecursorPacketCache::OptPBData& pbData, bool tcp, const ComboAddress& source, const ComboAddress& mappedSource);
void protobufLogResponse(pdns::ProtoZero::RecMessage& message);
void protobufLogResponse(const DNSName& qname, QType qtype, const struct dnsheader* header, LocalStateHolder<LuaConfigItems>& luaconfsLocal,
- const RecursorPacketCache::OptPBData& pbData, const struct timeval& tv,
+ const RecursorPacketCache::OptPBData& pbData, const struct timeval& tval,
bool tcp, const ComboAddress& source, const ComboAddress& destination,
const ComboAddress& mappedSource, const EDNSSubnetOpts& ednssubnet,
const boost::uuids::uuid& uniqueId, const string& requestorId, const string& deviceId,
void activateLuaConfig(LuaConfigItems& lci);
unsigned int authWaitTimeMSec(const std::unique_ptr<MT_t>& mtasker);
-#define LOCAL_NETS "127.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 169.254.0.0/16, 192.168.0.0/16, 172.16.0.0/12, ::1/128, fc00::/7, fe80::/10"
-#define LOCAL_NETS_INVERSE "!127.0.0.0/8, !10.0.0.0/8, !100.64.0.0/10, !169.254.0.0/16, !192.168.0.0/16, !172.16.0.0/12, !::1/128, !fc00::/7, !fe80::/10"
+static const std::string LOCAL_NETS = "127.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 169.254.0.0/16, 192.168.0.0/16, 172.16.0.0/12, ::1/128, fc00::/7, fe80::/10";
+static const std::string LOCAL_NETS_INVERSE = "!127.0.0.0/8, !10.0.0.0/8, !100.64.0.0/10, !169.254.0.0/16, !192.168.0.0/16, !172.16.0.0/12, !::1/128, !fc00::/7, !fe80::/10";
// Bad Nets taken from both:
// http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
// and
// http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
// where such a network may not be considered a valid destination
-#define BAD_NETS "0.0.0.0/8, 192.0.0.0/24, 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, 240.0.0.0/4, ::/96, ::ffff:0:0/96, 100::/64, 2001:db8::/32"
-#define DONT_QUERY LOCAL_NETS ", " BAD_NETS
+static const std::string BAD_NETS = "0.0.0.0/8, 192.0.0.0/24, 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, 240.0.0.0/4, ::/96, ::ffff:0:0/96, 100::/64, 2001:db8::/32";
+static const std::string DONT_QUERY = LOCAL_NETS + ", " + BAD_NETS;