mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd::net::dns: Use conf item for resolver servers.
This commit is contained in:
parent
33a8430661
commit
ccaaf22cac
2 changed files with 53 additions and 21 deletions
|
@ -23,6 +23,7 @@ struct ircd::net::dns::resolver
|
|||
using header = rfc1035::header;
|
||||
|
||||
static constexpr const size_t &MAX_COUNT{64};
|
||||
static conf::item<std::string> servers;
|
||||
static conf::item<milliseconds> timeout;
|
||||
static conf::item<milliseconds> send_rate;
|
||||
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
|
||||
size_t server_next{0}; // Round-robin state to hit servers
|
||||
void init_servers();
|
||||
|
||||
ctx::dock dock;
|
||||
std::map<uint16_t, tag> tags; // The active requests
|
||||
steady_point send_last; // Time of last send
|
||||
std::deque<uint16_t> sendq; // Queue of frames for rate-limiting
|
||||
|
||||
ip::udp::socket ns; // A pollable activity object
|
||||
ip::udp::endpoint reply_from; // Remote addr of 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 header &, const rfc1035::question &, tag &);
|
||||
void handle_reply(const header &, const const_buffer &body, tag &);
|
||||
|
|
66
ircd/net.cc
66
ircd/net.cc
|
@ -3371,6 +3371,19 @@ ircd::net::dns::cache::get(const hostport &hp,
|
|||
// 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)
|
||||
ircd::net::dns::resolver::timeout
|
||||
{
|
||||
|
@ -3416,8 +3429,8 @@ ircd::net::dns::resolver::resolver()
|
|||
{
|
||||
ns.open(ip::udp::v4());
|
||||
ns.non_blocking(true);
|
||||
set_servers();
|
||||
set_handle();
|
||||
init_servers();
|
||||
}
|
||||
|
||||
ircd::net::dns::resolver::~resolver()
|
||||
|
@ -3987,31 +4000,48 @@ const
|
|||
}
|
||||
}
|
||||
|
||||
//TODO: x-platform
|
||||
void
|
||||
ircd::net::dns::resolver::init_servers()
|
||||
ircd::net::dns::resolver::set_servers()
|
||||
{
|
||||
const auto resolve_conf
|
||||
{
|
||||
fs::read("/etc/resolv.conf")
|
||||
};
|
||||
const std::string &list(resolver::servers);
|
||||
set_servers(list);
|
||||
}
|
||||
|
||||
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, ' '));
|
||||
if(kv.first == "nameserver")
|
||||
const auto &port
|
||||
{
|
||||
const ipport server{kv.second, 53};
|
||||
this->server.emplace_back(make_endpoint_udp(server));
|
||||
log::debug
|
||||
{
|
||||
log, "Found nameserver %s from resolv.conf",
|
||||
string(server)
|
||||
};
|
||||
}
|
||||
net::port(hp) != canon_port? net::port(hp) : uint16_t(53)
|
||||
};
|
||||
|
||||
const ipport ipp
|
||||
{
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue