Plus a few remaining cases for startup abnd config.
#ifdef RECURSOR
#include "logger.hh"
+#include "logging.hh"
#else
#include "dolog.hh"
#endif
uint8_t *frame = (uint8_t*)malloc(data.length());
if (!frame) {
#ifdef RECURSOR
- g_log<<Logger::Warning<<"FrameStreamLogger: cannot allocate memory for stream."<<std::endl;
+ SLOG(g_log<<Logger::Warning<<"FrameStreamLogger: cannot allocate memory for stream."<<std::endl,
+ g_slog->withName("dnstap")->info(Logr::Warning, "cannot allocate memory for stream"));
#else
warnlog("FrameStreamLogger: cannot allocate memory for stream.");
#endif
} else if (res == fstrm_res_again) {
free(frame);
#ifdef RECURSOR
- g_log<<Logger::Debug<<"FrameStreamLogger: queue full, dropping."<<std::endl;
+ SLOG(g_log<<Logger::Debug<<"FrameStreamLogger: queue full, dropping."<<std::endl,
+ g_slog->withName("dnstap")->info(Logr::Debug, "queue full, dropping"));
#else
vinfolog("FrameStreamLogger: queue full, dropping.");
#endif
// Permanent failure.
free(frame);
#ifdef RECURSOR
- g_log<<Logger::Warning<<"FrameStreamLogger: submitting to queue failed."<<std::endl;
+ SLOG(g_log<<Logger::Warning<<"FrameStreamLogger: submitting to queue failed."<<std::endl,
+ g_slog->withName("dnstap")->info(Logr::Warning, "submitting to queue failed"));
#else
warnlog("FrameStreamLogger: submitting to queue failed.");
#endif
setSocketReceiveBuffer(fd, 250000);
}
catch (const std::exception& e) {
- g_log << Logger::Error << e.what() << endl;
+ SLOG(g_log << Logger::Error << e.what() << endl,
+ log->error(Logr::Error, e.what(), "Exception while setting socker buffer size"));
}
sin.sin4.sin_port = htons(st.port);
if (have.count("refresh")) {
refresh = boost::get<uint32_t>(have["refresh"]);
if (refresh == 0) {
- g_log << Logger::Warning << "rpzPrimary refresh value of 0 ignored" << endl;
+ SLOG(g_log << Logger::Warning << "rpzPrimary refresh value of 0 ignored" << endl,
+ lci.d_slog->info(Logr::Warning, "rpzPrimary refresh value of 0 ignored"));
}
}
zone->setName(polName);
zoneIdx = lci.dfe.addZone(zone);
+ auto log = lci.d_slog->withValues("seedfile", Logging::Loggable(seedFile), "zone", Logging::Loggable(zoneName));
if (!seedFile.empty()) {
- g_log << Logger::Info << "Pre-loading RPZ zone " << zoneName << " from seed file '" << seedFile << "'" << endl;
+ SLOG(g_log << Logger::Info << "Pre-loading RPZ zone " << zoneName << " from seed file '" << seedFile << "'" << endl,
+ log->info(Logr::Info, "Pre-loading RPZ zone from seed file"));
try {
sr = loadRPZFromFile(seedFile, zone, defpol, defpolOverrideLocal, maxTTL);
}
}
catch (const PDNSException& e) {
- g_log << Logger::Warning << "Unable to pre-load RPZ zone " << zoneName << " from seed file '" << seedFile << "': " << e.reason << endl;
+ SLOG(g_log << Logger::Warning << "Unable to pre-load RPZ zone " << zoneName << " from seed file '" << seedFile << "': " << e.reason << endl,
+ log->error(Logr::Warning, e.reason, "Exception while pre-loadin RPZ zone", "exception", Logging::Loggable("PDNSException")));
zone->clear();
}
catch (const std::exception& e) {
- g_log << Logger::Warning << "Unable to pre-load RPZ zone " << zoneName << " from seed file '" << seedFile << "': " << e.what() << endl;
+ SLOG(g_log << Logger::Warning << "Unable to pre-load RPZ zone " << zoneName << " from seed file '" << seedFile << "': " << e.what() << endl,
+ log->error(Logr::Warning, e.what(), "Exception while pre-loadin RPZ zone", "exception", Logging::Loggable("std::exception")));
zone->clear();
}
}
}
catch (const std::exception& e) {
- g_log << Logger::Error << "Problem configuring 'rpzPrimary': " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "Problem configuring 'rpzPrimary': " << e.what() << endl,
+ lci.d_slog->error(Logr::Critical, e.what(), "Exception configuring 'rpzPrimary'", "exception", Logging::Loggable("std::exception")));
exit(1); // FIXME proper exit code?
}
catch (const PDNSException& e) {
- g_log << Logger::Error << "Problem configuring 'rpzPrimary': " << e.reason << endl;
+ SLOG(g_log << Logger::Error << "Problem configuring 'rpzPrimary': " << e.reason << endl,
+ lci.d_slog->error(Logr::Critical, e.reason, "Exception configuring 'rpzPrimary'", Logging::Loggable("PDNSException")));
exit(1); // FIXME proper exit code?
}
void loadRecursorLuaConfig(const std::string& fname, luaConfigDelayedThreads& delayedThreads, ProxyMapping& proxyMapping)
{
LuaConfigItems lci;
+ lci.d_slog = g_slog->withName("luaconfig");
RecLuaConfigContext Lua;
Lua->writeVariable("Policy", pmap);
Lua->writeFunction("rpzFile", [&lci](const string& filename, boost::optional<rpzOptions_t> options) {
+ auto log = lci.d_slog->withValues("file", Logging::Loggable(filename));
try {
boost::optional<DNSFilterEngine::Policy> defpol;
bool defpolOverrideLocal = true;
auto& have = *options;
parseRPZParameters(have, zone, polName, defpol, defpolOverrideLocal, maxTTL);
}
- g_log << Logger::Warning << "Loading RPZ from file '" << filename << "'" << endl;
+ SLOG(g_log << Logger::Warning << "Loading RPZ from file '" << filename << "'" << endl,
+ log->info(Logr::Info, "Loading RPZ from file"));
zone->setName(polName);
loadRPZFromFile(filename, zone, defpol, defpolOverrideLocal, maxTTL);
lci.dfe.addZone(zone);
- g_log << Logger::Warning << "Done loading RPZ from file '" << filename << "'" << endl;
+ SLOG(g_log << Logger::Warning << "Done loading RPZ from file '" << filename << "'" << endl,
+ log->info(Logr::Info, "Done loading RPZ from file"));
}
catch (const std::exception& e) {
- g_log << Logger::Error << "Unable to load RPZ zone from '" << filename << "': " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "Unable to load RPZ zone from '" << filename << "': " << e.what() << endl,
+ log->error(Logr::Error, e.what(), "Exception while loadinf RPZ zone from file"));
}
});
Lua->writeFunction("rpzMaster", [&lci, &delayedThreads](const boost::variant<string, std::vector<std::pair<int, string>>>& primaries_, const string& zoneName, boost::optional<rpzOptions_t> options) {
- g_log << Logger::Warning << "'rpzMaster' is deprecated and will be removed in a future release, use 'rpzPrimary' instead" << endl;
+ SLOG(g_log << Logger::Warning << "'rpzMaster' is deprecated and will be removed in a future release, use 'rpzPrimary' instead" << endl,
+ lci.d_slog->info(Logr::Warning, "'rpzMaster' is deprecated and will be removed in a future release, use 'rpzPrimary' instead"));
rpzPrimary(lci, delayedThreads, primaries_, zoneName, options);
});
Lua->writeFunction("rpzPrimary", [&lci, &delayedThreads](const boost::variant<string, std::vector<std::pair<int, string>>>& primaries_, const string& zoneName, boost::optional<rpzOptions_t> options) {
if (interval) {
realInterval = static_cast<uint32_t>(*interval);
}
- auto log = g_slog->withName("config");
warnIfDNSSECDisabled("Warning: reading Trust Anchors from file (readTrustAnchorsFromFile), but dnssec is set to 'off'!");
lci.trustAnchorFileInfo.fname = fnamearg;
lci.trustAnchorFileInfo.interval = realInterval;
- updateTrustAnchorsFromFile(fnamearg, lci.dsAnchors, log);
+ updateTrustAnchorsFromFile(fnamearg, lci.dsAnchors, lci.d_slog);
});
Lua->writeFunction("setProtobufMasks", [&lci](const uint8_t maskV4, uint8_t maskV6) {
parseProtobufOptions(vars, lci.protobufExportConfig);
}
catch (std::exception& e) {
- g_log << Logger::Error << "Error while adding protobuf logger: " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "Error while adding protobuf logger: " << e.what() << endl,
+ lci.d_slog->error(Logr::Error, e.what(), "Exception while adding protobuf logger", "exception", Logging::Loggable("std::exception")));
}
catch (PDNSException& e) {
- g_log << Logger::Error << "Error while adding protobuf logger: " << e.reason << endl;
+ SLOG(g_log << Logger::Error << "Error while adding protobuf logger: " << e.reason << endl,
+ lci.d_slog->error(Logr::Error, e.reason, "Exception while adding protobuf logger", "exception", Logging::Loggable("PDNSException")));
}
}
else {
- g_log << Logger::Error << "Only one protobufServer() directive can be configured, we already have " << lci.protobufExportConfig.servers.at(0).toString() << endl;
+ SLOG(g_log << Logger::Error << "Only one protobufServer() directive can be configured, we already have " << lci.protobufExportConfig.servers.at(0).toString() << endl,
+ lci.d_slog->info(Logr::Error, "Only one protobufServer() directive can be configured", "existing", Logging::Loggable(lci.protobufExportConfig.servers.at(0).toString())));
}
});
parseProtobufOptions(vars, lci.outgoingProtobufExportConfig);
}
catch (std::exception& e) {
- g_log << Logger::Error << "Error while starting outgoing protobuf logger: " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "Error while starting outgoing protobuf logger: " << e.what() << endl,
+ lci.d_slog->error(Logr::Error, "Exception while starting outgoing protobuf logger", "exception", Logging::Loggable("std::exception")));
}
catch (PDNSException& e) {
- g_log << Logger::Error << "Error while starting outgoing protobuf logger: " << e.reason << endl;
+ SLOG(g_log << Logger::Error << "Error while starting outgoing protobuf logger: " << e.reason << endl,
+ lci.d_slog->error(Logr::Error, "Exception while starting outgoing protobuf logger", "exception", Logging::Loggable("PDNSException")));
}
}
else {
- g_log << Logger::Error << "Only one outgoingProtobufServer() directive can be configured, we already have " << lci.outgoingProtobufExportConfig.servers.at(0).toString() << endl;
+ SLOG(g_log << Logger::Error << "Only one outgoingProtobufServer() directive can be configured, we already have " << lci.outgoingProtobufExportConfig.servers.at(0).toString() << endl,
+ lci.d_slog->info(Logr::Error, "Only one outgoingProtobufServer() directive can be configured", "existing", Logging::Loggable(lci.outgoingProtobufExportConfig.servers.at(0).toString())));
}
});
parseFrameStreamOptions(vars, lci.frameStreamExportConfig);
}
catch (std::exception& e) {
- g_log << Logger::Error << "Error reading config for dnstap framestream logger: " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "Error reading config for dnstap framestream logger: " << e.what() << endl,
+ lci.d_slog->error(Logr::Error, "Exception reading config for dnstap framestream logger", "exception", Logging::Loggable("std::exception")));
}
catch (PDNSException& e) {
- g_log << Logger::Error << "Error reading config for dnstap framestream logger: " << e.reason << endl;
+ SLOG(g_log << Logger::Error << "Error reading config for dnstap framestream logger: " << e.reason << endl,
+ lci.d_slog->error(Logr::Error, "Exception reading config for dnstap framestream logger", "exception", Logging::Loggable("PDNSException")));
}
}
else {
- g_log << Logger::Error << "Only one dnstapFrameStreamServer() directive can be configured, we already have " << lci.frameStreamExportConfig.servers.at(0) << endl;
+ SLOG(g_log << Logger::Error << "Only one dnstapFrameStreamServer() directive can be configured, we already have " << lci.frameStreamExportConfig.servers.at(0) << endl,
+ lci.d_slog->info(Logr::Error, "Only one dnstapFrameStreamServer() directive can be configured", "existing", Logging::Loggable(lci.frameStreamExportConfig.servers.at(0))));
}
});
#endif /* HAVE_FSTRM */
t.detach();
}
catch (const std::exception& e) {
- g_log << Logger::Error << "Problem starting RPZIXFRTracker thread: " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "Problem starting RPZIXFRTracker thread: " << e.what() << endl,
+ g_slog->withName("rpz")->error(Logr::Error, e.what(), "Exception startng RPZIXFRTracker thread", "exception", Logging::Loggable("std::exception")));
exit(1);
}
catch (const PDNSException& e) {
- g_log << Logger::Error << "Problem starting RPZIXFRTracker thread: " << e.reason << endl;
+ SLOG(g_log << Logger::Error << "Problem starting RPZIXFRTracker thread: " << e.reason << endl,
+ g_slog->withName("rpz")->error(Logr::Error, e.reason, "Exception startng RPZIXFRTracker thread", "exception", Logging::Loggable("PDNSException")));
exit(1);
}
}
#include "filterpo.hh"
#include "validate.hh"
#include "rec-zonetocache.hh"
+#include "logging.hh"
struct ProtobufExportConfig
{
ProtobufExportConfig protobufExportConfig;
ProtobufExportConfig outgoingProtobufExportConfig;
FrameStreamExportConfig frameStreamExportConfig;
+ std::shared_ptr<Logr::Logger> d_slog;
/* we need to increment this every time the configuration
is reloaded, so we know if we need to reload the protobuf
remote loggers */
_exit(1);
}
-static std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>> startProtobufServers(const ProtobufExportConfig& config)
+static std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>> startProtobufServers(const ProtobufExportConfig& config, Logr::log_t log)
{
auto result = std::make_shared<std::vector<std::unique_ptr<RemoteLogger>>>();
result->emplace_back(std::move(logger));
}
catch (const std::exception& e) {
- g_log << Logger::Error << "Error while starting protobuf logger to '" << server << ": " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "Error while starting protobuf logger to '" << server << ": " << e.what() << endl,
+ log->error(Logr::Error, e.what(), "Exception while starting protobuf logger", "exception", Logging::Loggable("std::exception"), "server", Logging::Loggable(server)));
}
catch (const PDNSException& e) {
- g_log << Logger::Error << "Error while starting protobuf logger to '" << server << ": " << e.reason << endl;
+ SLOG(g_log << Logger::Error << "Error while starting protobuf logger to '" << server << ": " << e.reason << endl,
+ log->error(Logr::Error, e.reason, "Exception while starting protobuf logger", "exception", Logging::Loggable("PDNSException"), "server", Logging::Loggable(server)));
}
}
}
t_protobufServers.reset();
- t_protobufServers = startProtobufServers(luaconfsLocal->protobufExportConfig);
+ auto log = g_slog->withName("protobuf");
+ t_protobufServers = startProtobufServers(luaconfsLocal->protobufExportConfig, log);
t_protobufServersGeneration = luaconfsLocal->generation;
}
}
t_outgoingProtobufServers.reset();
- t_outgoingProtobufServers = startProtobufServers(luaconfsLocal->outgoingProtobufExportConfig);
+ auto log = g_slog->withName("protobuf");
+ t_outgoingProtobufServers = startProtobufServers(luaconfsLocal->outgoingProtobufExportConfig, log);
t_outgoingProtobufServersGeneration = luaconfsLocal->generation;
}
#ifdef HAVE_FSTRM
-static std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> startFrameStreamServers(const FrameStreamExportConfig& config)
+static std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> startFrameStreamServers(const FrameStreamExportConfig& config, Logr::log_t log)
{
auto result = std::make_shared<std::vector<std::unique_ptr<FrameStreamLogger>>>();
result->emplace_back(fsl);
}
catch (const std::exception& e) {
- g_log << Logger::Error << "Error while starting dnstap framestream logger to '" << server << ": " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "Error while starting dnstap framestream logger to '" << server << ": " << e.what() << endl,
+ log->error(Logr::Error, e.what(), "Exception while starting dnstap framestream logger", "exception", Logging::Loggable("std::exception"), "server", Logging::Loggable(server)));
}
catch (const PDNSException& e) {
- g_log << Logger::Error << "Error while starting dnstap framestream logger to '" << server << ": " << e.reason << endl;
+ SLOG(g_log << Logger::Error << "Error while starting dnstap framestream logger to '" << server << ": " << e.reason << endl,
+ log->error(Logr::Error, e.reason, "Exception while starting dnstap framestream logger", "exception", Logging::Loggable("PDNSException"), "server", Logging::Loggable(server)));
}
}
t_frameStreamServers.reset();
}
- t_frameStreamServers = startFrameStreamServers(luaconfsLocal->frameStreamExportConfig);
+ auto log = g_slog->withName("dnstap");
+ t_frameStreamServers = startFrameStreamServers(luaconfsLocal->frameStreamExportConfig, log);
t_frameStreamServersGeneration = luaconfsLocal->generation;
}
T broadcastAccFunction(const std::function<T*()>& func)
{
if (!RecThreadInfo::self().isHandler()) {
- g_log << Logger::Error << "broadcastAccFunction has been called by a worker (" << RecThreadInfo::id() << ")" << endl;
+ SLOG(g_log << Logger::Error << "broadcastAccFunction has been called by a worker (" << RecThreadInfo::id() << ")" << endl,
+ g_slog->withName("runtime")->info(Logr::Critical, "broadcastAccFunction has been called by a worker")); // tid will be added
_exit(1);
}
SyncRes::s_max_busy_dot_probes = ::arg().asNum("max-busy-dot-probes");
if (SyncRes::s_tcp_fast_open_connect) {
- checkFastOpenSysctl(true);
- checkTFOconnect();
+ checkFastOpenSysctl(true, log);
+ checkTFOconnect(log);
}
if (SyncRes::s_serverID.empty()) {
resp = tmsg->func();
}
catch (std::exception& e) {
- if (g_logCommonErrors)
- g_log << Logger::Error << "PIPE function we executed created exception: " << e.what() << endl; // but what if they wanted an answer.. we send 0
+ if (g_logCommonErrors) {
+ SLOG(g_log << Logger::Error << "PIPE function we executed created exception: " << e.what() << endl, // but what if they wanted an answer.. we send 0
+ g_slog->withName("runtime")->error(Logr::Error, e.what(), "PIPE function we executed created exception", "exception", Logging::Loggable("std::exception")));
+ }
}
catch (PDNSException& e) {
- if (g_logCommonErrors)
- g_log << Logger::Error << "PIPE function we executed created PDNS exception: " << e.reason << endl; // but what if they wanted an answer.. we send 0
+ if (g_logCommonErrors) {
+ SLOG(g_log << Logger::Error << "PIPE function we executed created PDNS exception: " << e.reason << endl, // but what if they wanted an answer.. we send 0
+ g_slog->withName("runtime")->error(Logr::Error, e.reason, "PIPE function we executed created exception", "exception", Logging::Loggable("PDNSException")));
+ }
}
if (tmsg->wantAnswer) {
if (write(RecThreadInfo::self().pipes.writeFromThread, &resp, sizeof(resp)) != sizeof(resp)) {
if (threadInfo.isHandler()) {
if (::arg().mustDo("webserver")) {
- g_log << Logger::Warning << "Enabling web server" << endl;
+ SLOG(g_log << Logger::Warning << "Enabling web server" << endl,
+ log->info(Logr::Info, "Enabling web server"))
try {
rws = make_unique<RecursorWebServer>(t_fdm.get());
}
catch (const PDNSException& e) {
- g_log << Logger::Error << "Unable to start the internal web server: " << e.reason << endl;
+ SLOG(g_log << Logger::Error << "Unable to start the internal web server: " << e.reason << endl,
+ log->error(Logr::Critical, e.reason, "Exception while starting internal web server"));
_exit(99);
}
}
- g_log << Logger::Info << "Enabled '" << t_fdm->getName() << "' multiplexer" << endl;
+ SLOG(g_log << Logger::Info << "Enabled '" << t_fdm->getName() << "' multiplexer" << endl,
+ log->info(Logr::Info, "Enabled multiplexer", "name", Logging::Loggable(t_fdm->getName())));
}
else {
t_fdm->addReadFD(threadInfo.pipes.readQueriesToThread, handlePipeRequest);
}
}
catch (PDNSException& ae) {
- g_log << Logger::Error << "Exception: " << ae.reason << endl;
+ SLOG(g_log << Logger::Error << "Exception: " << ae.reason << endl,
+ log->error(Logr::Error, ae.reason, "Exception in RecursorThread", "exception", Logging::Loggable("PDNSException")))
}
catch (std::exception& e) {
- g_log << Logger::Error << "STL Exception: " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "STL Exception: " << e.what() << endl,
+ log->error(Logr::Error, e.what(), "Exception in RecursorThread", "exception", Logging::Loggable("std::exception")))
}
catch (...) {
- g_log << Logger::Error << "any other exception in main: " << endl;
+ SLOG(g_log << Logger::Error << "any other exception in main: " << endl,
+ log->info(Logr::Error, "Exception in RecursorThread"));
}
}
void startDoResolve(void* p);
bool expectProxyProtocol(const ComboAddress& from);
void finishTCPReply(std::unique_ptr<DNSComboWriter>& dc, bool hadError, bool updateInFlight);
-void checkFastOpenSysctl(bool active);
-void checkTFOconnect();
+void checkFastOpenSysctl(bool active, Logr::log_t);
+void checkTFOconnect(Logr::log_t);
void makeTCPServerSockets(deferredAdd_t& deferredAdds, std::set<int>& tcpSockets, Logr::log_t);
void handleNewTCPQuestion(int fd, FDMultiplexer::funcparam_t&);
TCPIOHandlerStateChange(pid->lowState, newstate, pid);
}
-void checkFastOpenSysctl(bool active)
+void checkFastOpenSysctl(bool active, Logr::log_t log)
{
#ifdef __linux__
string line;
if (readFileIfThere("/proc/sys/net/ipv4/tcp_fastopen", &line)) {
int flag = std::stoi(line);
if (active && !(flag & 1)) {
- g_log << Logger::Error << "tcp-fast-open-connect enabled but net.ipv4.tcp_fastopen does not allow it" << endl;
+ SLOG(g_log << Logger::Error << "tcp-fast-open-connect enabled but net.ipv4.tcp_fastopen does not allow it" << endl,
+ log->info(Logr::Error, "tcp-fast-open-connect enabled but net.ipv4.tcp_fastopen does not allow it"));
}
if (!active && !(flag & 2)) {
- g_log << Logger::Error << "tcp-fast-open enabled but net.ipv4.tcp_fastopen does not allow it" << endl;
+ SLOG(g_log << Logger::Error << "tcp-fast-open enabled but net.ipv4.tcp_fastopen does not allow it" << endl,
+ log->info(Logr::Error, "tcp-fast-open enabled but net.ipv4.tcp_fastopen does not allow it"));
}
}
else {
- g_log << Logger::Notice << "Cannot determine if kernel settings allow fast-open" << endl;
+ SLOG(g_log << Logger::Notice << "Cannot determine if kernel settings allow fast-open" << endl,
+ log->info(Logr::Notice, "Cannot determine if kernel settings allow fast-open"));
}
#else
- g_log << Logger::Notice << "Cannot determine if kernel settings allow fast-open" << endl;
+ SLOG(g_log << Logger::Notice << "Cannot determine if kernel settings allow fast-open" << endl,
+ log->info(Logr::Notice, "Cannot determine if kernel settings allow fast-open"));
#endif
}
-void checkTFOconnect()
+void checkTFOconnect( Logr::log_t log)
{
try {
Socket s(AF_INET, SOCK_STREAM);
s.setFastOpenConnect();
}
catch (const NetworkError& e) {
- g_log << Logger::Error << "tcp-fast-open-connect enabled but returned error: " << e.what() << endl;
+ SLOG(g_log << Logger::Error << "tcp-fast-open-connect enabled but returned error: " << e.what() << endl,
+ log->error(Logr::Error, e.what(), "tcp-fast-open-connect enabled but returned error"));
}
}
int tmp = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof tmp) < 0) {
- g_log << Logger::Error << "Setsockopt failed for TCP listening socket" << endl;
+ int err = errno;
+ SLOG(g_log << Logger::Error << "Setsockopt failed for TCP listening socket" << endl,
+ log->error(Logr::Critical, err, "Setsockopt failed for TCP listening socket"));
exit(1);
}
if (sin.sin6.sin6_family == AF_INET6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &tmp, sizeof(tmp)) < 0) {
}
if (SyncRes::s_tcp_fast_open > 0) {
- checkFastOpenSysctl(false);
+ checkFastOpenSysctl(false, log);
#ifdef TCP_FASTOPEN
if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &SyncRes::s_tcp_fast_open, sizeof SyncRes::s_tcp_fast_open) < 0) {
int err = errno;
#endif
#ifdef PDNS_CONFIG_ARGS
#include "logger.hh"
+#include "logging.hh"
#define WE_ARE_RECURSOR
#else
#include "dolog.hh"
}
catch (const std::exception& e) {
#ifdef WE_ARE_RECURSOR
- g_log<<Logger::Warning<<"Error connecting to remote logger "<<d_remote.toStringWithPort()<<": "<<e.what()<<std::endl;
+ SLOG(g_log<<Logger::Warning<<"Error connecting to remote logger "<<d_remote.toStringWithPort()<<": "<<e.what()<<std::endl,
+ g_slog->withName("protobuf")->error(Logr::Error, e.what(), "Exception while connection to remote logger", "address", Logging::Loggable(d_remote)));
#else
warnlog("Error connecting to remote logger %s: %s", d_remote.toStringWithPort(), e.what());
#endif
}
catch (const std::exception& e)
{
- cerr << "Remote Logger's maintenance thead died on: " << e.what() << endl;
+ SLOG(g_log << "Remote Logger's maintenance thead died on: " << e.what() << endl,
+ g_slog->withName("protobuf")->error(Logr::Error, e.what(), "Remote Logger's maintenance thead died"));
}
catch (...) {
- cerr << "Remote Logger's maintenance thead died on unknown exception" << endl;
+ SLOG(g_log << "Remote Logger's maintenance thead died on unknown exception" << endl,
+ g_slog->withName("protobuf")->info(Logr::Error, "Remote Logger's maintenance thead died"));
}
}
return Netmask(v6);
}
-static void RPZRecordToPolicy(const DNSRecord& dr, std::shared_ptr<DNSFilterEngine::Zone> zone, bool addOrRemove, const boost::optional<DNSFilterEngine::Policy>& defpol, bool defpolOverrideLocal, uint32_t maxTTL)
+static void RPZRecordToPolicy(const DNSRecord& dr, std::shared_ptr<DNSFilterEngine::Zone> zone, bool addOrRemove, const boost::optional<DNSFilterEngine::Policy>& defpol, bool defpolOverrideLocal, uint32_t maxTTL, Logr::log_t log)
{
static const DNSName drop("rpz-drop."), truncate("rpz-tcp-only."), noaction("rpz-passthru.");
static const DNSName rpzClientIP("rpz-client-ip"), rpzIP("rpz-ip"),
else if(!crcTarget.empty() && !crcTarget.isRoot() && crcTarget.getRawLabel(crcTarget.countLabels() - 1).compare(0, rpzPrefix.length(), rpzPrefix) == 0) {
/* this is very likely an higher format number or a configuration error,
let's just ignore it. */
- g_log<<Logger::Info<<"Discarding unsupported RPZ entry "<<crcTarget<<" for "<<dr.d_name<<endl;
+ SLOG(g_log<<Logger::Info<<"Discarding unsupported RPZ entry "<<crcTarget<<" for "<<dr.d_name<<endl,
+ log->info(Logr::Info, "Discarding unsupported RPZ entry", "target", Logging::Loggable(crcTarget), "name", Logging::Loggable(dr.d_name)));
return;
}
else {
auto logger = plogger->withValues("primary", Logging::Loggable(primary));
SLOG(g_log<<Logger::Warning<<"Loading RPZ zone '"<<zoneName<<"' from "<<primary.toStringWithPort()<<endl,
logger->info(Logr::Info, "Loading RPZ from nameserver"));
- logger = logger->v(1);
if(!tt.name.empty()) {
SLOG(g_log<<Logger::Warning<<"With TSIG key '"<<tt.name<<"' of algorithm '"<<tt.algo<<"'"<<endl,
logger->info(Logr::Info, "Using TSIG key for authentication", "tsig_key_name", Logging::Loggable(tt.name), "tsig_key_algorithm", Logging::Loggable(tt.algo)));
continue;
}
- RPZRecordToPolicy(dr, zone, true, defpol, defpolOverrideLocal, maxTTL);
+ RPZRecordToPolicy(dr, zone, true, defpol, defpolOverrideLocal, maxTTL, logger);
nrecords++;
}
axfrNow = time(nullptr);
zpt.setMaxIncludes(::arg().asNum("max-include-depth"));
DNSResourceRecord drr;
DNSName domain;
+ auto log = g_slog->withName("rpz")->withValues("file", Logging::Loggable(fname), "zone", Logging::Loggable(zone->getName()));
while(zpt.get(drr)) {
try {
if(drr.qtype.getCode() == QType::CNAME && drr.content.empty())
}
else {
dr.d_name=dr.d_name.makeRelative(domain);
- RPZRecordToPolicy(dr, zone, true, defpol, defpolOverrideLocal, maxTTL);
+ RPZRecordToPolicy(dr, zone, true, defpol, defpolOverrideLocal, maxTTL, log);
}
}
catch(const PDNSException& pe) {
return sr;
}
-static bool dumpZoneToDisk(Logr::log_t plogger, const DNSName& zoneName, const std::shared_ptr<DNSFilterEngine::Zone>& newZone, const std::string& dumpZoneFileName)
+static bool dumpZoneToDisk(Logr::log_t logger, const DNSName& zoneName, const std::shared_ptr<DNSFilterEngine::Zone>& newZone, const std::string& dumpZoneFileName)
{
- auto logger = plogger->v(1);
- logger->info("Dumping zone to disk", "destination_file", Logging::Loggable(dumpZoneFileName));
+ logger->info(Logr::Debug, "Dumping zone to disk", "destination_file", Logging::Loggable(dumpZoneFileName));
std::string temp = dumpZoneFileName + "XXXXXX";
int fd = mkstemp(&temp.at(0));
if (fd < 0) {
bool isPreloaded = sr != nullptr;
auto luaconfsLocal = g_luaconfs.getLocal();
- auto logger = g_slog->withName("rpz")->v(1);
+ auto logger = g_slog->withName("rpz");
/* we can _never_ modify this zone directly, we need to do a full copy then replace the existing zone */
std::shared_ptr<DNSFilterEngine::Zone> oldZone = luaconfsLocal->dfe.getZone(zoneIdx);
/* the configuration has been reloaded, meaning that a new thread
has been started to handle that zone and we are now obsolete.
*/
- g_log<<Logger::Info<<"A more recent configuration has been found, stopping the existing RPZ update thread for "<<zoneName<<endl;
+ SLOG(g_log<<Logger::Info<<"A more recent configuration has been found, stopping the existing RPZ update thread for "<<zoneName<<endl,
+ logger->info(Logr::Info, "A more recent configuration has been found, stopping the existing RPZ update thread"));
return;
}
for (const auto& primary : primaries) {
auto soa = getRR<SOARecordContent>(dr);
auto serial = soa ? soa->d_st.serial : 0;
- g_log<<Logger::Info<<"Getting IXFR deltas for "<<zoneName<<" from "<<primary.toStringWithPort()<<", our serial: "<<serial<<endl;
+ SLOG(g_log<<Logger::Info<<"Getting IXFR deltas for "<<zoneName<<" from "<<primary.toStringWithPort()<<", our serial: "<<serial<<endl,
+ logger->info(Logr::Info, "Getting IXFR deltas", "address", Logging::Loggable(primary)));
ComboAddress local(localAddress);
if (local == ComboAddress()) {
/* no need to try another primary */
break;
} catch(const std::runtime_error& e ){
- g_log<<Logger::Warning<<e.what()<<endl;
+ SLOG(g_log<<Logger::Warning<<e.what()<<endl,
+ logger->error(Logr::Warning, e.what(), "Exception during retrieval of delta"));
incRPZFailedTransfers(polName);
continue;
}
}
try {
- g_log<<Logger::Info<<"Processing "<<deltas.size()<<" delta"<<addS(deltas)<<" for RPZ "<<zoneName<<endl;
+ SLOG(g_log<<Logger::Info<<"Processing "<<deltas.size()<<" delta"<<addS(deltas)<<" for RPZ "<<zoneName<<endl,
+ logger->info(Logr::Info, "Processing deltas", "size", Logging::Loggable(deltas.size())));
if (luaconfsLocal->generation != configGeneration) {
- g_log<<Logger::Info<<"A more recent configuration has been found, stopping the existing RPZ update thread for "<<zoneName<<endl;
+ SLOG(g_log<<Logger::Info<<"A more recent configuration has been found, stopping the existing RPZ update thread for "<<zoneName<<endl,
+ logger->info(Logr::Info, "A more recent configuration has been found, stopping the existing RPZ update thread"))
return;
}
oldZone = luaconfsLocal->dfe.getZone(zoneIdx);
if (!oldZone || oldZone->getDomain() != zoneName) {
- g_log<<Logger::Info<<"This policy is no more, stopping the existing RPZ update thread for "<<zoneName << endl;
+ SLOG(g_log<<Logger::Info<<"This policy is no more, stopping the existing RPZ update thread for "<<zoneName << endl,
+ logger->info(Logr::Info, "This policy is no more, stopping the existing RPZ update thread"));
return;
}
/* we need to make a _full copy_ of the zone we are going to work on */
const auto& remove = delta.first;
const auto& add = delta.second;
if(remove.empty()) {
- g_log<<Logger::Warning<<"IXFR update is a whole new zone"<<endl;
+ SLOG(g_log<<Logger::Warning<<"IXFR update is a whole new zone"<<endl,
+ logger->info(Logr::Warning, "IXFR update is a whole new zone"));
newZone->clear();
fullUpdate = true;
}
}
else {
totremove++;
- g_log<<(g_logRPZChanges ? Logger::Info : Logger::Debug)<<"Had removal of "<<rr.d_name<<" from RPZ zone "<<zoneName<<endl;
- RPZRecordToPolicy(rr, newZone, false, defpol, defpolOverrideLocal, maxTTL);
+ SLOG(g_log<<(g_logRPZChanges ? Logger::Info : Logger::Debug)<<"Had removal of "<<rr.d_name<<" from RPZ zone "<<zoneName<<endl,
+ logger->info(g_logRPZChanges ? Logr::Info : Logr::Debug, "Remove from RPZ zone", "name", Logging::Loggable(rr.d_name)));
+ RPZRecordToPolicy(rr, newZone, false, defpol, defpolOverrideLocal, maxTTL, logger);
}
}
}
else {
totadd++;
- g_log<<(g_logRPZChanges ? Logger::Info : Logger::Debug)<<"Had addition of "<<rr.d_name<<" to RPZ zone "<<zoneName<<endl;
- RPZRecordToPolicy(rr, newZone, true, defpol, defpolOverrideLocal, maxTTL);
+ SLOG(g_log<<(g_logRPZChanges ? Logger::Info : Logger::Debug)<<"Had addition of "<<rr.d_name<<" to RPZ zone "<<zoneName<<endl,
+ logger->info(g_logRPZChanges ? Logr::Info : Logr::Debug, "Addition to RPZ zone", "name", Logging::Loggable(rr.d_name)));
+ RPZRecordToPolicy(rr, newZone, true, defpol, defpolOverrideLocal, maxTTL, logger);
}
}
}
if (currentSR) {
sr = currentSR;
}
- g_log<<Logger::Info<<"Had "<<totremove<<" RPZ removal"<<addS(totremove)<<", "<<totadd<<" addition"<<addS(totadd)<<" for "<<zoneName<<" New serial: "<<sr->d_st.serial<<endl;
+ SLOG(g_log<<Logger::Info<<"Had "<<totremove<<" RPZ removal"<<addS(totremove)<<", "<<totadd<<" addition"<<addS(totadd)<<" for "<<zoneName<<" New serial: "<<sr->d_st.serial<<endl,
+ logger->info(Logr::Info, "RPZ mutations", "removals", Logging::Loggable(totremove), "additions", Logging::Loggable(totadd), "newserial", Logging::Loggable(sr->d_st.serial)));
newZone->setSerial(sr->d_st.serial);
newZone->setRefresh(sr->d_st.refresh);
setRPZZoneNewState(polName, sr->d_st.serial, newZone->size(), false, fullUpdate);
since they might have been updated by another RPZ IXFR tracker thread.
*/
if (luaconfsLocal->generation != configGeneration) {
- g_log<<Logger::Info<<"A more recent configuration has been found, stopping the existing RPZ update thread for "<<zoneName<<endl;
+ SLOG(g_log<<Logger::Info<<"A more recent configuration has been found, stopping the existing RPZ update thread for "<<zoneName<<endl,
+ logger->info(Logr::Info, "A more recent configuration has been found, stopping the existing RPZ update thread"));
return;
}
g_luaconfs.modify([zoneIdx, &newZone](LuaConfigItems& lci) {
refresh = std::max(refreshFromConf ? refreshFromConf : newZone->getRefresh(), 1U);
}
catch (const std::exception& e) {
- g_log << Logger::Error << "Error while applying the update received over XFR for "<<zoneName<<", skipping the update: "<< e.what() <<endl;
+ SLOG(g_log << Logger::Error << "Error while applying the update received over XFR for "<<zoneName<<", skipping the update: "<< e.what() <<endl,
+ logger->error(Logr::Error, e.what(), "Exception while applying the update received over XFR, skipping"));
}
}
}