From nobody Wed Oct 11 18:01:08 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 4S5LDP22Zwz4wTnK; Wed, 11 Oct 2023 18:01:09 +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 4S5LDP0bcwz4PrG; Wed, 11 Oct 2023 18:01:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697047269; 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=ufrxik+aHR6HR6vV6g9AOCkdv6g2dmBFWlupaud/FWs=; b=aVOkHkO+u1xo2/vqYKYq7MI3Zim1xLHNU700lS+2vJ/BAJp3ROMk1ydnOpoT8ndg5L00jo fCC6dg8NUdEOR8R92nM7yWqHY7oXX13WkXXqd969bV6cJowm1cYPGd8SiqLbUCcI/e/22c 4olixkfv1iK8DG80lW4j3rlWMPSCounVFWnjI+PgTzc2H09Ekty2ul3A178YNQFT/Y/BuM 8rVuBQwMF+Nd6RJyaRKzNhuDZPC98UR+d/T6wLTaPJ4/lFUmO36cvb2GNhMI0PXuXpXZCo Wkq/n+4BgRaiFQLulIto02BA2KnBYT/gk6x2pBEU2m502Icl0iLu44jOCq4ZCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697047269; a=rsa-sha256; cv=none; b=ORA4/cSJXSes4PgpoSPK2XGpNDf9dAxblFcxBTyuxqmHgSlsVH3d/TpB+9qdxygp0dzdyd bWf4S0QjA2Ec0Hq1fJV2Lypx3fyXxmNKis89RS6ZrRQ3jl6y5/xHBG5kwoNalNPlWeHHXZ Uv30NxCDGwiXI7LV551kh6dStk8/6WjNJjYGCQQtMU0OSV4N3+486gBZ0CWVXXXDbL87FR SC+meM/otZ9X7oixRsG6TDsdK2VQGod6nEK7xdOGzXJyZm5b5N9H/dqbQQSmwFKGrfbOzv cDNchObInIUPm+USCnYHR59ZgYCsyboNKSfacXbVm3Zxj2bdm9pKyVSssIQfPw== 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=1697047269; 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=ufrxik+aHR6HR6vV6g9AOCkdv6g2dmBFWlupaud/FWs=; b=YgRvMv3OcLivqayRmm++mCEpxAL2yhCgNRL3C7yNGL/NGirl7/pXDfJ6s1fxZD7zk8Dxql fX3c0/s3cgaXNeIoKK2qZjRlbWuNfcaGZjLFZ3H0v9Fg/HrO+soXreWbwq+P5N7WagtA2D Pt4m1POndjfnDiuVi/ZUGxxdOzvMcSQnfJh4EE/33N/CXTfU3ssG74N/nLUzTQAXoI/inv Yv+2xT20xdooDCPUGoLA6DThPtWlr4W2Fv/kpQyNbqEljZ7KsHADaZrscKsJBm6seJh8Xe tfw85FzAchp58+2YKIkEqaaPpoFoJY8PTpKRjd7I1PdOnTuR6Dux5EoGoDzBdA== 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 4S5LDN6lzGzWSy; Wed, 11 Oct 2023 18:01:08 +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 39BI18uY053903; Wed, 11 Oct 2023 18:01:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39BI18eL053900; Wed, 11 Oct 2023 18:01:08 GMT (envelope-from git) Date: Wed, 11 Oct 2023 18:01:08 GMT Message-Id: <202310111801.39BI18eL053900@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: b86e4812cce8 - main - 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/main X-Git-Reftype: branch X-Git-Commit: b86e4812cce88920cb592bd3b8571572373dbb9c Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b86e4812cce88920cb592bd3b8571572373dbb9c commit b86e4812cce88920cb592bd3b8571572373dbb9c Author: Jose Luis Duran AuthorDate: 2023-04-13 15:30:44 +0000 Commit: Mark Johnston CommitDate: 2023-10-11 17:48:28 +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 --- 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 545e680fbc9f..645940a62cb6 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 ---