From nobody Mon Feb 03 18:10:07 2025 X-Original-To: dev-commits-src-main@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 4Ymvfm47DDz5mHSp; Mon, 03 Feb 2025 18:10:08 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Ymvfm0KfWz3TgW; Mon, 03 Feb 2025 18:10:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738606208; 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=WS8QIeWSwrxoQiKNVG0y+foo/vHv42QJqg2rBrbB5Yg=; b=VdGncOqNKtox1cY+wio4MsjxpNaRJUuNwkcMOjWxjAGROPEWEyCKrYJPv2NvzU0mX9wqH0 4Flg5ysZStf+o0f+2nfL3svyCGggxsvLdS5fTAI+6rwM/J4IkpUmjJCo/J/qCMTui3X1nq etGhB77X8/SpfROT2xFu41+IHIhmqAI9aV7BZteezEujwwxck0Mjk5tID+KKXBm09sT+vc 6jNMTMHhr7xrYHWI4pAZ7+9/h5QLDVp+KU9CW/WQ/t8JImXyBYHUxNtya8wdnwdZmwNRJF ppJTYK36WfHwhNlDOR+q6GZj4m5+x9Fl0ta2QTaIRCQIqQSGCC+p2jEIcupKrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738606208; 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=WS8QIeWSwrxoQiKNVG0y+foo/vHv42QJqg2rBrbB5Yg=; b=BVADH8El0N1/WMmye0ESl437jAclZov2AaMb8GbEwzLXvhczq5ZtDAc7d8qoEeVuwraWSA E289NScUOdnUwx16YKDCl0ZaLtzadF5zVki94hIYWCEdA9dSDLSz8F2M5MMs4lB4gjIQo8 izGrU7otLtI2wVc0M3ZXGztRFBgWaJh23qYp3pXqfjncuIqRcN92ez+6VCjPVq69jHQpRa wHzdxUKqUiWRS1euCgh27g6XqR7uHXgjea6d3oByYwFRMQtzoM/5cvk4B1Sz1vv6kLnk1O OKUOvtU5V8wGSYq4iqJlYH9yXALlLj6cgK9zIJHL28tk47RcQ7klQIm7TBbo/A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1738606208; a=rsa-sha256; cv=none; b=s7aAZgqu0O3x2AGSY5AGILsSr7E8r8GxEtx48cUZI8eR12GmiMgs9E/tHQabKk4V9mMh54 kQOsqT+Zom8bg4/8taUEJ4f/rb79S3MB/6jCFTrJFm9jwf+ofNFEB7VbDweaH62jsMmXSY erbR8n+GEwY5px9vmEsA7UPef3um+QPoput5wqfFx+XkN1huTFgtcSelqdOmPdVZrMx1xf ximDQ7nGr5YVPyVaf3bb9xfjOnwaAIS/PaRo4vroKRBP+FEjkAQeY7qsg9Z8DWDeMS2eN/ HW57ILP+UTFDwF5m16hU821tAGwaMNiGoO5YhSDUuuIOIzlIBvbxBVEheTPjxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Ymvfl72TjzncY; Mon, 03 Feb 2025 18:10:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 513IA7Nn089425; Mon, 3 Feb 2025 18:10:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 513IA7vR089421; Mon, 3 Feb 2025 18:10:07 GMT (envelope-from git) Date: Mon, 3 Feb 2025 18:10:07 GMT Message-Id: <202502031810.513IA7vR089421@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: c2aa91745e87 - main - netstat: restore printing the "default" keyword, provide -nn option List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c2aa91745e870d9d925cb054cc114f65180ed8c6 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=c2aa91745e870d9d925cb054cc114f65180ed8c6 commit c2aa91745e870d9d925cb054cc114f65180ed8c6 Author: Gleb Smirnoff AuthorDate: 2025-02-03 18:09:58 +0000 Commit: Gleb Smirnoff CommitDate: 2025-02-03 18:09:58 +0000 netstat: restore printing the "default" keyword, provide -nn option Avoid POLA breakage and preserve output standard that really predates the FreeBSD project itself. There are scripts in the wild that rely on the behavior. Provide option to specify -nn twice to have a completely numeric output of the routing tables. Fixes: 9206c79961986c2114a9a2cfccf009ac010ad259 This reverts commit e090646d6f5a4a6848ecd4bcb1f2db498ea3b3e2. Reviewed by: zlei, gallatin, melifaro, allanjude, markj, emaste Differential Revision: https://reviews.freebsd.org/D48729 --- tests/sys/netinet/fibs_test.sh | 10 +++++----- tests/sys/netinet6/ndp.sh | 6 +++--- usr.bin/netstat/main.c | 7 ++++--- usr.bin/netstat/netstat.1 | 8 +++++++- usr.bin/netstat/netstat.h | 4 ++-- usr.bin/netstat/route.c | 4 ++-- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/tests/sys/netinet/fibs_test.sh b/tests/sys/netinet/fibs_test.sh index a57d999496fc..b58a45b26f3e 100644 --- a/tests/sys/netinet/fibs_test.sh +++ b/tests/sys/netinet/fibs_test.sh @@ -240,9 +240,9 @@ default_route_with_multiple_fibs_on_same_subnet_body() # Verify that the default route exists for both fibs, with their # respective interfaces. - atf_check -o match:"^0\.0\.0\.0.*${TAP0}$" \ + atf_check -o match:"^default.*${TAP0}$" \ setfib ${FIB0} netstat -rn -f inet - atf_check -o match:"^0\.0\.0\.0.*${TAP1}$" \ + atf_check -o match:"^default.*${TAP1}$" \ setfib ${FIB1} netstat -rn -f inet } @@ -286,9 +286,9 @@ default_route_with_multiple_fibs_on_same_subnet_inet6_body() # Verify that the default route exists for both fibs, with their # respective interfaces. - atf_check -o match:"^::/0.*${TAP0}$" \ + atf_check -o match:"^default.*${TAP0}$" \ setfib ${FIB0} netstat -rn -f inet6 - atf_check -o match:"^::/0.*${TAP1}$" \ + atf_check -o match:"^default.*${TAP1}$" \ setfib ${FIB1} netstat -rn -f inet6 } @@ -479,7 +479,7 @@ slaac_on_nondefault_fib6_body() atf_check -o match:"${SUBNET}:/${MASK}.*\.*$EPAIRB" \ netstat -rnf inet6 -F $FIB1 # Check default route - atf_check -o match:"^::/0.*\.*$EPAIRB" \ + atf_check -o match:"default.*\.*$EPAIRB" \ netstat -rnf inet6 -F $FIB1 # Check that none of the above routes appeared on other routes diff --git a/tests/sys/netinet6/ndp.sh b/tests/sys/netinet6/ndp.sh index 24c0853d7361..038a640f331e 100755 --- a/tests/sys/netinet6/ndp.sh +++ b/tests/sys/netinet6/ndp.sh @@ -163,12 +163,12 @@ ndp_slaac_default_route_body() { while [ -z "$(jexec ${jname} ndp -r)" ]; do sleep 0.1 done - atf_check -o match:"^::/0[[:space:]]+fe80:" \ + atf_check -o match:"^default[[:space:]]+fe80:" \ jexec ${jname} netstat -rn -6 # Get rid of the default route. jexec ${jname} route -6 flush - atf_check -o not-match:"^::/0[[:space:]]+fe80:" \ + atf_check -o not-match:"^default[[:space:]]+fe80:" \ jexec ${jname} netstat -rn -6 # Send another RA, make sure that the default route is installed again. @@ -180,7 +180,7 @@ ndp_slaac_default_route_body() { while [ -z "$(jexec ${jname} ndp -r)" ]; do sleep 0.1 done - atf_check -o match:"^::/0[[:space:]]+fe80:" \ + atf_check -o match:"^default[[:space:]]+fe80:" \ jexec ${jname} netstat -rn -6 } diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index 97509ea6798b..371216f4be59 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -207,8 +207,8 @@ int iflag; /* show interfaces */ int Lflag; /* show size of listen queues */ int mflag; /* show memory stats */ int noutputs = 0; /* how much outputs before we exit */ -int numeric_addr; /* show addresses numerically */ -int numeric_port; /* show ports numerically */ +u_int numeric_addr = 0; /* show addresses numerically */ +bool numeric_port; /* show ports numerically */ int Oflag; /* show nhgrp objects*/ int oflag; /* show nexthop objects*/ int Pflag; /* show TCP log ID */ @@ -361,7 +361,8 @@ main(int argc, char *argv[]) nlistf = optarg; break; case 'n': - numeric_addr = numeric_port = 1; + numeric_addr++; + numeric_port = true; break; case 'o': oflag = 1; diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1 index a5bbfc2f1b35..559cb1932080 100644 --- a/usr.bin/netstat/netstat.1 +++ b/usr.bin/netstat/netstat.1 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 29, 2024 +.Dd January 29, 2025 .Dt NETSTAT 1 .Os .Sh NAME @@ -872,6 +872,12 @@ Normally .Nm attempts to resolve addresses and ports, and display them symbolically. +Specifying +.Fl n +twice will also disable printing the keyword +.Qq Dv default +for the default IPv4 and IPv6 routes when displaying contents of routing +tables. .It Fl W Wider output; expand address fields, etc, to avoid truncation. Non-numeric values such as domain names may still be truncated; use the diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h index 7ebfc5180f44..7e37b9e5e820 100644 --- a/usr.bin/netstat/netstat.h +++ b/usr.bin/netstat/netstat.h @@ -49,8 +49,8 @@ extern int iflag; /* show interfaces */ extern int Lflag; /* show size of listen queues */ extern int mflag; /* show memory stats */ extern int noutputs; /* how much outputs before we exit */ -extern int numeric_addr; /* show addresses numerically */ -extern int numeric_port; /* show ports numerically */ +extern u_int numeric_addr; /* show addresses numerically */ +extern bool numeric_port; /* show ports numerically */ extern int Pflag; /* show TCP log ID */ extern int rflag; /* show routing tables (or routing stats) */ extern int Rflag; /* show flowid / RSS information */ diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index c54b1e61aa11..697c7ba2e9e1 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -578,7 +578,7 @@ netname4(in_addr_t in, in_addr_t mask) struct netent *np = 0; in_addr_t i; - if (!numeric_addr && in == INADDR_ANY && mask == 0) { + if (numeric_addr < 2 && in == INADDR_ANY && mask == 0) { strlcpy(line, "default", sizeof(line)); return (line); } @@ -673,7 +673,7 @@ netname6(struct sockaddr_in6 *sa6, struct sockaddr_in6 *mask) else masklen = 128; - if (!numeric_addr && masklen == 0 && + if (numeric_addr < 2 && masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr)) return("default");