From owner-freebsd-bugs@FreeBSD.ORG Mon Mar 31 17:00:01 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EBCF65F9 for ; Mon, 31 Mar 2014 17:00:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D864DA05 for ; Mon, 31 Mar 2014 17:00:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s2VH00C5071462 for ; Mon, 31 Mar 2014 17:00:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s2VH00kB071461; Mon, 31 Mar 2014 17:00:00 GMT (envelope-from gnats) Date: Mon, 31 Mar 2014 17:00:00 GMT Message-Id: <201403311700.s2VH00kB071461@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Eugene Grosbein Subject: Re: bin/187526: [patch] traceroute -a breaks of "whois" socket timeout X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: Eugene Grosbein List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Mar 2014 17:00:02 -0000 The following reply was made to PR bin/187526; it has been noted by GNATS. From: Eugene Grosbein To: bug-followup@FreeBSD.ORG Cc: Subject: Re: bin/187526: [patch] traceroute -a breaks of "whois" socket timeout Date: Mon, 31 Mar 2014 23:53:22 +0700 This is a multi-part message in MIME format. --------------040008040404060404030001 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Here comes corrected version of patch that fixes traceroute6 too (and unbreaks world building). --------------040008040404060404030001 Content-Type: text/plain; charset=KOI8-R; name="traceroute.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="traceroute.diff" --- contrib/traceroute/as.h.orig 2013-06-17 11:18:23.000000000 +0700 +++ contrib/traceroute/as.h 2014-03-13 17:13:48.000000000 +0700 @@ -31,5 +31,5 @@ */ void *as_setup(const char *); -unsigned int as_lookup(void *, char *, sa_family_t); +unsigned int as_lookup(void *, char *, sa_family_t, int *); void as_shutdown(void *); --- contrib/traceroute/as.c.orig 2013-06-17 11:18:23.000000000 +0700 +++ contrib/traceroute/as.c 2014-03-13 17:37:51.000000000 +0700 @@ -119,7 +119,7 @@ as_setup(const char *server) } unsigned int -as_lookup(void *_asn, char *addr, sa_family_t family) +as_lookup(void *_asn, char *addr, sa_family_t family, int *status) { struct aslookup *asn = _asn; char buf[1024]; @@ -129,8 +129,17 @@ as_lookup(void *_asn, char *addr, sa_fam as = 0; rc = dlen = 0; plen = (family == AF_INET6) ? 128 : 32; - (void)fprintf(asn->as_f, "!r%s/%d,l\n", addr, plen); - (void)fflush(asn->as_f); + *status = fprintf(asn->as_f, "!r%s/%d,l\n", addr, plen); + if (*status < 0) { + *status = errno; + return 0; + } + *status = fflush(asn->as_f); + if (*status == EOF) { + *status = errno; + return 0; + } + *status = 0; #ifdef AS_DEBUG_FILE if (asn->as_debug) { @@ -139,7 +148,14 @@ as_lookup(void *_asn, char *addr, sa_fam } #endif /* AS_DEBUG_FILE */ - while (fgets(buf, sizeof(buf), asn->as_f) != NULL) { + while (1) { + if (fgets(buf, sizeof(buf), asn->as_f) == NULL) { + if(feof(asn->as_f) || ferror(asn->as_f)) { + *status = EIO; + return 0; + } + break; + } buf[sizeof(buf) - 1] = '\0'; #ifdef AS_DEBUG_FILE --- contrib/traceroute/traceroute.c.orig 2013-06-17 11:18:23.000000000 +0700 +++ contrib/traceroute/traceroute.c 2014-03-13 17:27:14.000000000 +0700 @@ -931,6 +931,8 @@ as_path = 0; } } + if (as_path) + signal(SIGPIPE, SIG_IGN); #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) if (setpolicy(sndsock, "in bypass") < 0) @@ -1471,6 +1473,7 @@ { register struct ip *ip; register int hlen; + int as, status; char addr[INET_ADDRSTRLEN]; ip = (struct ip *) buf; @@ -1479,8 +1482,24 @@ strlcpy(addr, inet_ntoa(from->sin_addr), sizeof(addr)); - if (as_path) - Printf(" [AS%u]", as_lookup(asn, addr, AF_INET)); + while(as_path) { + as = as_lookup(asn, addr, AF_INET, &status); + if (status) { + as_shutdown(asn); + asn = as_setup(as_server); + if (asn == NULL) { + Fprintf(stderr, "%s: as_setup failed, AS# lookups" + " disabled\n", prog); + (void)fflush(stderr); + as_path = 0; + break; + } + else + continue; + } + Printf(" [AS%u]", as); + break; + } if (nflag) Printf(" %s", addr); --- usr.sbin/traceroute6/traceroute6.c.orig 2013-10-21 21:03:06.000000000 +0700 +++ usr.sbin/traceroute6/traceroute6.c 2014-03-24 00:25:21.000000000 +0700 @@ -885,6 +885,8 @@ main(argc, argv) as_path = 0; } } + if (as_path) + signal(SIGPIPE, SIG_IGN); /* * Message to users @@ -1376,13 +1378,30 @@ print(mhdr, cc) int cc; { struct sockaddr_in6 *from = (struct sockaddr_in6 *)mhdr->msg_name; + int as, status; char hbuf[NI_MAXHOST]; if (getnameinfo((struct sockaddr *)from, from->sin6_len, hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0) strlcpy(hbuf, "invalid", sizeof(hbuf)); - if (as_path) - printf(" [AS%u]", as_lookup(asn, hbuf, AF_INET6)); + while(as_path) { + as = as_lookup(asn, hbuf, AF_INET6, &status); + if (status) { + as_shutdown(asn); + asn = as_setup(as_server); + if (asn == NULL) { + fprintf(stderr, "traceroute6: as_setup failed, AS# lookups" + " disabled\n"); + (void)fflush(stderr); + as_path = 0; + break; + } + else + continue; + } + printf(" [AS%u]", as); + break; + } if (nflag) printf(" %s", hbuf); else if (lflag) --------------040008040404060404030001--