0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd::net::dns: Use conf item for resolver servers.

This commit is contained in:
Jason Volk 2018-09-29 19:56:22 -07:00
parent 33a8430661
commit ccaaf22cac
2 changed files with 53 additions and 21 deletions

View file

@ -23,6 +23,7 @@ struct ircd::net::dns::resolver
using header = rfc1035::header; using header = rfc1035::header;
static constexpr const size_t &MAX_COUNT{64}; static constexpr const size_t &MAX_COUNT{64};
static conf::item<std::string> servers;
static conf::item<milliseconds> timeout; static conf::item<milliseconds> timeout;
static conf::item<milliseconds> send_rate; static conf::item<milliseconds> send_rate;
static conf::item<size_t> send_burst; static conf::item<size_t> send_burst;
@ -30,17 +31,18 @@ struct ircd::net::dns::resolver
std::vector<ip::udp::endpoint> server; // The list of active servers std::vector<ip::udp::endpoint> server; // The list of active servers
size_t server_next{0}; // Round-robin state to hit servers size_t server_next{0}; // Round-robin state to hit servers
void init_servers();
ctx::dock dock; ctx::dock dock;
std::map<uint16_t, tag> tags; // The active requests std::map<uint16_t, tag> tags; // The active requests
steady_point send_last; // Time of last send steady_point send_last; // Time of last send
std::deque<uint16_t> sendq; // Queue of frames for rate-limiting std::deque<uint16_t> sendq; // Queue of frames for rate-limiting
ip::udp::socket ns; // A pollable activity object ip::udp::socket ns; // A pollable activity object
ip::udp::endpoint reply_from; // Remote addr of recv ip::udp::endpoint reply_from; // Remote addr of recv
unique_buffer<mutable_buffer> reply; // Buffer for recv unique_buffer<mutable_buffer> reply; // Buffer for recv
void add_server(const ipport &);
void set_servers(const string_view &list);
void set_servers();
bool handle_error(const error_code &ec) const; bool handle_error(const error_code &ec) const;
bool handle_error(const header &, const rfc1035::question &, tag &); bool handle_error(const header &, const rfc1035::question &, tag &);
void handle_reply(const header &, const const_buffer &body, tag &); void handle_reply(const header &, const const_buffer &body, tag &);

View file

@ -3371,6 +3371,19 @@ ircd::net::dns::cache::get(const hostport &hp,
// net/resolver.h // net/resolver.h
// //
decltype(ircd::net::dns::resolver::servers)
ircd::net::dns::resolver::servers
{
{
{ "name", "ircd.net.dns.resolver.servers" },
{ "default", "4.2.2.1;4.2.2.2;4.2.2.3;4.2.2.4;4.2.2.5;4.2.2.6" },
}, []
{
if(ircd::net::dns::resolver)
ircd::net::dns::resolver->set_servers();
}
};
decltype(ircd::net::dns::resolver::timeout) decltype(ircd::net::dns::resolver::timeout)
ircd::net::dns::resolver::timeout ircd::net::dns::resolver::timeout
{ {
@ -3416,8 +3429,8 @@ ircd::net::dns::resolver::resolver()
{ {
ns.open(ip::udp::v4()); ns.open(ip::udp::v4());
ns.non_blocking(true); ns.non_blocking(true);
set_servers();
set_handle(); set_handle();
init_servers();
} }
ircd::net::dns::resolver::~resolver() ircd::net::dns::resolver::~resolver()
@ -3987,31 +4000,48 @@ const
} }
} }
//TODO: x-platform
void void
ircd::net::dns::resolver::init_servers() ircd::net::dns::resolver::set_servers()
{ {
const auto resolve_conf const std::string &list(resolver::servers);
{ set_servers(list);
fs::read("/etc/resolv.conf") }
};
tokens(resolve_conf, '\n', [this](const auto &line) void
ircd::net::dns::resolver::set_servers(const string_view &list)
{
server.clear();
server_next = 0;
tokens(list, ';', [this]
(const hostport &hp)
{ {
const auto kv(split(line, ' ')); const auto &port
if(kv.first == "nameserver")
{ {
const ipport server{kv.second, 53}; net::port(hp) != canon_port? net::port(hp) : uint16_t(53)
this->server.emplace_back(make_endpoint_udp(server)); };
log::debug
{ const ipport ipp
log, "Found nameserver %s from resolv.conf", {
string(server) host(hp), port
}; };
}
add_server(ipp);
}); });
} }
void
ircd::net::dns::resolver::add_server(const ipport &ipp)
{
server.emplace_back(make_endpoint_udp(ipp));
log::debug
{
log, "Adding [%s] as DNS server #%zu",
string(ipp),
server.size()
};
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// //
// net/ipport.h // net/ipport.h