-#ifdef HAVE_CONFIG_H
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
#include "config.h"
-#endif
+
#include "rec_channel.hh"
-#include "utility.hh"
+
#include <sys/socket.h>
#include <cerrno>
-#include "misc.hh"
-#include <string.h>
#include <cstdlib>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <iostream>
-#include <limits.h>
-
-#include "pdnsexception.hh"
+#include "misc.hh"
#include "namespaces.hh"
+#include "pdnsexception.hh"
/* g++ defines __SANITIZE_THREAD__
clang++ supports the nice __has_feature(thread_sanitizer),
std::atomic<bool> RecursorControlChannel::stop = false;
-RecursorControlChannel::RecursorControlChannel()
+RecursorControlChannel::RecursorControlChannel() :
+ d_fd(-1)
{
- d_fd = -1;
- *d_local.sun_path = 0;
- d_local.sun_family = 0;
+ memset(&d_local, 0, sizeof(d_local));
}
RecursorControlChannel::~RecursorControlChannel()
{
- if (d_fd > 0)
+ if (d_fd > 0) {
close(d_fd);
- if (*d_local.sun_path)
- unlink(d_local.sun_path);
+ }
+ if (d_local.sun_path[0] != '\0') {
+ unlink(d_local.sun_path); // NOLINT
+ }
}
-int RecursorControlChannel::listen(const string& fname)
+int RecursorControlChannel::listen(const string& filename)
{
d_fd = socket(AF_UNIX, SOCK_STREAM, 0);
- setCloseOnExec(d_fd);
- if (d_fd < 0)
+ if (d_fd < 0) {
throw PDNSException("Creating UNIX domain socket: " + stringerror());
+ }
+ setCloseOnExec(d_fd);
int tmp = 1;
- if (setsockopt(d_fd, SOL_SOCKET, SO_REUSEADDR, (char*)&tmp, sizeof tmp) < 0)
+ if (setsockopt(d_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof tmp) < 0) {
throw PDNSException("Setsockopt failed: " + stringerror());
+ }
- int err = unlink(fname.c_str());
- if (err < 0 && errno != ENOENT)
- throw PDNSException("Can't remove (previous) controlsocket '" + fname + "': " + stringerror() + " (try --socket-dir)");
+ int err = unlink(filename.c_str());
+ if (err < 0 && errno != ENOENT) {
+ throw PDNSException("Can't remove (previous) controlsocket '" + filename + "': " + stringerror() + " (try --socket-dir)");
+ }
- if (makeUNsockaddr(fname, &d_local))
- throw PDNSException("Unable to bind to controlsocket, path '" + fname + "' is not a valid UNIX socket path.");
+ if (makeUNsockaddr(filename, &d_local) != 0) {
+ throw PDNSException("Unable to bind to controlsocket, path '" + filename + "' is not a valid UNIX socket path.");
+ }
- if (bind(d_fd, (sockaddr*)&d_local, sizeof(d_local)) < 0)
- throw PDNSException("Unable to bind to controlsocket '" + fname + "': " + stringerror());
+ if (bind(d_fd, reinterpret_cast<sockaddr*>(&d_local), sizeof(d_local)) < 0) { // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
+ throw PDNSException("Unable to bind to controlsocket '" + filename + "': " + stringerror());
+ }
if (::listen(d_fd, 0) == -1) {
- throw PDNSException("Unable to listen on controlsocket '" + fname + "': " + stringerror());
+ throw PDNSException("Unable to listen on controlsocket '" + filename + "': " + stringerror());
}
return d_fd;
}
-void RecursorControlChannel::connect(const string& path, const string& fname)
+void RecursorControlChannel::connect(const string& path, const string& filename)
{
- struct sockaddr_un remote;
+ struct sockaddr_un remote{};
d_fd = socket(AF_UNIX, SOCK_STREAM, 0);
setCloseOnExec(d_fd);
- if (d_fd < 0)
+ if (d_fd < 0) {
throw PDNSException("Creating UNIX domain socket: " + stringerror());
-
+ }
try {
int tmp = 1;
- if (setsockopt(d_fd, SOL_SOCKET, SO_REUSEADDR, (char*)&tmp, sizeof tmp) < 0)
+ if (setsockopt(d_fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof tmp) < 0) {
throw PDNSException("Setsockopt failed: " + stringerror());
+ }
- string remotename = path + "/" + fname;
- if (makeUNsockaddr(remotename, &remote))
+ string remotename = path + "/" + filename;
+ if (makeUNsockaddr(remotename, &remote) != 0) {
throw PDNSException("Unable to connect to controlsocket, path '" + remotename + "' is not a valid UNIX socket path.");
+ }
- if (::connect(d_fd, (sockaddr*)&remote, sizeof(remote)) < 0) {
- if (*d_local.sun_path)
- unlink(d_local.sun_path);
- throw PDNSException("Unable to connect to remote '" + string(remote.sun_path) + "': " + stringerror());
+ if (::connect(d_fd, reinterpret_cast<const sockaddr*>(&remote), sizeof(remote)) < 0) { // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
+ if (d_local.sun_path[0] != '\0') {
+ unlink(d_local.sun_path); // NOLINT
+ }
+ throw PDNSException("Unable to connect to remote '" + remotename + "': " + stringerror());
}
}
catch (...) {
}
}
-static void sendfd(int s, int fd)
+static void sendfd(int socket, int fd_to_pass)
{
- struct msghdr msg;
- struct cmsghdr* cmsg;
+ struct msghdr msg{};
+ struct cmsghdr* cmsg{};
union
{
struct cmsghdr hdr;
- unsigned char buf[CMSG_SPACE(sizeof(int))];
- } cmsgbuf;
- struct iovec io_vector[1];
- char ch = 'X';
+ std::array<unsigned char, CMSG_SPACE(sizeof(int))> buf;
+ } cmsgbuf{};
+ std::array<iovec, 1> io_vector{};
+ char character = 'X';
- io_vector[0].iov_base = &ch;
+ io_vector[0].iov_base = &character;
io_vector[0].iov_len = 1;
memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = sizeof(cmsgbuf.buf);
- msg.msg_iov = io_vector;
- msg.msg_iovlen = 1;
+ msg.msg_iov = io_vector.data();
+ msg.msg_iovlen = io_vector.size();
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
- *(int*)CMSG_DATA(cmsg) = fd;
+ *reinterpret_cast<int*>(CMSG_DATA(cmsg)) = fd_to_pass; // NOLINT(cppcoreguidelines-pro-reinterpret-cast>
- if (sendmsg(s, &msg, 0) == -1) {
+ if (sendmsg(socket, &msg, 0) == -1) {
throw PDNSException("Unable to send fd message over control channel: " + stringerror());
}
}
-void RecursorControlChannel::send(int fd, const Answer& msg, unsigned int timeout, int fd_to_pass)
+void RecursorControlChannel::send(int fileDesc, const Answer& msg, unsigned int timeout, int fd_to_pass)
{
- int ret = waitForRWData(fd, false, timeout, 0);
+ int ret = waitForRWData(fileDesc, false, static_cast<int>(timeout), 0);
if (ret == 0) {
throw PDNSException("Timeout sending message over control channel");
}
- else if (ret < 0) {
+ if (ret < 0) {
throw PDNSException("Error sending message over control channel:" + stringerror());
}
- if (::send(fd, &msg.d_ret, sizeof(msg.d_ret), 0) < 0) {
+ if (::send(fileDesc, &msg.d_ret, sizeof(msg.d_ret), 0) < 0) {
throw PDNSException("Unable to send return code over control channel: " + stringerror());
}
size_t len = msg.d_str.length();
- if (::send(fd, &len, sizeof(len), 0) < 0) {
+ if (::send(fileDesc, &len, sizeof(len), 0) < 0) {
throw PDNSException("Unable to send length over control channel: " + stringerror());
}
- if (::send(fd, msg.d_str.c_str(), len, 0) != static_cast<ssize_t>(len)) {
+ if (::send(fileDesc, msg.d_str.c_str(), len, 0) != static_cast<ssize_t>(len)) {
throw PDNSException("Unable to send message over control channel: " + stringerror());
}
if (fd_to_pass != -1) {
- sendfd(fd, fd_to_pass);
+ sendfd(fileDesc, fd_to_pass);
}
}
-static void waitForRead(int fd, unsigned int timeout, time_t start)
+static void waitForRead(int fileDesc, unsigned int timeout, time_t start)
{
time_t elapsed = time(nullptr) - start;
if (elapsed >= timeout) {
throw PDNSException("Timeout waiting for control channel data");
}
// coverity[store_truncates_time_t]
- int ret = waitForData(fd, timeout - elapsed, 0);
+ int ret = waitForData(fileDesc, static_cast<int>(timeout - static_cast<unsigned int>(elapsed)), 0);
if (ret == 0) {
throw PDNSException("Timeout waiting for control channel data");
}
return 4096;
}
-RecursorControlChannel::Answer RecursorControlChannel::recv(int fd, unsigned int timeout)
+RecursorControlChannel::Answer RecursorControlChannel::recv(int fileDesc, unsigned int timeout)
{
// timeout covers the operation of all read ops combined
const time_t start = time(nullptr);
- waitForRead(fd, timeout, start);
+ waitForRead(fileDesc, timeout, start);
int err{};
- auto ret = ::recv(fd, &err, sizeof(err), 0);
+ auto ret = ::recv(fileDesc, &err, sizeof(err), 0);
if (ret == 0) {
#if defined(__SANITIZE_THREAD__)
return {0, "bye nicely\n"}; // Hack because TSAN enabled build justs _exits on quit-nicely
throw PDNSException("Unable to receive return status over control channel: " + stringerror());
}
- waitForRead(fd, timeout, start);
- size_t len;
- if (::recv(fd, &len, sizeof(len), 0) != sizeof(len)) {
+ waitForRead(fileDesc, timeout, start);
+ size_t len{};
+ if (::recv(fileDesc, &len, sizeof(len), 0) != sizeof(len)) {
throw PDNSException("Unable to receive length over control channel: " + stringerror());
}
string str;
str.reserve(len);
while (str.length() < len) {
- char buffer[1024];
- waitForRead(fd, timeout, start);
+ std::array<char, 1024> buffer{};
+ waitForRead(fileDesc, timeout, start);
size_t toRead = std::min(len - str.length(), sizeof(buffer));
- ssize_t recvd = ::recv(fd, buffer, toRead, 0);
+ ssize_t recvd = ::recv(fileDesc, buffer.data(), toRead, 0);
if (recvd <= 0) {
// EOF means we have a length error
throw PDNSException("Unable to receive message over control channel: " + stringerror());
}
- str.append(buffer, recvd);
+ str.append(buffer.data(), recvd);
}
return {err, std::move(str)};
-#ifdef HAVE_CONFIG_H
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
#include "config.h"
-#endif
+
#include "utility.hh"
#include "rec_channel.hh"
#include <sanitizer/lsan_interface.h>
#endif
-std::pair<std::string, std::string> PrefixDashNumberCompare::prefixAndTrailingNum(const std::string& a)
+std::pair<std::string, std::string> PrefixDashNumberCompare::prefixAndTrailingNum(const std::string& arg)
{
- auto i = a.length();
- if (i == 0) {
- return {a, ""};
+ auto length = arg.length();
+ if (length == 0) {
+ return {arg, ""};
}
- --i;
- if (!std::isdigit(a[i])) {
- return {a, ""};
+ --length;
+ if (std::isdigit(arg[length]) == 0) {
+ return {arg, ""};
}
- while (i > 0) {
- if (!std::isdigit(a[i])) {
+ while (length > 0) {
+ if (std::isdigit(arg[length]) == 0) {
break;
}
- --i;
+ --length;
}
- return {a.substr(0, i + 1), a.substr(i + 1, a.size() - i - 1)};
+ return {arg.substr(0, length + 1), arg.substr(length + 1, arg.size() - length - 1)};
}
-bool PrefixDashNumberCompare::operator()(const std::string& a, const std::string& b) const
+bool PrefixDashNumberCompare::operator()(const std::string& lhs, const std::string& rhs) const
{
- auto [aprefix, anum] = prefixAndTrailingNum(a);
- auto [bprefix, bnum] = prefixAndTrailingNum(b);
+ auto [aprefix, anum] = prefixAndTrailingNum(lhs);
+ auto [bprefix, bnum] = prefixAndTrailingNum(rhs);
if (aprefix != bprefix || anum.length() == 0 || bnum.length() == 0) {
- return a < b;
+ return lhs < rhs;
}
- auto aa = std::stoull(anum);
- auto bb = std::stoull(bnum);
- return aa < bb;
+ return std::stoull(anum) < std::stoull(bnum);
}
static map<string, const pdns::stat_t*> d_getatomics;
std::vector<std::string> disabledStats;
stringtok(disabledStats, stats, ", ");
auto& map = s_disabledStats[component];
- for (const auto& st : disabledStats) {
- map.insert(st);
+ for (const auto& stat : disabledStats) {
+ map.insert(stat);
}
}
{
std::string name = arg;
std::replace_if(
- name.begin(), name.end(), [](char c) { return !isalnum(static_cast<unsigned char>(c)); }, '_');
+ name.begin(), name.end(), [](char letter) { return isalnum(static_cast<unsigned char>(letter)) == 0; }, '_');
return "pdns_recursor_" + name;
}
std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName)
{
- auto dm = d_dynmetrics.lock();
- auto f = dm->find(str);
- if (f != dm->end()) {
- return f->second.d_ptr;
+ auto locked = d_dynmetrics.lock();
+ auto iter = locked->find(str);
+ if (iter != locked->end()) {
+ return iter->second.d_ptr;
}
std::string name(str);
}
auto ret = dynmetrics{new std::atomic<unsigned long>(), std::move(name)};
- (*dm)[str] = ret;
+ (*locked)[str] = ret;
return ret.d_ptr;
}
}
{
- auto dm = d_dynmetrics.lock();
- auto f = rplookup(*dm, name);
- if (f) {
- return f->d_ptr->load();
+ auto lcoked = d_dynmetrics.lock();
+ const auto* ptr = rplookup(*lcoked, name);
+ if (ptr != nullptr) {
+ return ptr->d_ptr->load();
}
}
}
{
- for (const auto& a : *(d_dynmetrics.lock())) {
- if (disabledlistMap.count(a.first) == 0) {
- ret.emplace(a.first, StatsMapEntry{a.second.d_prometheusName, std::to_string(*a.second.d_ptr)});
+ for (const auto& value : *(d_dynmetrics.lock())) {
+ if (disabledlistMap.count(value.first) == 0) {
+ ret.emplace(value.first, StatsMapEntry{value.second.d_prometheusName, std::to_string(*value.second.d_ptr)});
}
}
}
return ret;
}
-template <typename T>
-static string doGet(T begin, T end)
+using ArgIterator = vector<string>::iterator;
+
+static string doGet(ArgIterator begin, ArgIterator end)
{
string ret;
- for (T i = begin; i != end; ++i) {
+ for (auto i = begin; i != end; ++i) {
std::optional<uint64_t> num = get(*i);
- if (num)
+ if (num) {
ret += std::to_string(*num) + "\n";
- else
+ }
+ else {
ret += "UNKNOWN\n";
+ }
}
return ret;
}
-template <typename T>
-string static doGetParameter(T begin, T end)
+string static doGetParameter(ArgIterator begin, ArgIterator end)
{
string ret;
string parm;
using boost::replace_all;
- for (T i = begin; i != end; ++i) {
+ for (auto i = begin; i != end; ++i) {
if (::arg().parmIsset(*i)) {
parm = ::arg()[*i];
replace_all(parm, "\\", "\\\\");
replace_all(parm, "\n", "\\n");
ret += *i + "=\"" + parm + "\"\n";
}
- else
+ else {
ret += *i + " not known\n";
+ }
}
return ret;
}
/* Read an (open) fd from the control channel */
static FDWrapper
-getfd(int s)
+getfd(int socket)
{
- int fd = -1;
- struct msghdr msg;
- struct cmsghdr* cmsg;
+ int fileDesc = -1;
+ struct msghdr msg{};
+ struct cmsghdr* cmsg{};
union
{
struct cmsghdr hdr;
- unsigned char buf[CMSG_SPACE(sizeof(int))];
+ std::array<unsigned char, CMSG_SPACE(sizeof(int))> buf{};
} cmsgbuf;
- struct iovec io_vector[1];
- char ch;
+ std::array<struct iovec, 1> io_vector{};
+ char character = 0;
- io_vector[0].iov_base = &ch;
+ io_vector[0].iov_base = &character;
io_vector[0].iov_len = 1;
memset(&msg, 0, sizeof(msg));
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = sizeof(cmsgbuf.buf);
- msg.msg_iov = io_vector;
- msg.msg_iovlen = 1;
+ msg.msg_iov = io_vector.data();
+ msg.msg_iovlen = io_vector.size();
- if (recvmsg(s, &msg, 0) == -1) {
+ if (recvmsg(socket, &msg, 0) == -1) {
throw PDNSException("recvmsg");
}
- if ((msg.msg_flags & MSG_TRUNC) || (msg.msg_flags & MSG_CTRUNC)) {
+ if ((msg.msg_flags & MSG_TRUNC) != 0 || (msg.msg_flags & MSG_CTRUNC) != 0) {
throw PDNSException("control message truncated");
}
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != nullptr;
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
- fd = *(int*)CMSG_DATA(cmsg);
+ fileDesc = *reinterpret_cast<int*>(CMSG_DATA(cmsg)); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
break;
}
}
- return FDWrapper(fd);
+ return fileDesc;
}
-static uint64_t dumpAggressiveNSECCache(int fd)
+static uint64_t dumpAggressiveNSECCache(int fileDesc)
{
if (!g_aggressiveNSECCache) {
return 0;
}
- int newfd = dup(fd);
+ int newfd = dup(fileDesc);
if (newfd == -1) {
return 0;
}
}
fprintf(filePtr.get(), "; aggressive NSEC cache dump follows\n;\n");
- struct timeval now;
+ struct timeval now{};
Utility::gettimeofday(&now, nullptr);
return g_aggressiveNSECCache->dumpToFile(filePtr, now);
}
-static uint64_t* pleaseDumpEDNSMap(int fd)
+// NOLINTBEGIN(cppcoreguidelines-owning-memory)
+static uint64_t* pleaseDumpEDNSMap(int fileDesc)
{
- return new uint64_t(SyncRes::doEDNSDump(fd));
+ return new uint64_t(SyncRes::doEDNSDump(fileDesc));
}
-static uint64_t* pleaseDumpNSSpeeds(int fd)
+static uint64_t* pleaseDumpNSSpeeds(int fileDesc)
{
- return new uint64_t(SyncRes::doDumpNSSpeeds(fd));
+ return new uint64_t(SyncRes::doDumpNSSpeeds(fileDesc));
}
-static uint64_t* pleaseDumpThrottleMap(int fd)
+static uint64_t* pleaseDumpThrottleMap(int fileDesc)
{
- return new uint64_t(SyncRes::doDumpThrottleMap(fd));
+ return new uint64_t(SyncRes::doDumpThrottleMap(fileDesc));
}
-static uint64_t* pleaseDumpFailedServers(int fd)
+static uint64_t* pleaseDumpFailedServers(int fileDesc)
{
- return new uint64_t(SyncRes::doDumpFailedServers(fd));
+ return new uint64_t(SyncRes::doDumpFailedServers(fileDesc));
}
-static uint64_t* pleaseDumpSavedParentNSSets(int fd)
+static uint64_t* pleaseDumpSavedParentNSSets(int fileDesc)
{
- return new uint64_t(SyncRes::doDumpSavedParentNSSets(fd));
+ return new uint64_t(SyncRes::doDumpSavedParentNSSets(fileDesc));
}
-static uint64_t* pleaseDumpNonResolvingNS(int fd)
+static uint64_t* pleaseDumpNonResolvingNS(int fileDesc)
{
- return new uint64_t(SyncRes::doDumpNonResolvingNS(fd));
+ return new uint64_t(SyncRes::doDumpNonResolvingNS(fileDesc));
}
-static uint64_t* pleaseDumpDoTProbeMap(int fd)
+static uint64_t* pleaseDumpDoTProbeMap(int fileDesc)
{
- return new uint64_t(SyncRes::doDumpDoTProbeMap(fd));
+ return new uint64_t(SyncRes::doDumpDoTProbeMap(fileDesc));
}
+// NOLINTEND(cppcoreguidelines-owning-memory)
// Generic dump to file command
-static RecursorControlChannel::Answer doDumpToFile(int s, uint64_t* (*function)(int s), const string& name, bool threads = true)
+static RecursorControlChannel::Answer doDumpToFile(int socket, uint64_t* (*function)(int), const string& name, bool threads = true)
{
- auto fdw = getfd(s);
+ auto fdw = getfd(socket);
if (fdw < 0) {
return {1, name + ": error opening dump file for writing: " + stringerror() + "\n"};
uint64_t total = 0;
try {
if (threads) {
- int fd = fdw;
- total = broadcastAccFunction<uint64_t>([function, fd] { return function(fd); });
+ int fileDesc = fdw;
+ total = broadcastAccFunction<uint64_t>([function, fileDesc] { return function(fileDesc); });
}
else {
- auto ret = function(fdw);
+ auto* ret = function(fdw);
total = *ret;
- delete ret;
+ delete ret; // NOLINT(cppcoreguidelines-owning-memory)
}
}
catch (std::exception& e) {
}
// Does not follow the generic dump to file pattern, has a more complex lambda
-template <typename T>
-static RecursorControlChannel::Answer doDumpCache(int socket, T begin, T end)
+static RecursorControlChannel::Answer doDumpCache(int socket, ArgIterator begin, ArgIterator end)
{
auto fdw = getfd(socket);
}
}
catch (...) {
+ ;
}
return {0, "dumped " + std::to_string(total) + " records\n"};
}
// Does not follow the generic dump to file pattern, has an argument
-template <typename T>
-static RecursorControlChannel::Answer doDumpRPZ(int s, T begin, T end)
+static RecursorControlChannel::Answer doDumpRPZ(int socket, ArgIterator begin, ArgIterator end)
{
- auto fdw = getfd(s);
+ auto fdw = getfd(socket);
if (fdw < 0) {
return {1, "Error opening dump file for writing: " + stringerror() + "\n"};
}
- T i = begin;
+ auto iter = begin;
- if (i == end) {
+ if (iter == end) {
return {1, "No zone name specified\n"};
}
- string zoneName = *i;
+ const string& zoneName = *iter;
auto luaconf = g_luaconfs.getLocal();
const auto zone = luaconf->dfe.getZone(zoneName);
return {0, "done\n"};
}
-template <typename T>
-static string doWipeCache(T begin, T end, uint16_t qtype)
+static string doWipeCache(ArgIterator begin, ArgIterator end, uint16_t qtype)
{
vector<pair<DNSName, bool>> toWipe;
- for (T i = begin; i != end; ++i) {
+ for (auto i = begin; i != end; ++i) {
DNSName canon;
bool subtree = false;
toWipe.emplace_back(canon, subtree);
}
- int count = 0, pcount = 0, countNeg = 0;
+ int count = 0;
+ int pcount = 0;
+ int countNeg = 0;
for (const auto& wipe : toWipe) {
try {
auto res = wipeCaches(wipe.first, wipe.second, qtype);
return "wiped " + std::to_string(count) + " records, " + std::to_string(countNeg) + " negative records, " + std::to_string(pcount) + " packets\n";
}
-template <typename T>
-static string doSetCarbonServer(T begin, T end)
+static string doSetCarbonServer(ArgIterator begin, ArgIterator end)
{
auto config = g_carbonConfig.getCopy();
if (begin == end) {
return ret;
}
-template <typename T>
-static string doSetDnssecLogBogus(T begin, T end)
+static string doSetDnssecLogBogus(ArgIterator begin, ArgIterator end)
{
- if (checkDNSSECDisabled())
+ if (checkDNSSECDisabled()) {
return "DNSSEC is disabled in the configuration, not changing the Bogus logging setting\n";
-
- if (begin == end)
+ }
+ if (begin == end) {
return "No DNSSEC Bogus logging setting specified\n";
-
+ }
if (pdns_iequals(*begin, "on") || pdns_iequals(*begin, "yes")) {
if (!g_dnssecLogBogus) {
g_log << Logger::Warning << "Enabling DNSSEC Bogus logging, requested via control channel" << endl;
return "Unknown DNSSEC Bogus setting: '" + *begin + "'\n";
}
-template <typename T>
-static string doAddNTA(T begin, T end)
+static string doAddNTA(ArgIterator begin, ArgIterator end)
{
- if (checkDNSSECDisabled())
+ if (checkDNSSECDisabled()) {
return "DNSSEC is disabled in the configuration, not adding a Negative Trust Anchor\n";
-
- if (begin == end)
+ }
+ if (begin == end) {
return "No NTA specified, doing nothing\n";
-
+ }
DNSName who;
try {
who = DNSName(*begin);
}
begin++;
- string why("");
+ string why;
while (begin != end) {
why += *begin;
begin++;
- if (begin != end)
+ if (begin != end) {
why += " ";
+ }
}
g_log << Logger::Warning << "Adding Negative Trust Anchor for " << who << " with reason '" << why << "', requested via control channel" << endl;
g_luaconfs.modify([who, why](LuaConfigItems& lci) {
return "Added Negative Trust Anchor for " + who.toLogString() + " with reason '" + why + "'\n";
}
-template <typename T>
-static string doClearNTA(T begin, T end)
+static string doClearNTA(ArgIterator begin, ArgIterator end)
{
- if (checkDNSSECDisabled())
+ if (checkDNSSECDisabled()) {
return "DNSSEC is disabled in the configuration, not removing a Negative Trust Anchor\n";
-
- if (begin == end)
+ }
+ if (begin == end) {
return "No Negative Trust Anchor specified, doing nothing.\n";
-
+ }
if (begin + 1 == end && *begin == "*") {
g_log << Logger::Warning << "Clearing all Negative Trust Anchors, requested via control channel" << endl;
g_luaconfs.modify([](LuaConfigItems& lci) {
vector<DNSName> toRemove;
DNSName who;
while (begin != end) {
- if (*begin == "*")
+ if (*begin == "*") {
return "Don't mix all Negative Trust Anchor removal with multiple Negative Trust Anchor removal. Nothing removed\n";
+ }
try {
who = DNSName(*begin);
}
begin++;
}
- string removed("");
+ string removed;
bool first(true);
try {
for (auto const& entry : toRemove) {
static string getNTAs()
{
- if (checkDNSSECDisabled())
+ if (checkDNSSECDisabled()) {
return "DNSSEC is disabled in the configuration\n";
-
+ }
string ret("Configured Negative Trust Anchors:\n");
auto luaconf = g_luaconfs.getLocal();
- for (const auto& negAnchor : luaconf->negAnchors)
+ for (const auto& negAnchor : luaconf->negAnchors) {
ret += negAnchor.first.toLogString() + "\t" + negAnchor.second + "\n";
+ }
return ret;
}
-template <typename T>
-static string doAddTA(T begin, T end)
+static string doAddTA(ArgIterator begin, ArgIterator end)
{
- if (checkDNSSECDisabled())
+ if (checkDNSSECDisabled()) {
return "DNSSEC is disabled in the configuration, not adding a Trust Anchor\n";
-
- if (begin == end)
+ }
+ if (begin == end) {
return "No TA specified, doing nothing\n";
-
+ }
DNSName who;
try {
who = DNSName(*begin);
}
begin++;
- string what("");
+ string what;
while (begin != end) {
what += *begin + " ";
begin++;
try {
g_log << Logger::Warning << "Adding Trust Anchor for " << who << " with data '" << what << "', requested via control channel";
g_luaconfs.modify([who, what](LuaConfigItems& lci) {
- auto ds = std::dynamic_pointer_cast<DSRecordContent>(DSRecordContent::make(what));
- lci.dsAnchors[who].insert(*ds);
+ auto dsRecord = std::dynamic_pointer_cast<DSRecordContent>(DSRecordContent::make(what));
+ lci.dsAnchors[who].insert(*dsRecord);
});
wipeCaches(who, true, 0xffff);
g_log << Logger::Warning << endl;
}
}
-template <typename T>
-static string doClearTA(T begin, T end)
+static string doClearTA(ArgIterator begin, ArgIterator end)
{
- if (checkDNSSECDisabled())
+ if (checkDNSSECDisabled()) {
return "DNSSEC is disabled in the configuration, not removing a Trust Anchor\n";
-
- if (begin == end)
+ }
+ if (begin == end) {
return "No Trust Anchor to clear\n";
-
+ }
vector<DNSName> toRemove;
DNSName who;
while (begin != end) {
ret += ". No Anchors removed\n";
return ret;
}
- if (who.isRoot())
+ if (who.isRoot()) {
return "Refusing to remove root Trust Anchor, no Anchors removed\n";
+ }
toRemove.push_back(who);
begin++;
}
- string removed("");
- bool first(true);
+ string removed;
+ bool first = true;
try {
for (auto const& entry : toRemove) {
g_log << Logger::Warning << "Removing Trust Anchor for " << entry << ", requested via control channel" << endl;
static string getTAs()
{
- if (checkDNSSECDisabled())
+ if (checkDNSSECDisabled()) {
return "DNSSEC is disabled in the configuration\n";
-
+ }
string ret("Configured Trust Anchors:\n");
auto luaconf = g_luaconfs.getLocal();
for (const auto& anchor : luaconf->dsAnchors) {
ret += anchor.first.toLogString() + "\n";
- for (const auto& e : anchor.second) {
- ret += "\t\t" + e.getZoneRepresentation() + "\n";
+ for (const auto& entry : anchor.second) {
+ ret += "\t\t" + entry.getZoneRepresentation() + "\n";
}
}
return ret;
}
-template <typename T>
-static string setMinimumTTL(T begin, T end)
+static string setMinimumTTL(ArgIterator begin, ArgIterator end)
{
- if (end - begin != 1)
+ if (end - begin != 1) {
return "Need to supply new minimum TTL number\n";
+ }
try {
pdns::checked_stoi_into(SyncRes::s_minimumTTL, *begin);
return "New minimum TTL: " + std::to_string(SyncRes::s_minimumTTL) + "\n";
}
}
-template <typename T>
-static string setMinimumECSTTL(T begin, T end)
+static string setMinimumECSTTL(ArgIterator begin, ArgIterator end)
{
- if (end - begin != 1)
+ if (end - begin != 1) {
return "Need to supply new ECS minimum TTL number\n";
+ }
try {
pdns::checked_stoi_into(SyncRes::s_minimumECSTTL, *begin);
return "New minimum ECS TTL: " + std::to_string(SyncRes::s_minimumECSTTL) + "\n";
}
}
-template <typename T>
-static string setMaxCacheEntries(T begin, T end)
+static string setMaxCacheEntries(ArgIterator begin, ArgIterator end)
{
- if (end - begin != 1)
+ if (end - begin != 1) {
return "Need to supply new cache size\n";
+ }
try {
g_maxCacheEntries = pdns::checked_stoi<uint32_t>(*begin);
return "New max cache entries: " + std::to_string(g_maxCacheEntries) + "\n";
}
}
-template <typename T>
-static string setMaxPacketCacheEntries(T begin, T end)
+static string setMaxPacketCacheEntries(ArgIterator begin, ArgIterator end)
{
- if (end - begin != 1)
+ if (end - begin != 1) {
return "Need to supply new packet cache size\n";
+ }
if (::arg().mustDo("disable-packetcache")) {
return "Packet cache is disabled\n";
}
}
}
-template <typename T>
-static RecursorControlChannel::Answer setAggrNSECCacheSize(T begin, T end)
+static RecursorControlChannel::Answer setAggrNSECCacheSize(ArgIterator begin, ArgIterator end)
{
if (end - begin != 1) {
return {1, "Need to supply new aggressive NSEC cache size\n"};
static uint64_t getSysTimeMsec()
{
- struct rusage ru;
- getrusage(RUSAGE_SELF, &ru);
- return (ru.ru_stime.tv_sec * 1000ULL + ru.ru_stime.tv_usec / 1000);
+ struct rusage usage{};
+ getrusage(RUSAGE_SELF, &usage);
+ return (usage.ru_stime.tv_sec * 1000ULL) + (usage.ru_stime.tv_usec / 1000);
}
static uint64_t getUserTimeMsec()
{
- struct rusage ru;
- getrusage(RUSAGE_SELF, &ru);
- return (ru.ru_utime.tv_sec * 1000ULL + ru.ru_utime.tv_usec / 1000);
+ struct rusage usage{};
+ getrusage(RUSAGE_SELF, &usage);
+ return (usage.ru_utime.tv_sec * 1000ULL) + (usage.ru_utime.tv_usec / 1000);
}
/* This is a pretty weird set of functions. To get per-thread cpu usage numbers,
ret = (ru.ru_utime.tv_sec * 1000ULL + ru.ru_utime.tv_usec / 1000);
ret += (ru.ru_stime.tv_sec * 1000ULL + ru.ru_stime.tv_usec / 1000);
#endif
- return new ThreadTimes{ret, vector<uint64_t>()};
+ return new ThreadTimes{ret, vector<uint64_t>()}; // NOLINT(cppcoreguidelines-owning-memory)
}
/* Next up, when you want msec data for a specific thread, we check
We then answer you from the (re)fresh(ed) ThreadTimes.
*/
-static uint64_t doGetThreadCPUMsec(int n)
+static uint64_t doGetThreadCPUMsec(unsigned int n)
{
static std::mutex s_mut;
static time_t last = 0;
- static ThreadTimes tt;
+ static ThreadTimes threadTimes;
auto lock = std::scoped_lock(s_mut);
if (last != time(nullptr)) {
- tt = broadcastAccFunction<ThreadTimes>(pleaseGetThreadCPUMsec);
+ threadTimes = broadcastAccFunction<ThreadTimes>(pleaseGetThreadCPUMsec);
last = time(nullptr);
}
- return tt.times.at(n);
+ return threadTimes.times.at(n);
}
static ProxyMappingStats_t* pleaseGetProxyMappingStats()
{
- auto ret = new ProxyMappingStats_t;
+ auto* ret = new ProxyMappingStats_t; // NOLINT(cppcoreguidelines-owning-memory)
if (t_proxyMapping) {
for (const auto& [key, entry] : *t_proxyMapping) {
ret->emplace(key, ProxyMappingCounts{entry.stats.netmaskMatches, entry.stats.suffixMatches});
static RemoteLoggerStats_t* pleaseGetRemoteLoggerStats()
{
- auto ret = make_unique<RemoteLoggerStats_t>();
+ auto ret = make_unique<RemoteLoggerStats_t>(); // NOLINT(cppcoreguidelines-owning-memory)
if (t_protobufServers.servers) {
for (const auto& server : *t_protobufServers.servers) {
static string* pleaseGetCurrentQueries()
{
ostringstream ostr;
- struct timeval now;
- gettimeofday(&now, 0);
+ struct timeval now{};
+ gettimeofday(&now, nullptr);
ostr << getMT()->getWaiters().size() << " currently outstanding questions\n";
boost::format fmt("%1% %|40t|%2% %|47t|%3% %|63t|%4% %|68t|%5% %|78t|%6%\n");
ostr << (fmt % "qname" % "qtype" % "remote" % "tcp" % "chained" % "spent(ms)");
- unsigned int n = 0;
+ unsigned int count = 0;
for (const auto& mthread : getMT()->getWaiters()) {
const std::shared_ptr<PacketID>& pident = mthread.key;
const double spent = g_networkTimeoutMsec - (DiffTime(now, mthread.ttd) * 1000);
ostr << (fmt
% pident->domain.toLogString() /* ?? */ % DNSRecordContent::NumberToType(pident->type)
- % pident->remote.toString() % (pident->tcpsock ? 'Y' : 'n')
+ % pident->remote.toString() % ((pident->tcpsock != 0) ? 'Y' : 'n')
% (pident->fd == -1 ? 'Y' : 'n')
% (spent > 0 ? spent : '0'));
- ++n;
- if (n >= 100)
+ ++count;
+ if (count >= 100) {
break;
+ }
}
ostr << " - done\n";
- return new string(ostr.str());
+ return new string(ostr.str()); // NOLINT(cppcoreguidelines-owning-memory)
}
static string doCurrentQueries()
uint64_t* pleaseGetConcurrentQueries()
{
- return new uint64_t(getMT() ? getMT()->numProcesses() : 0);
+ return new uint64_t((getMT() != nullptr) ? getMT()->numProcesses() : 0); // NOLINT(cppcoreguidelines-owning-memory)
}
static uint64_t getConcurrentQueries()
const auto& data = histogram.getCumulativeBuckets();
const string pbasename = getPrometheusName(name);
StatsMap entries;
- char buf[32];
+ std::array<char, 32> buf{};
for (const auto& bucket : data) {
- snprintf(buf, sizeof(buf), "%g", bucket.d_boundary / 1e6);
- std::string pname = pbasename + "seconds_bucket{" + "le=\"" + (bucket.d_boundary == std::numeric_limits<uint64_t>::max() ? "+Inf" : buf) + "\"}";
+ snprintf(buf.data(), buf.size(), "%g", static_cast<double>(bucket.d_boundary) / 1e6);
+ std::string pname = pbasename + "seconds_bucket{" + "le=\"" + (bucket.d_boundary == std::numeric_limits<uint64_t>::max() ? "+Inf" : buf.data()) + "\"}";
entries.emplace(bucket.d_name, StatsMapEntry{std::move(pname), std::to_string(bucket.d_count)});
}
- snprintf(buf, sizeof(buf), "%g", histogram.getSum() / 1e6);
- entries.emplace(name + "sum", StatsMapEntry{pbasename + "seconds_sum", buf});
+ snprintf(buf.data(), buf.size(), "%g", static_cast<double>(histogram.getSum()) / 1e6);
+ entries.emplace(name + "sum", StatsMapEntry{pbasename + "seconds_sum", buf.data()});
entries.emplace(name + "count", StatsMapEntry{pbasename + "seconds_count", std::to_string(data.back().d_count)});
return entries;
{
const string pbasename = getPrometheusName(name);
StatsMap entries;
- char buf[32];
+ std::array<char, 32> buf{};
std::string pname;
const auto& data4 = histogram4.getCumulativeBuckets();
for (const auto& bucket : data4) {
- snprintf(buf, sizeof(buf), "%g", bucket.d_boundary / 1e6);
- pname = pbasename + "seconds_bucket{ipversion=\"v4\",le=\"" + (bucket.d_boundary == std::numeric_limits<uint64_t>::max() ? "+Inf" : buf) + "\"}";
+ snprintf(buf.data(), buf.size(), "%g", static_cast<double>(bucket.d_boundary) / 1e6);
+ pname = pbasename + R"(seconds_bucket{ipversion="v4",le=")" + (bucket.d_boundary == std::numeric_limits<uint64_t>::max() ? "+Inf" : buf.data()) + "\"}";
entries.emplace(bucket.d_name + "4", StatsMapEntry{pname, std::to_string(bucket.d_count)});
}
- snprintf(buf, sizeof(buf), "%g", histogram4.getSum() / 1e6);
- entries.emplace(name + "sum4", StatsMapEntry{pbasename + "seconds_sum{ipversion=\"v4\"}", buf});
+ snprintf(buf.data(), buf.size(), "%g", static_cast<double>(histogram4.getSum()) / 1e6);
+ entries.emplace(name + "sum4", StatsMapEntry{pbasename + "seconds_sum{ipversion=\"v4\"}", buf.data()});
entries.emplace(name + "count4", StatsMapEntry{pbasename + "seconds_count{ipversion=\"v4\"}", std::to_string(data4.back().d_count)});
const auto& data6 = histogram6.getCumulativeBuckets();
for (const auto& bucket : data6) {
- snprintf(buf, sizeof(buf), "%g", bucket.d_boundary / 1e6);
- pname = pbasename + "seconds_bucket{ipversion=\"v6\",le=\"" + (bucket.d_boundary == std::numeric_limits<uint64_t>::max() ? "+Inf" : buf) + "\"}";
+ snprintf(buf.data(), buf.size(), "%g", static_cast<double>(bucket.d_boundary) / 1e6);
+ pname = pbasename + R"(seconds_bucket{ipversion="v6",le=")" + (bucket.d_boundary == std::numeric_limits<uint64_t>::max() ? "+Inf" : buf.data()) + "\"}";
entries.emplace(bucket.d_name + "6", StatsMapEntry{pname, std::to_string(bucket.d_count)});
}
- snprintf(buf, sizeof(buf), "%g", histogram6.getSum() / 1e6);
- entries.emplace(name + "sum6", StatsMapEntry{pbasename + "seconds_sum{ipversion=\"v6\"}", buf});
+ snprintf(buf.data(), buf.size(), "%g", static_cast<double>(histogram6.getSum()) / 1e6);
+ entries.emplace(name + "sum6", StatsMapEntry{pbasename + "seconds_sum{ipversion=\"v6\"}", buf.data()});
entries.emplace(name + "count6", StatsMapEntry{pbasename + "seconds_count{ipversion=\"v6\"}", std::to_string(data6.back().d_count)});
return entries;
const string pbasename = getPrometheusName(name);
StatsMap entries;
- uint8_t n = 0;
+ uint8_t count = 0;
auto rcodes = g_Counters.sum(rec::RCode::auth).rcodeCounters;
for (const auto& entry : rcodes) {
- const auto key = RCode::to_short_s(n);
- std::string pname = pbasename + "{rcode=\"" + key + "\"}";
+ const auto key = RCode::to_short_s(count);
+ std::string pname = pbasename;
+ pname += "{rcode=\"" + key + "\"}";
entries.emplace("auth-" + key + "-answers", StatsMapEntry{std::move(pname), std::to_string(entry)});
- n++;
+ count++;
}
return entries;
}
StatsMap entries;
// Handler is not reported
- for (unsigned int n = 0; n < RecThreadInfo::numRecursorThreads() - 1; ++n) {
- uint64_t tm = doGetThreadCPUMsec(n);
- std::string pname = pbasename + "{thread=\"" + std::to_string(n) + "\"}";
- entries.emplace(name + "-thread-" + std::to_string(n), StatsMapEntry{std::move(pname), std::to_string(tm)});
+ for (unsigned int thread = 0; thread < RecThreadInfo::numRecursorThreads() - 1; ++thread) {
+ uint64_t timeTaken = doGetThreadCPUMsec(thread);
+ std::string pname = pbasename + "{thread=\"" + std::to_string(thread) + "\"}";
+ entries.emplace(name + "-thread-" + std::to_string(thread), StatsMapEntry{std::move(pname), std::to_string(timeTaken)});
}
return entries;
}
for (const auto& entry : map) {
const auto& key = entry.first;
auto count = entry.second;
- std::string sname, pname;
+ std::string sname;
+ std::string pname;
if (key.empty()) {
sname = name + "-filter";
pname = pbasename + "{type=\"filter\"}";
}
else {
- sname = name + "-rpz-" + key;
- pname = pbasename + "{type=\"rpz\",policyname=\"" + key + "\"}";
+ sname = name;
+ sname += "-rpz-" + key;
+ pname = pbasename;
+ pname += R"({type="rpz",policyname=")" + key + "\"}";
}
entries.emplace(sname, StatsMapEntry{std::move(pname), std::to_string(count)});
total += count;
uint64_t count = 0;
for (const auto& [stats, type] : list) {
for (const auto& [key, entry] : stats) {
- auto keyname = pbasename + "{address=\"" + key + "\",type=\"" + type + "\",count=\"";
+ auto keyname = pbasename;
+ keyname += "{address=\"" + key + "\",type=\"";
+ keyname += type + "\",count=\"";
auto sname1 = name + "-q-" + std::to_string(count);
auto pname1 = keyname + "queued\"}";
entries.emplace(sname1, StatsMapEntry{std::move(pname1), std::to_string(entry.d_queued)});
}
catch (...) {
g_log << Logger::Critical << "Could not add stat entries" << endl;
- exit(1);
+ exit(1); // NOLINT(concurrency-mt-unsafe)
}
}
doExitGeneric(true);
}
+// NOLINTBEGIN(cppcoreguidelines-owning-memory)
vector<pair<DNSName, uint16_t>>* pleaseGetQueryRing()
{
- typedef pair<DNSName, uint16_t> query_t;
- vector<query_t>* ret = new vector<query_t>();
- if (!t_queryring)
+ using query_t = pair<DNSName, uint16_t>;
+ auto* ret = new vector<query_t>();
+ if (!t_queryring) {
return ret;
+ }
ret->reserve(t_queryring->size());
- for (const query_t& q : *t_queryring) {
- ret->push_back(q);
+ for (const query_t& query : *t_queryring) {
+ ret->emplace_back(query);
}
return ret;
}
vector<pair<DNSName, uint16_t>>* pleaseGetServfailQueryRing()
{
- typedef pair<DNSName, uint16_t> query_t;
- vector<query_t>* ret = new vector<query_t>();
- if (!t_servfailqueryring)
+ using query_t = pair<DNSName, uint16_t>;
+ auto* ret = new vector<query_t>();
+ if (!t_servfailqueryring) {
return ret;
+ }
ret->reserve(t_servfailqueryring->size());
- for (const query_t& q : *t_servfailqueryring) {
- ret->push_back(q);
+ for (const query_t& query : *t_servfailqueryring) {
+ ret->emplace_back(query);
}
return ret;
}
vector<pair<DNSName, uint16_t>>* pleaseGetBogusQueryRing()
{
- typedef pair<DNSName, uint16_t> query_t;
- vector<query_t>* ret = new vector<query_t>();
- if (!t_bogusqueryring)
+ using query_t = pair<DNSName, uint16_t>;
+ auto* ret = new vector<query_t>();
+ if (!t_bogusqueryring) {
return ret;
+ }
ret->reserve(t_bogusqueryring->size());
- for (const query_t& q : *t_bogusqueryring) {
- ret->push_back(q);
+ for (const query_t& query : *t_bogusqueryring) {
+ ret->emplace_back(query);
}
return ret;
}
-typedef std::function<vector<ComboAddress>*()> pleaseremotefunc_t;
-typedef std::function<vector<pair<DNSName, uint16_t>>*()> pleasequeryfunc_t;
+using pleaseremotefunc_t = std::function<vector<ComboAddress>*()>;
+using pleasequeryfunc_t = std::function<vector<pair<DNSName, uint16_t>>*()>;
vector<ComboAddress>* pleaseGetRemotes()
{
- vector<ComboAddress>* ret = new vector<ComboAddress>();
- if (!t_remotes)
+ auto* ret = new vector<ComboAddress>();
+ if (!t_remotes) {
return ret;
-
+ }
ret->reserve(t_remotes->size());
- for (const ComboAddress& ca : *t_remotes) {
- ret->push_back(ca);
+ for (const ComboAddress& address : *t_remotes) {
+ ret->emplace_back(address);
}
return ret;
}
vector<ComboAddress>* pleaseGetServfailRemotes()
{
- vector<ComboAddress>* ret = new vector<ComboAddress>();
- if (!t_servfailremotes)
+ auto* ret = new vector<ComboAddress>();
+ if (!t_servfailremotes) {
return ret;
+ }
ret->reserve(t_servfailremotes->size());
- for (const ComboAddress& ca : *t_servfailremotes) {
- ret->push_back(ca);
+ for (const ComboAddress& address : *t_servfailremotes) {
+ ret->push_back(address);
}
return ret;
}
vector<ComboAddress>* pleaseGetBogusRemotes()
{
- vector<ComboAddress>* ret = new vector<ComboAddress>();
- if (!t_bogusremotes)
+ auto* ret = new vector<ComboAddress>();
+ if (!t_bogusremotes) {
return ret;
+ }
ret->reserve(t_bogusremotes->size());
- for (const ComboAddress& ca : *t_bogusremotes) {
- ret->push_back(ca);
+ for (const ComboAddress& address : *t_bogusremotes) {
+ ret->emplace_back(address);
}
return ret;
}
vector<ComboAddress>* pleaseGetLargeAnswerRemotes()
{
- vector<ComboAddress>* ret = new vector<ComboAddress>();
- if (!t_largeanswerremotes)
+ auto* ret = new vector<ComboAddress>();
+ if (!t_largeanswerremotes) {
return ret;
+ }
ret->reserve(t_largeanswerremotes->size());
- for (const ComboAddress& ca : *t_largeanswerremotes) {
- ret->push_back(ca);
+ for (const ComboAddress& address : *t_largeanswerremotes) {
+ ret->emplace_back(address);
}
return ret;
}
vector<ComboAddress>* pleaseGetTimeouts()
{
- vector<ComboAddress>* ret = new vector<ComboAddress>();
- if (!t_timeouts)
+ auto* ret = new vector<ComboAddress>();
+ if (!t_timeouts) {
return ret;
+ }
ret->reserve(t_timeouts->size());
- for (const ComboAddress& ca : *t_timeouts) {
- ret->push_back(ca);
+ for (const ComboAddress& address : *t_timeouts) {
+ ret->emplace_back(address);
}
return ret;
}
+// NOLINTEND(cppcoreguidelines-owning-memory)
static string doGenericTopRemotes(const pleaseremotefunc_t& func)
{
DNSName getRegisteredName(const DNSName& dom)
{
auto parts = dom.getRawLabels();
- if (parts.size() <= 2)
+ if (parts.size() <= 2) {
return dom;
+ }
reverse(parts.begin(), parts.end());
for (string& str : parts) {
str = toLower(str);
if (parts.size() == 1 || binary_search(g_pubs.begin(), g_pubs.end(), parts)) {
string ret = std::move(last);
- if (!ret.empty())
+ if (!ret.empty()) {
ret += ".";
-
- for (auto p = parts.crbegin(); p != parts.crend(); ++p) {
- ret += (*p) + ".";
+ }
+ for (auto part = parts.crbegin(); part != parts.crend(); ++part) {
+ ret += (*part) + ".";
}
return DNSName(ret);
}
static string* nopFunction()
{
- return new string("pong " + RecThreadInfo::self().getName() + '\n');
+ return new string("pong " + RecThreadInfo::self().getName() + '\n'); // NOLINT(cppcoreguidelines-owning-memory)
}
static string getDontThrottleNames()
return dtn->toString() + "\n";
}
-template <typename T>
-static string addDontThrottleNames(T begin, T end)
+static string addDontThrottleNames(ArgIterator begin, ArgIterator end)
{
if (begin == end) {
return "No names specified, keeping existing list\n";
vector<DNSName> toAdd;
while (begin != end) {
try {
- auto d = DNSName(*begin);
- toAdd.push_back(std::move(d));
+ auto name = DNSName(*begin);
+ toAdd.emplace_back(std::move(name));
}
catch (const std::exception& e) {
return "Problem parsing '" + *begin + "': " + e.what() + ", nothing added\n";
string ret = "Added";
auto dnt = g_dontThrottleNames.getCopy();
bool first = true;
- for (auto const& d : toAdd) {
+ for (auto const& name : toAdd) {
if (!first) {
ret += ",";
}
first = false;
- ret += " " + d.toLogString();
- dnt.add(d);
+ ret += " " + name.toLogString();
+ dnt.add(name);
}
g_dontThrottleNames.setState(std::move(dnt));
return ret + "\n";
}
-template <typename T>
-static string addDontThrottleNetmasks(T begin, T end)
+static string addDontThrottleNetmasks(ArgIterator begin, ArgIterator end)
{
if (begin == end) {
return "No netmasks specified, keeping existing list\n";
vector<Netmask> toAdd;
while (begin != end) {
try {
- auto n = Netmask(*begin);
- toAdd.push_back(n);
+ auto netmask = Netmask(*begin);
+ toAdd.push_back(netmask);
}
catch (const std::exception& e) {
return "Problem parsing '" + *begin + "': " + e.what() + ", nothing added\n";
string ret = "Added";
auto dnt = g_dontThrottleNetmasks.getCopy();
bool first = true;
- for (auto const& t : toAdd) {
+ for (auto const& netmask : toAdd) {
if (!first) {
ret += ",";
}
first = false;
- ret += " " + t.toString();
- dnt.addMask(t);
+ ret += " " + netmask.toString();
+ dnt.addMask(netmask);
}
g_dontThrottleNetmasks.setState(std::move(dnt));
return ret + "\n";
}
-template <typename T>
-static string clearDontThrottleNames(T begin, T end)
+static string clearDontThrottleNames(ArgIterator begin, ArgIterator end)
{
- if (begin == end)
+ if (begin == end) {
return "No names specified, doing nothing.\n";
-
+ }
if (begin + 1 == end && *begin == "*") {
SuffixMatchNode smn;
g_dontThrottleNames.setState(std::move(smn));
if (*begin == "*") {
return "Please don't mix '*' with other names, nothing removed\n";
}
- toRemove.push_back(DNSName(*begin));
+ toRemove.emplace_back(*begin);
}
catch (const std::exception& e) {
return "Problem parsing '" + *begin + "': " + e.what() + ", nothing removed\n";
return ret + "\n";
}
-template <typename T>
-static string clearDontThrottleNetmasks(T begin, T end)
+static string clearDontThrottleNetmasks(ArgIterator begin, ArgIterator end)
{
- if (begin == end)
+ if (begin == end) {
return "No netmasks specified, doing nothing.\n";
-
+ }
if (begin + 1 == end && *begin == "*") {
auto nmg = g_dontThrottleNetmasks.getCopy();
nmg.clear();
if (*begin == "*") {
return "Please don't mix '*' with other netmasks, nothing removed\n";
}
- auto n = Netmask(*begin);
- toRemove.push_back(n);
+ auto netmask = Netmask(*begin);
+ toRemove.push_back(netmask);
}
catch (const std::exception& e) {
return "Problem parsing '" + *begin + "': " + e.what() + ", nothing added\n";
return ret + "\n";
}
-template <typename T>
-static string setEventTracing(T begin, T end)
+static string setEventTracing(ArgIterator begin, ArgIterator end)
{
if (begin == end) {
return "No event trace enabled value specified\n";
}
}
-static void* pleaseSupplantProxyMapping(const ProxyMapping& pm)
+static void* pleaseSupplantProxyMapping(const ProxyMapping& proxyMapping)
{
- if (pm.empty()) {
+ if (proxyMapping.empty()) {
t_proxyMapping = nullptr;
}
else {
// Copy the existing stats values, for the new config items also present in the old
auto newmapping = make_unique<ProxyMapping>();
- for (const auto& [nm, entry] : pm) {
+ for (const auto& [nm, entry] : proxyMapping) {
auto& newentry = newmapping->insert(nm);
newentry.second = entry;
if (t_proxyMapping) {
}
}
-template <typename T>
-static RecursorControlChannel::Answer luaconfig(T begin, T end)
+static RecursorControlChannel::Answer luaconfig(ArgIterator begin, ArgIterator end)
{
if (begin != end) {
if (g_luaSettingsInYAML) {