nghttpx: More log output when resolving addresses for better debugging
This commit is contained in:
parent
7adfa5dea7
commit
eb0c82d91f
|
@ -167,6 +167,10 @@ int main(int argc, char *argv[]) {
|
|||
!CU_add_test(pSuite, "util_get_uint64", shrpx::test_util_get_uint64) ||
|
||||
!CU_add_test(pSuite, "util_parse_config_str_list",
|
||||
shrpx::test_util_parse_config_str_list) ||
|
||||
!CU_add_test(pSuite, "util_make_http_hostport",
|
||||
shrpx::test_util_make_http_hostport) ||
|
||||
!CU_add_test(pSuite, "util_make_hostport",
|
||||
shrpx::test_util_make_hostport) ||
|
||||
!CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate) ||
|
||||
!CU_add_test(pSuite, "buffer_write", nghttp2::test_buffer_write) ||
|
||||
!CU_add_test(pSuite, "pool_recycle", nghttp2::test_pool_recycle) ||
|
||||
|
|
39
src/shrpx.cc
39
src/shrpx.cc
|
@ -656,7 +656,7 @@ int create_tcp_server_socket(UpstreamAddr &faddr,
|
|||
}
|
||||
|
||||
faddr.fd = fd;
|
||||
faddr.hostport = util::make_hostport(host.data(), faddr.port);
|
||||
faddr.hostport = util::make_http_hostport(host.data(), faddr.port);
|
||||
|
||||
LOG(NOTICE) << "Listening on " << faddr.hostport;
|
||||
|
||||
|
@ -2178,8 +2178,10 @@ void process_options(
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
LOG(INFO) << "Use UNIX domain socket path " << path
|
||||
<< " for backend connection";
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
LOG(INFO) << "Use UNIX domain socket path " << path
|
||||
<< " for backend connection";
|
||||
}
|
||||
|
||||
addr.addr.su.un.sun_family = AF_UNIX;
|
||||
// copy path including terminal NULL
|
||||
|
@ -2189,44 +2191,65 @@ void process_options(
|
|||
continue;
|
||||
}
|
||||
|
||||
addr.hostport =
|
||||
ImmutableString(util::make_hostport(addr.host.c_str(), addr.port));
|
||||
addr.hostport = ImmutableString(
|
||||
util::make_http_hostport(StringRef(addr.host), addr.port));
|
||||
|
||||
auto hostport = util::make_hostport(addr.host.c_str(), addr.port);
|
||||
|
||||
if (resolve_hostname(&addr.addr, addr.host.c_str(), addr.port,
|
||||
downstreamconf.family) == -1) {
|
||||
LOG(FATAL) << "Resolving backend address failed: " << hostport;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
LOG(NOTICE) << "Resolved backend address: " << hostport << " -> "
|
||||
<< util::numeric_hostport(&addr.addr.su.sa, addr.addr.len);
|
||||
}
|
||||
}
|
||||
|
||||
auto &proxy = mod_config()->downstream_http_proxy;
|
||||
if (!proxy.host.empty()) {
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
LOG(INFO) << "Resolving backend http proxy address";
|
||||
}
|
||||
auto hostport = util::make_hostport(proxy.host.c_str(), proxy.port);
|
||||
if (resolve_hostname(&proxy.addr, proxy.host.c_str(), proxy.port,
|
||||
AF_UNSPEC) == -1) {
|
||||
LOG(FATAL) << "Resolving backend HTTP proxy address failed: " << hostport;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
LOG(NOTICE) << "Backend HTTP proxy address: " << hostport << " -> "
|
||||
<< util::numeric_hostport(&proxy.addr.su.sa, proxy.addr.len);
|
||||
}
|
||||
|
||||
{
|
||||
auto &memcachedconf = tlsconf.session_cache.memcached;
|
||||
if (memcachedconf.host) {
|
||||
auto hostport =
|
||||
util::make_hostport(memcachedconf.host.get(), memcachedconf.port);
|
||||
if (resolve_hostname(&memcachedconf.addr, memcachedconf.host.get(),
|
||||
memcachedconf.port, memcachedconf.family) == -1) {
|
||||
LOG(FATAL)
|
||||
<< "Resolving memcached address for TLS session cache failed: "
|
||||
<< hostport;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
LOG(NOTICE) << "Memcached address for TLS session cache: " << hostport
|
||||
<< " -> " << util::numeric_hostport(&memcachedconf.addr.su.sa,
|
||||
memcachedconf.addr.len);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto &memcachedconf = tlsconf.ticket.memcached;
|
||||
if (memcachedconf.host) {
|
||||
auto hostport =
|
||||
util::make_hostport(memcachedconf.host.get(), memcachedconf.port);
|
||||
if (resolve_hostname(&memcachedconf.addr, memcachedconf.host.get(),
|
||||
memcachedconf.port, memcachedconf.family) == -1) {
|
||||
LOG(FATAL) << "Resolving memcached address for TLS ticket key failed: "
|
||||
<< hostport;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
LOG(NOTICE) << "Memcached address for TLS ticket key: " << hostport
|
||||
<< " -> " << util::numeric_hostport(&memcachedconf.addr.su.sa,
|
||||
memcachedconf.addr.len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
61
src/util.cc
61
src/util.cc
|
@ -57,7 +57,6 @@
|
|||
#include <nghttp2/nghttp2.h>
|
||||
|
||||
#include "timegm.h"
|
||||
#include "template.h"
|
||||
|
||||
namespace nghttp2 {
|
||||
|
||||
|
@ -1149,25 +1148,53 @@ std::string dtos(double n) {
|
|||
return utos(static_cast<int64_t>(n)) + "." + (f.size() == 1 ? "0" : "") + f;
|
||||
}
|
||||
|
||||
std::string make_hostport(const char *host, uint16_t port) {
|
||||
auto ipv6 = ipv6_numeric_addr(host);
|
||||
std::string hostport;
|
||||
|
||||
if (ipv6) {
|
||||
hostport += '[';
|
||||
}
|
||||
|
||||
hostport += host;
|
||||
|
||||
if (ipv6) {
|
||||
hostport += ']';
|
||||
}
|
||||
|
||||
std::string make_http_hostport(const StringRef &host, uint16_t port) {
|
||||
if (port != 80 && port != 443) {
|
||||
hostport += ':';
|
||||
hostport += utos(port);
|
||||
return make_hostport(host, port);
|
||||
}
|
||||
|
||||
auto ipv6 = ipv6_numeric_addr(host.c_str());
|
||||
|
||||
std::string hostport;
|
||||
hostport.resize(host.size() + (ipv6 ? 2 : 0));
|
||||
|
||||
auto p = &hostport[0];
|
||||
|
||||
if (ipv6) {
|
||||
*p++ = '[';
|
||||
}
|
||||
|
||||
p = std::copy_n(host.c_str(), host.size(), p);
|
||||
|
||||
if (ipv6) {
|
||||
*p++ = ']';
|
||||
}
|
||||
|
||||
return hostport;
|
||||
}
|
||||
|
||||
std::string make_hostport(const StringRef &host, uint16_t port) {
|
||||
auto ipv6 = ipv6_numeric_addr(host.c_str());
|
||||
auto serv = utos(port);
|
||||
|
||||
std::string hostport;
|
||||
hostport.resize(host.size() + (ipv6 ? 2 : 0) + 1 + serv.size());
|
||||
|
||||
auto p = &hostport[0];
|
||||
|
||||
if (ipv6) {
|
||||
*p++ = '[';
|
||||
}
|
||||
|
||||
p = std::copy_n(host.c_str(), host.size(), p);
|
||||
|
||||
if (ipv6) {
|
||||
*p++ = ']';
|
||||
}
|
||||
|
||||
*p++ = ':';
|
||||
std::copy_n(serv.c_str(), serv.size(), p);
|
||||
|
||||
return hostport;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,8 @@
|
|||
|
||||
#include "http-parser/http_parser.h"
|
||||
|
||||
#include "template.h"
|
||||
|
||||
namespace nghttp2 {
|
||||
|
||||
// The additional HTTP/2 protocol ALPN protocol identifier we also
|
||||
|
@ -623,7 +625,11 @@ std::string format_duration(double t);
|
|||
// Creates "host:port" string using given |host| and |port|. If
|
||||
// |host| is numeric IPv6 address (e.g., ::1), it is enclosed by "["
|
||||
// and "]". If |port| is 80 or 443, port part is omitted.
|
||||
std::string make_hostport(const char *host, uint16_t port);
|
||||
std::string make_http_hostport(const StringRef &host, uint16_t port);
|
||||
|
||||
// Just like make_http_hostport(), but doesn't treat 80 and 443
|
||||
// specially.
|
||||
std::string make_hostport(const StringRef &host, uint16_t port);
|
||||
|
||||
// Dumps |src| of length |len| in the format similar to `hexdump -C`.
|
||||
void hexdump(FILE *out, const uint8_t *src, size_t len);
|
||||
|
|
|
@ -455,4 +455,15 @@ void test_util_parse_config_str_list(void) {
|
|||
CU_ASSERT("charlie" == res[2]);
|
||||
}
|
||||
|
||||
void test_util_make_http_hostport(void) {
|
||||
CU_ASSERT("localhost" == util::make_http_hostport("localhost", 80));
|
||||
CU_ASSERT("[::1]" == util::make_http_hostport("::1", 443));
|
||||
CU_ASSERT("localhost:3000" == util::make_http_hostport("localhost", 3000));
|
||||
}
|
||||
|
||||
void test_util_make_hostport(void) {
|
||||
CU_ASSERT("localhost:80" == util::make_hostport("localhost", 80));
|
||||
CU_ASSERT("[::1]:443" == util::make_hostport("::1", 443));
|
||||
}
|
||||
|
||||
} // namespace shrpx
|
||||
|
|
|
@ -57,6 +57,8 @@ void test_util_parse_http_date(void);
|
|||
void test_util_localtime_date(void);
|
||||
void test_util_get_uint64(void);
|
||||
void test_util_parse_config_str_list(void);
|
||||
void test_util_make_http_hostport(void);
|
||||
void test_util_make_hostport(void);
|
||||
|
||||
} // namespace shrpx
|
||||
|
||||
|
|
Loading…
Reference in New Issue