From nobody Mon Feb 23 06:42:31 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fKB9g3yP3z6SvRd for ; Mon, 23 Feb 2026 06:42:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fKB9g2bXrz3VBp for ; Mon, 23 Feb 2026 06:42:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1771828951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0Q66/EPllj8KzD4FkoIiMY85f+nAiPTnzF8Gq/txtk0=; b=wBtANu7PdHWoWH7/+Mw3LDb6eyo/+/XzKFK+JcmP6IvRcod0il1COebp5qQPBKYmj9qWzZ VIceECxjmEXYtkz0qZMlbRxL5stkMJC2itGCzOXfeRve5FhDKNNiarwo9ZNP4HfQ/cLS+k 0p+8e22vA+znCt3q9z/PiufRBuYeCxc3ppM3o6/bSCeqY7WF5hoLufABctuuO74L3n+c+B Dmyhqr0oSuQLhaVKvItSRL1iqHyLbllhMet9H+PVX5j6yH662/yVgresO4iQvEomAs+RNL QoRJZSvKOpXIyN7aoRHwsOeKX8X0vxnoJ3OuuzLDgyCms8uD+oiZyg3ECcIpAw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1771828951; a=rsa-sha256; cv=none; b=emAwk6m5vIp9nt0IKENyNr480POsQRPqY7Uca/OXzYu/fvKkw8TRvwWFh9bYWzFE+wxUJF 1zRBy4NHs89EVfSTwbMBZnBgZLoyqNoLmUu+swSfcagizyEg6hjrB4XEFQzpmcyWQHg7+p gTue2nxAa5dD667ksXEEK3drtn3m6pMj5MSfe8ee1sGteCmDPuO3JUHIZtEWkrYBriHpu8 CPpsOaULaG5sSPqaImsRb5qGGNadmietbtDndBw6e/WZo+CMRzgstwgTUrNdax6ZjR8YKr dPoQeHjn+jsk1JnpieqU8IozZynVXdhTK3PVZU0bTyhUHQWYT5KGBDorf2hizg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1771828951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0Q66/EPllj8KzD4FkoIiMY85f+nAiPTnzF8Gq/txtk0=; b=QmFHJLiNCQxWpkhracQ4TTGMOc1GJR6XQq9vrj+mr/Soi6gXULpPMEOPQtVckuOlwtgU76 wmk0/QVQdC1EaDSNjUfpaFl2FQTs0P5X9ZTLCwNjXPqaP+Iqj3aegk0VOMnYc+TxTdxv0D M8iKaWOzXxyIKIvWsOxcb+tiempBdyVoMRWdQL4MLXUE7x4Hvog8W7gQaAxdYZcWz2D0fY 2QnM2Ar2/n1VAl8X/yD/dnPDpQhYY7xvUrePjSxfYTnkAp42lQ4gHeNLrteVI4RcIr53aj l4th2S0MbVVYra2LfbS3+KiBcpvu/taacgD9hw8SeF3EIBoDIpFy18IcaNZY0A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fKB9g2BSFz3sh for ; Mon, 23 Feb 2026 06:42:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 44686 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 23 Feb 2026 06:42:31 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Eugene Grosbein Subject: git: 8df05ce54e12 - stable/14 - traceroute: MFC: graceful recover after networking errors with as_server List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: eugen X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 8df05ce54e12860111445e4ad98a791d4235be9e Auto-Submitted: auto-generated Date: Mon, 23 Feb 2026 06:42:31 +0000 Message-Id: <699bf6d7.44686.28121ae3@gitrepo.freebsd.org> The branch stable/14 has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=8df05ce54e12860111445e4ad98a791d4235be9e commit 8df05ce54e12860111445e4ad98a791d4235be9e Author: Eugene Grosbein AuthorDate: 2026-02-09 09:47:01 +0000 Commit: Eugene Grosbein CommitDate: 2026-02-23 06:42:20 +0000 traceroute: MFC: graceful recover after networking errors with as_server Currently, the traceroute[6] utility does not check for possible networking errors while talking to as_server in case of "traceroute -a". Meantime, there is a common case when trace is long and it has many non-responding hops (shown as '* * *'), so as_server aborts our connection, hence no AS numbers shown for the rest of trace. Somewhat artifical way to reproduce the problem: traceroute to 57.144.244.1 (57.144.244.1), 80 hops max, 48 byte packets 5 [AS174] be2950.ccr42.fra05.atlas.cogentco.com (154.54.72.42) 74.277 ms 9.605 ms 9.599 ms 6 [AS174] 149.11.228.19 (149.11.228.19) 9.506 ms 9.466 ms 9.420 ms 7 [AS33182] po172.asw02.fra5.tfbnw.net (129.134.108.146) 9.725 ms 9.874 ms 9.696 ms 8 [AS32934] psw04.fra5.tfbnw.net (157.240.59.85) 8.718 ms 8.691 ms 8.618 ms 9 * * * 10 [AS0] edge-star-mini-shv-01-fra5.facebook.com (57.144.244.1) 9.747 ms 9.815 ms 9.699 ms Note what due to increased timeout (-w10) we get [AS0] for 10th hop because as_server closed our connection. Same problem occurs with default -w3 when there are lots of '* * *' hops in a trace. Fix it with some additional error checking and a reconnection. This patch was in my use for many years and after traceroute(8) moved from contrib/ to usr.sbin/ it's nice to have it in the tree. (cherry picked from commit 60a6ebaf73719ef7aa15768c3906626fb106b2b3) --- usr.sbin/traceroute/as.c | 24 ++++++++++++++++++++---- usr.sbin/traceroute/as.h | 2 +- usr.sbin/traceroute/traceroute.c | 21 +++++++++++++++++++-- usr.sbin/traceroute6/traceroute6.c | 23 +++++++++++++++++++++-- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/usr.sbin/traceroute/as.c b/usr.sbin/traceroute/as.c index fd2f96100101..ab86b5205565 100644 --- a/usr.sbin/traceroute/as.c +++ b/usr.sbin/traceroute/as.c @@ -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_family_t family) 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_family_t family) } #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 diff --git a/usr.sbin/traceroute/as.h b/usr.sbin/traceroute/as.h index ce10b4b50098..d5d3f928c0da 100644 --- a/usr.sbin/traceroute/as.h +++ b/usr.sbin/traceroute/as.h @@ -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 *); diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c index 2f9358689c90..93116fe7fc3c 100644 --- a/usr.sbin/traceroute/traceroute.c +++ b/usr.sbin/traceroute/traceroute.c @@ -1653,6 +1653,7 @@ print(register u_char *buf, register int cc, register struct sockaddr_in *from) { register struct ip *ip; register int hlen; + int as, status; char addr[INET_ADDRSTRLEN]; ip = (struct ip *) buf; @@ -1661,8 +1662,24 @@ print(register u_char *buf, register int cc, register struct sockaddr_in *from) 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); diff --git a/usr.sbin/traceroute6/traceroute6.c b/usr.sbin/traceroute6/traceroute6.c index 1f5fc0a6b3a3..f2c1999b6ac5 100644 --- a/usr.sbin/traceroute6/traceroute6.c +++ b/usr.sbin/traceroute6/traceroute6.c @@ -908,6 +908,8 @@ main(int argc, char *argv[]) as_path = 0; } } + if (as_path) + signal(SIGPIPE, SIG_IGN); /* * Message to users @@ -1587,13 +1589,30 @@ void print(struct msghdr *mhdr, int cc) { struct sockaddr_in6 *from = (struct sockaddr_in6 *)mhdr->msg_name; + int as, status; char hbuf[NI_MAXHOST]; if (cap_getnameinfo(capdns, (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)