From 86df5510d49c491ceedb1efe2ab83d3f83dc32f4 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 6 Feb 2023 11:58:48 -0800 Subject: [PATCH] ircd::net::dns: Optimize query w/ internal lookup priority when enabled by conf. --- ircd/net_dns_netdb.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ircd/net_dns_netdb.cc b/ircd/net_dns_netdb.cc index 4981b9f82..1aaa348e1 100644 --- a/ircd/net_dns_netdb.cc +++ b/ircd/net_dns_netdb.cc @@ -17,6 +17,7 @@ namespace ircd::net::dns static bool netdb_ready; extern conf::item netdb_enable; + extern conf::item netdb_internal; extern const std::map, uint16_t> service_ports; extern const std::map, string_view> service_names; } @@ -55,6 +56,14 @@ ircd::net::dns::netdb_enable { "default", true }, }; +[[gnu::visibility("internal")]] +decltype(ircd::net::dns::netdb_internal) +ircd::net::dns::netdb_internal +{ + { "name", "ircd.net.dns.netdb.internal" }, + { "default", true }, +}; + void ircd::net::dns::init::service_init() { @@ -115,6 +124,10 @@ try thread_local struct ::servent res, *ent {nullptr}; thread_local char _name[32], _prot[32], buf[2048]; + if(likely(netdb_internal)) + if((res.s_port = _service_port(name, prot))) + return res.s_port; + const mods::ldso::exceptions enable {false}; const prof::syscall_usage_warning timer { @@ -210,6 +223,13 @@ try thread_local struct ::servent res, *ent {nullptr}; thread_local char _prot[32], buf[2048]; + if(likely(netdb_internal)) + { + string_view ret; + if((ret = strlcpy(out, _service_name(port, prot)))) + return ret; + } + const mods::ldso::exceptions enable {false}; const prof::syscall_usage_warning timer {