From 4a2f357f0b40fe85473a18187d0cc35cb30a5c0b Mon Sep 17 00:00:00 2001 From: "Greg A. Woods" Date: Tue, 28 Jan 2025 11:22:41 -0800 Subject: [PATCH] improve & add some network-related debugging messages --- conserver/access.c | 14 ++++++++++++-- conserver/consent.c | 24 ++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/conserver/access.c b/conserver/access.c index 0679a2c..c0bbe7a 100644 --- a/conserver/access.c +++ b/conserver/access.c @@ -146,6 +146,12 @@ AccType(INADDR_STYPE *addr, char **peername) so = sizeof(*addr); #if USE_IPV6 + /* + * XXX where is the TRUST_REVERSE_DNS support for IPv6??? + * + * XXX IPv4 should use getnameinfo() et al as well + * (if available, they are in IEEE Std 1003.1g-2000) + */ error = getnameinfo((struct sockaddr *)addr, so, ipaddr, sizeof(ipaddr), NULL, 0, NI_NUMERICHOST); @@ -153,7 +159,11 @@ AccType(INADDR_STYPE *addr, char **peername) Error("AccType(): getnameinfo failed: %s", gai_strerror(error)); goto common_ret; } - CONDDEBUG((1, "AccType(): ip=%s", ipaddr)); + CONDDEBUG((1, "AccType(): ip=%s (%s)", ipaddr, + addr->ss_family == AF_UNSPEC ? "AF_UNSPEC" : + addr->ss_family == AF_LOCAL ? "AF_LOCAL" : + addr->ss_family == AF_INET ? "AF_INET" : + addr->ss_family == AF_INET6 ? "AF_INET6" : "IF_???")); error = getnameinfo((struct sockaddr *)addr, so, host, sizeof(host), NULL, @@ -189,7 +199,7 @@ AccType(INADDR_STYPE *addr, char **peername) common_ret: if (config->loghostnames == FLAGTRUE && !error) *peername = StrDup(host); -#else +#else /* !USE_IPV6 */ # if TRUST_REVERSE_DNS /* if we trust reverse dns, we get the names associated with * the address we're checking and then check each of those diff --git a/conserver/consent.c b/conserver/consent.c index 2b7eaa7..4114038 100644 --- a/conserver/consent.c +++ b/conserver/consent.c @@ -915,6 +915,9 @@ ConsInit(CONSENT *pCE) case HOST: { #if USE_IPV6 + /* XXX IPv4 should use getaddrinfo() and getnameinfo() as well, + * (if available, they are in IEEE Std 1003.1g-2000) + */ int error; char host[NI_MAXHOST]; char serv[NI_MAXSERV]; @@ -929,7 +932,7 @@ ConsInit(CONSENT *pCE) Sleep(100000); /* Not all terminal servers can keep up */ #if USE_IPV6 -# if HAVE_MEMSET +# if HAVE_MEMSET /* XXX memset() is C89!!! */ memset(&hints, 0, sizeof(hints)); # else bzero(&hints, sizeof(hints)); @@ -966,8 +969,12 @@ ConsInit(CONSENT *pCE) # if HAVE_SETSOCKOPT if (setsockopt (cofile, SOL_SOCKET, SO_KEEPALIVE, - (char *)&one, sizeof(one)) < 0) + (char *)&one, sizeof(one)) < 0) { + Error + ("[%s] %s:%s setsockopt(%u,SO_KEEPALIVE): %s", + pCE->server, host, serv, cofile, strerror(errno)); goto fail; + } # endif if (!SetFlags(cofile, O_NONBLOCK, 0)) goto fail; @@ -975,20 +982,25 @@ ConsInit(CONSENT *pCE) ret = connect(cofile, rp->ai_addr, rp->ai_addrlen); if (ret == 0 || errno == EINPROGRESS) goto success; - + Error("[%s] %s:%s connect(%u): %s", + pCE->server, host, serv, cofile, strerror(errno)); fail: close(cofile); + } else { + Error + ("[%s] %s:%s socket(AF_INET,SOCK_STREAM): %s", + pCE->server, host, serv, strerror(errno)); } rp = rp->ai_next; } - Error("[%s]: Unable to connect to %s:%s", pCE->server, - host, serv); + Error("[%s] Unable to connect to %s:%s, forcing down", pCE->server, + pCE->host, serv); ConsDown(pCE, FLAGTRUE, FLAGTRUE); return; success: freeaddrinfo(ai); -#else +#else /* !USE_IPV6 */ # if HAVE_MEMSET memset((void *)&port, 0, sizeof(port)); # else