From: Pieter Lexis Date: Wed, 10 Jan 2018 17:02:00 +0000 (+0100) Subject: ixfrdist: add listen sockets X-Git-Tag: dnsdist-1.3.0~111^2~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aff1f1fd7d15c94f00f678318be34d6531ba995d;p=pdns ixfrdist: add listen sockets --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 77051ad47..3022fae78 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -601,15 +601,17 @@ ixfrdist_SOURCES = \ dnssecinfra.cc \ dnswriter.cc dnswriter.hh \ gss_context.cc gss_context.hh \ + ixfr.cc ixfr.hh \ + ixfrdist.cc \ + ixfrutils.cc ixfrutils.hh \ logger.cc \ misc.cc misc.hh \ + mplexer.hh \ nsecrecords.cc \ qtype.cc \ rcpgenerator.cc rcpgenerator.hh \ resolver.cc \ - ixfrutils.cc ixfrutils.hh \ - ixfr.cc ixfr.hh \ - ixfrdist.cc \ + selectmplexer.cc \ sillyrecords.cc \ sstuff.hh \ statbag.cc \ diff --git a/pdns/ixfrdist.cc b/pdns/ixfrdist.cc index 2de117719..30e9a12e4 100644 --- a/pdns/ixfrdist.cc +++ b/pdns/ixfrdist.cc @@ -28,6 +28,8 @@ #include "ixfrutils.hh" #include "resolver.hh" #include "dns_random.hh" +#include "sstuff.hh" +#include "mplexer.hh" /* BEGIN Needed because of deeper dependencies */ #include "arguments.hh" @@ -41,6 +43,13 @@ ArgvMap &arg() } /* END Needed because of deeper dependencies */ + +// For all the listen-sockets +SelectFDMultiplexer g_fdm; + +// The domains we support +set g_domains; + using namespace boost::multi_index; namespace po = boost::program_options; @@ -48,18 +57,19 @@ po::variables_map g_vm; string g_workdir; ComboAddress g_master; bool g_verbose = false; +bool g_debug = false; void usage(po::options_description &desc) { cerr << "Usage: ixfrdist [OPTION]... DOMAIN [DOMAIN]..."< &domains) { +void updateThread() { std::map serials; std::map lastCheck; // Initialize the serials we have - for (const auto &domain : domains) { + for (const auto &domain : g_domains) { lastCheck[domain] = 0; string dir = g_workdir + "/" + domain.toString(); try { @@ -69,7 +79,7 @@ void updateThread(const vector &domains) { cerr<<"[INFO] "< &domains) { while (true) { time_t now = time(nullptr); - for (const auto &domain : domains) { + for (const auto &domain : g_domains) { string dir = g_workdir + "/" + domain.toString(); if (now - lastCheck[domain] < 30) { // YOLO 30 seconds continue; @@ -143,12 +153,64 @@ void updateThread(const vector &domains) { } /* while (true) */ } /* updateThread */ +void handleUDPRequest(int fd, boost::any&) { + // TODO make the buffer-size configurable + char buf[4096]; + struct sockaddr saddr; + socklen_t fromlen; + int res = recvfrom(fd, buf, sizeof(buf), 0, &saddr, &fromlen); + ComboAddress from(&saddr, fromlen); + + if (res == 0) { + cerr<<"[Warning] Got an empty message from "< info_msg; + + if (g_debug) { + cerr<<"[Debug] Had "<>(), "IP Address(es) to listen on") ("server-address", po::value()->default_value("127.0.0.1:5300"), "server address") ("work-dir", po::value()->default_value("."), "Directory for storing AXFR and IXFR data") @@ -165,25 +227,29 @@ int main(int argc, char** argv) { po::store(po::command_line_parser(argc, argv).options(alloptions).positional(p).run(), g_vm); po::notify(g_vm); - if (g_vm.count("help")) { + if (g_vm.count("help") > 0) { usage(desc); return EXIT_SUCCESS; } - if (g_vm.count("version")) { + if (g_vm.count("version") > 0) { cout<<"ixfrdist "< 0 || g_vm.count("debug") > 0) { g_verbose = true; } + if (g_vm.count("debug") > 0) { + g_debug = true; + } + bool had_error = false; vector listen_addresses = {ComboAddress("127.0.0.1:53")}; - if (g_vm.count("listen-address")) { + if (g_vm.count("listen-address") > 0) { listen_addresses.clear(); for (const auto &addr : g_vm["listen-address"].as< vector< string> >()) { try { @@ -207,17 +273,60 @@ int main(int argc, char** argv) { had_error = true; } - vector domains; - for (const auto &domain : g_vm["domains"].as>()) { try { - domains.push_back(DNSName(domain)); + g_domains.insert(DNSName(domain)); } catch (PDNSException &e) { cerr<<"[Error] '"<(); if (had_error) { @@ -228,8 +337,19 @@ int main(int argc, char** argv) { // It all starts here // Init the things we need reportAllTypes(); + + // TODO read from urandom (perhaps getrandom(2)? dns_random_init("0123456789abcdef"); // Updater thread (TODO: actually thread it :)) - updateThread(domains); + // TODO use mplexer? + // updateThread(); + + // start loop + cout<<"IXFR distributor starting up!"<