From 4a2f357f0b40fe85473a18187d0cc35cb30a5c0b Mon Sep 17 00:00:00 2001 From: "Greg A. Woods" Date: Tue, 28 Jan 2025 11:22:41 -0800 Subject: [PATCH 1/4] 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 From 525f3a6fb48e417cba05996968875c76dd92a3ce Mon Sep 17 00:00:00 2001 From: "Greg A. Woods" Date: Tue, 28 Jan 2025 11:26:54 -0800 Subject: [PATCH 2/4] reduce level of string alloc management debug messages String alloc management debug messages are way too noisy and get in the way of more important debugging tasks. --- conserver/cutil.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/conserver/cutil.c b/conserver/cutil.c index 49abc16..8120108 100644 --- a/conserver/cutil.c +++ b/conserver/cutil.c @@ -262,7 +262,7 @@ DestroyString(STRING *msg) { if (msg->prev == (STRING *)0 && msg->next == (STRING *)0 && allStrings != msg) { - CONDDEBUG((1, "DestroyString(): 0x%lx non-pooled string destroyed", + CONDDEBUG((3, "DestroyString(): 0x%lx non-pooled string destroyed", (void *)msg, stringCount)); } else { if (msg->prev != (STRING *)0) @@ -273,7 +273,7 @@ DestroyString(STRING *msg) allStrings = msg->next; } stringCount--; - CONDDEBUG((1, + CONDDEBUG((3, "DestroyString(): 0x%lx string destroyed (count==%d)", (void *)msg, stringCount)); } @@ -296,7 +296,7 @@ AllocString(void) allStrings = s; InitString(s); stringCount++; - CONDDEBUG((1, "AllocString(): 0x%lx created string #%d", (void *)s, + CONDDEBUG((3, "AllocString(): 0x%lx created string #%d", (void *)s, stringCount)); return s; } From 9cbb5cd6026542fba961bde455fae0729ff004b4 Mon Sep 17 00:00:00 2001 From: Bryan Stansell Date: Tue, 28 Jan 2025 12:17:01 -0800 Subject: [PATCH 3/4] fix bug with parser and "#" lines, fix debug output in ParseFile() --- conserver/cutil.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/conserver/cutil.c b/conserver/cutil.c index 8120108..78d93fe 100644 --- a/conserver/cutil.c +++ b/conserver/cutil.c @@ -2415,7 +2415,7 @@ GetWord(FILE *fp, int *line, short spaceok, STRING *word) while ((c = fgetc(fp)) != EOF) { if (c == '\n') { (*line)++; - if (checkInc == -2) + if (checkInc == -2 || checkInc == 0) checkInc = -1; } if (comment) { @@ -2592,11 +2592,17 @@ ParseFile(char *filename, FILE *fp, int level) strerror(errno)); } else { char *fname; + char *sfile; + int *sline; /* word gets destroyed, so save the name */ fname = StrDup(word->string); + sfile = file; + sline = line; ParseFile(fname, lfp, level + 1); fclose(lfp); free(fname); + file = sfile; + line = sline; } } else { switch (state) { From ba8c638db168519f6816686786308ff50d71ff38 Mon Sep 17 00:00:00 2001 From: Bryan Stansell Date: Tue, 28 Jan 2025 12:23:21 -0800 Subject: [PATCH 4/4] typo --- conserver/cutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conserver/cutil.c b/conserver/cutil.c index 78d93fe..27997f6 100644 --- a/conserver/cutil.c +++ b/conserver/cutil.c @@ -2593,7 +2593,7 @@ ParseFile(char *filename, FILE *fp, int level) } else { char *fname; char *sfile; - int *sline; + int sline; /* word gets destroyed, so save the name */ fname = StrDup(word->string); sfile = file;