From 13fcd8b3a5f1b168e6b1004cee27cca63e4f7d7e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 8 Oct 2020 19:38:33 -0700 Subject: [PATCH] ircd::net: Fix canon string inconsistencies; perform service lookups. --- ircd/net.cc | 33 ++++++++++++++++++++------------- ircd/server.cc | 2 +- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/ircd/net.cc b/ircd/net.cc index 9a5269fb6..bf0fd0b30 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -2910,28 +2910,35 @@ ircd::string_view ircd::net::canonize(const mutable_buffer &buf, const hostport &hostport) { - thread_local char tlbuf[2][rfc3986::DOMAIN_BUFSIZE * 2]; - + thread_local char svc[32], tlbuf[2][rfc3986::DOMAIN_BUFSIZE * 2]; assert(service(hostport) || port(hostport)); - if(unlikely(!service(hostport) && !port(hostport))) + + const string_view &service_name + { + !service(hostport)? + net::dns::service_name(std::nothrow, svc, port(hostport), "tcp"): + service(hostport) + }; + + if(likely(service_name)) + return fmt::sprintf + { + buf, "%s:%s", + tolower(tlbuf[0], host(hostport)), + tolower(tlbuf[1], service_name), + }; + + if(unlikely(!port(hostport))) throw error { "Missing service suffix in hostname:service string.", }; - if(port(hostport)) - return fmt::sprintf - { - buf, "%s:%u", - tolower(tlbuf[0], host(hostport)), - port(hostport), - }; - return fmt::sprintf { - buf, "%s:%s", + buf, "%s:%u", tolower(tlbuf[0], host(hostport)), - tolower(tlbuf[1], service(hostport)), + port(hostport), }; } diff --git a/ircd/server.cc b/ircd/server.cc index 8f5ab2983..db1e71605 100644 --- a/ircd/server.cc +++ b/ircd/server.cc @@ -677,7 +677,7 @@ ircd::server::peer::peer(const net::hostport &hostport, open_opts } { - const net::hostport &canon + const net::hostport canon { this->hostcanon };