From nobody Mon Nov 06 16:45:56 2023 X-Original-To: dev-commits-src-all@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 4SPHKc3Pk4z50FBq; Mon, 6 Nov 2023 16:45:56 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SPHKc1kFsz4GvZ; Mon, 6 Nov 2023 16:45:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699289156; 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=fbmUCZOMWCEYUjveOC2Ggt7AQ2KP4mPlXK3G0W0r+ak=; b=XDbSJ5cPz0+RFJ0enr3lgRlTV+JqikL9Q9CQUuPCMA6YSjKuovV500SCp0KGcbi/8lnE3n K2DK1gAdMpcHKPi5FCko+0pXnUL0eoAlj9VjzPPCKqZgIuS33pxJzO5m0bV9D3nsXXHUJ3 I3ymnNHTVufynqoQyf3pTPp2lWSkYtpRkMVJZebj0tOkn7twbcVLEyAtvNJXna3FvZRP/T /ujF44F7FQgMrOnt59kDdOS+kZr5xsytsie+PWOVa6I1W+fpxZWRzCg9kc4Z4BbDn3lu2g Ku6yne7+b+bkFZnMEeTZep/sG/kCJsjw0Fx2ZzcPlgrXHnDK9Lb6H4WiiSZkgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699289156; 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=fbmUCZOMWCEYUjveOC2Ggt7AQ2KP4mPlXK3G0W0r+ak=; b=yI9Qzyp7lCOatA005sLGHFwwG/T+spyw190OUAicgnIlyicr4iTLpxdhXnX8dxx5wuA4jo /2QB1GtIcmTPBFQ2aCgCrqGxYHoUIxRjvyZJXODzpreCPhLTGhr/g5zo7ErTDPWeCtgxiZ 6eI/ILXIJZ/d48ymMdl6csa4XtXFRt7j/BbSIKqXv2iEGEZiLbbeZ5VDqX032U6ozdkM+2 bp0XODWF8KKY2NdQQmYKkbA/Wfi5W3X6l08iLlaTbh5XqyjjXrYFQS8mDPLjI6tYx9QDN/ k5UebEghGihV7Romsj94dnoHys+uef7ooxZ82v0Q1U2Q1vyQoaxXBNlhYbEiSg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699289156; a=rsa-sha256; cv=none; b=UHaAT13NE1Favup7dVoEcift9IrV9sEPG1dZE2+0RE9EgJhQbBNW7Aa8+esWRfGZabiXsA E5hd769v80xkY/yB/dfOazCcyMZIGr6WTP7An5/XfwvAcUX9EFM37Iz4rU1tzWtAkSaWUr NFNwdhDl9I1Q3UT4QRvN9JM4tRI/h48vSgMNxR7yGc2KXAzJzNtrqRX52wWwklGVN2hINp 7WRo0DDPaRlLOpR6BR0lQHiS6DiraCVDaB3n/SdOopkm1WQ9STO2SjbLNrOeS8BvlJsUfd TIRSivYh1ju+28CHwPlKHgBqNJAhaeqHvBFmjLqpi8WK4yAdsTdGPTy02A7mNQ== 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 4SPHKc0r1Xz14t; Mon, 6 Nov 2023 16:45:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3A6GjuSQ058519; Mon, 6 Nov 2023 16:45:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A6GjuED058516; Mon, 6 Nov 2023 16:45:56 GMT (envelope-from git) Date: Mon, 6 Nov 2023 16:45:56 GMT Message-Id: <202311061645.3A6GjuED058516@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: a753d3632eaf - stable/14 - ping: pr_iph() improvements List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: a753d3632eaf8369a6fc8eff0c904b935f56dad9 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=a753d3632eaf8369a6fc8eff0c904b935f56dad9 commit a753d3632eaf8369a6fc8eff0c904b935f56dad9 Author: Jose Luis Duran AuthorDate: 2023-04-13 15:30:44 +0000 Commit: Mark Johnston CommitDate: 2023-11-06 16:45:44 +0000 ping: pr_iph() improvements Very early on, the Src/Dst IP addresses were printed in hex notation (%08x), which will always be 8-characters wide. It was later changed to use a dot-decimal notation. Depending on the IP address length, the Src and Dst headers may require a different padding. Use the source and destination IP lengths as padding for the headers. Also, print an Opts (options) header, if there are options present. It has been abbreviated to Opts to match the length of the previous Data header, removed in ef9e6dc7eebe9830511602904d3ef5218d964080. Print the header info such that no trailing spaces are produced. As some git workflows may automatically trim them, and make the tests fail (see 25b86f8559c2e7076daff56933217e95cd4398d4). Before Vr HL TOS Len ID Flg off TTL Pro cks Src Dst 4 f 00 007c 0001 0 0000 40 01 d868 192.0.2.1 192.0.2.2␣ After Vr HL TOS Len ID Flg off TTL Pro cks Src Dst 4 f 00 007c 0001 0 0000 40 01 d868 192.0.2.1 192.0.2.2 And with options: Before Vr HL TOS Len ID Flg off TTL Pro cks Src Dst 4 f 00 007c 0001 0 0000 40 01 d868 192.0.2.1 192.0.2.2 01... After Vr HL TOS Len ID Flg off TTL Pro cks Src Dst Opts 4 f 00 007c 0001 0 0000 40 01 d868 192.0.2.1 192.0.2.2 01... Reviewed by: markj MFC after: 1 week Pull Request: https://github.com/freebsd/freebsd-src/pull/863 Differential Revision: https://reviews.freebsd.org/D39561 (cherry picked from commit b86e4812cce88920cb592bd3b8571572373dbb9c) --- sbin/ping/ping.c | 25 +++++++++++++++++-------- sbin/ping/tests/test_ping.py | 12 ++++++------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index fcc27d34ee54..3b8663772e87 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1561,13 +1561,21 @@ pr_icmph(struct icmp *icp, struct ip *oip, const u_char *const oicmp_raw) static void pr_iph(struct ip *ip, const u_char *cp) { - struct in_addr ina; + struct in_addr dst_ina, src_ina; int hlen; hlen = ip->ip_hl << 2; cp = cp + sizeof(struct ip); /* point to options */ - (void)printf("Vr HL TOS Len ID Flg off TTL Pro cks Src Dst\n"); + memcpy(&src_ina, &ip->ip_src.s_addr, sizeof(src_ina)); + memcpy(&dst_ina, &ip->ip_dst.s_addr, sizeof(dst_ina)); + + (void)printf("Vr HL TOS Len ID Flg off TTL Pro cks %*s %*s", + (int)strlen(inet_ntoa(src_ina)), "Src", + (int)strlen(inet_ntoa(dst_ina)), "Dst"); + if (hlen > (int)sizeof(struct ip)) + (void)printf(" Opts"); + (void)putchar('\n'); (void)printf(" %1x %1x %02x %04x %04x", ip->ip_v, ip->ip_hl, ip->ip_tos, ntohs(ip->ip_len), ntohs(ip->ip_id)); @@ -1576,13 +1584,14 @@ pr_iph(struct ip *ip, const u_char *cp) ntohs(ip->ip_off) & 0x1fff); (void)printf(" %02x %02x %04x", ip->ip_ttl, ip->ip_p, ntohs(ip->ip_sum)); - memcpy(&ina, &ip->ip_src.s_addr, sizeof ina); - (void)printf(" %s ", inet_ntoa(ina)); - memcpy(&ina, &ip->ip_dst.s_addr, sizeof ina); - (void)printf(" %s ", inet_ntoa(ina)); + (void)printf(" %s", inet_ntoa(src_ina)); + (void)printf(" %s", inet_ntoa(dst_ina)); /* dump any option bytes */ - while (hlen-- > (int)sizeof(struct ip)) { - (void)printf("%02x", *cp++); + if (hlen > (int)sizeof(struct ip)) { + (void)printf(" "); + while (hlen-- > (int)sizeof(struct ip)) { + (void)printf("%02x", *cp++); + } } (void)putchar('\n'); } diff --git a/sbin/ping/tests/test_ping.py b/sbin/ping/tests/test_ping.py index 00ddbbd63723..2a052b50ce07 100644 --- a/sbin/ping/tests/test_ping.py +++ b/sbin/ping/tests/test_ping.py @@ -1244,8 +1244,8 @@ round-trip min/avg/max/stddev = /// ms "stdout": """\ PING 192.0.2.2 (192.0.2.2): 56 data bytes 132 bytes from 192.0.2.2: Destination Host Unreachable -Vr HL TOS Len ID Flg off TTL Pro cks Src Dst - 4 f 00 007c 0001 0 0000 40 01 d868 192.0.2.1 192.0.2.2 01010101010101010101010101010101010101010101010101010101010101010101010101010101 +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst Opts + 4 f 00 007c 0001 0 0000 40 01 d868 192.0.2.1 192.0.2.2 01010101010101010101010101010101010101010101010101010101010101010101010101010101 --- 192.0.2.2 ping statistics --- @@ -1269,8 +1269,8 @@ Vr HL TOS Len ID Flg off TTL Pro cks Src Dst "stdout": """\ PING 192.0.2.2 (192.0.2.2): 56 data bytes 92 bytes from 192.0.2.2: Destination Host Unreachable -Vr HL TOS Len ID Flg off TTL Pro cks Src Dst - 4 5 00 0054 0001 2 0000 40 01 b6a4 192.0.2.1 192.0.2.2 +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst + 4 5 00 0054 0001 2 0000 40 01 b6a4 192.0.2.1 192.0.2.2 --- 192.0.2.2 ping statistics --- @@ -1342,8 +1342,8 @@ ping: quoted data too short (28 bytes) from 192.0.2.2 "stdout": """\ PING 192.0.2.2 (192.0.2.2): 56 data bytes 92 bytes from 192.0.2.2: Destination Host Unreachable -Vr HL TOS Len ID Flg off TTL Pro cks Src Dst - 4 5 00 0054 0001 0 0000 40 01 f6a4 192.0.2.1 192.0.2.2 +Vr HL TOS Len ID Flg off TTL Pro cks Src Dst + 4 5 00 0054 0001 0 0000 40 01 f6a4 192.0.2.1 192.0.2.2 --- 192.0.2.2 ping statistics ---