From nobody Sun Mar 19 16:33:27 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 4Pfk2H36mvz40PJr; Sun, 19 Mar 2023 16:33:27 +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 4Pfk2H2Dl4z4SrX; Sun, 19 Mar 2023 16:33:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679243607; 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=6as3w0/BRMD08e9uocFg7TE2q/2uWkJquQ8YQ0zAugc=; b=NHTSfgU8iSB96XCV/d9uvyz7lNuoxeDDGZWGv3rFDTmiaYhz95Si7QrVRwWEpGG/XC0yGM wGawRbTbAjhZf4Df3LGt1otj1TQLFDytHmXtOreN27mCjSpy5SNGfpdC/9bbFIlz/MCkv9 Us3XbLD+b5bewmtNMpLgnoeGx7VV5WhSv7+WRZ82lzdHJ6GBTHbh0n/LQuqKb8/Z0QpP/Q 0Tmg/DkxL7qSnbzmZTRYRU8yROVykjoQ3h9g+3LCeyrU134Rj0KnsR18I8VQ8m0ZK6j0AY lr7m1k1iVBKGG9lWuzZc72DJ+BhEcEQHZN3KGzXn15z/BtcFmp3BejuZ864K/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679243607; 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=6as3w0/BRMD08e9uocFg7TE2q/2uWkJquQ8YQ0zAugc=; b=x+bxX09tiy/74y/jwWnThiUmqvOwnRqaEjHLsbH4hMfevbf6Uj3Od9ew5tJXR7Uw/z+um1 OqCoZ0qTh/5TQt6nI/ZpXY/e+Sjb/0iUHwWeC2STUpB1ZujC0WPqq/FhUyDrGpE8hK7xmu JRhzQ6OqbDhogn2VsIF9y+a1n25YFs8OKm1/chSmc2/uC8sx8Jy4suEE6NA7jBskSEz1zS E20nN4GLHgLgLCl6n+c5nCl4Y4YSWcYNErhykAbmSLzGbg8YpQ2MS2r6EgToEFiEN/T/Yq 12hZLOP2MMmNSB0h7FYi1BcoiOqWS9JyEL5tF/5KHBB2QNxXgVyWcDZxGgdSwA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679243607; a=rsa-sha256; cv=none; b=XRDSzJDR/hL4GKDzkEmpbnA2jjW2/7u6KTB/Tzq4RZiOpmIjMcVjnpgnz7RrhMfqfToH/n uZxk0IZpUrH8Kb/xejoJOLlIDLGyWSxjchV85HaQZzVxM/erxqeZNcaqxK1CVfgZzXLI4W gJ5jAGLKhqM8DbfcX/yoi46vzwgLnoElim0i5bGEJhEDrGul1YJJiY57P32ssq329Ze5hm hrku2GUKqVfQRb8uRQUfsJZbC+T8TUVanhy8AV3rFaMYQJk2yBoo/CG5aSHeSP8IldCLvm 64kqS+D2WgqghVrFZieuxE4+UiObeFnVCAoJFdX94qUQmt+NCeIJkzE1o+dwBQ== 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 4Pfk2H17C1zvx0; Sun, 19 Mar 2023 16:33:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32JGXRIS003189; Sun, 19 Mar 2023 16:33:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32JGXR3j003188; Sun, 19 Mar 2023 16:33:27 GMT (envelope-from git) Date: Sun, 19 Mar 2023 16:33:27 GMT Message-Id: <202303191633.32JGXR3j003188@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: 1dc1f6bd3138 - main - ping: Remove pr_retip() 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: 1dc1f6bd3138760a9e96e13017cc3c05e5e1b1e9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1dc1f6bd3138760a9e96e13017cc3c05e5e1b1e9 commit 1dc1f6bd3138760a9e96e13017cc3c05e5e1b1e9 Author: Jose Luis Duran AuthorDate: 2023-02-09 21:05:58 +0000 Commit: Mark Johnston CommitDate: 2023-03-19 16:23:22 +0000 ping: Remove pr_retip() Ping used to provide some sort of packet sniffing capabilities, this was in an era where hubs were used and tcpdump wasn't invented. pr_iph() is a function that prints the IP header of the packet. pr_retip() is essentially a wrapper function to pr_iph(), that also displays the source and destination ports of a TCP or UDP packet. After ef9e6dc7eebe9830511602904d3ef5218d964080 some of this functionality was almost removed, to only display packets sent by us (26+ years ago). At this point, reaching this code path was only possible by doctoring the original packet. After 46d7b45a267b3d78c5054b210ff7b6c55bfca42b this code path can never be reached. Remove the code. Reviewed by: markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D38475 --- sbin/ping/ping.c | 33 +++++------------------------- sbin/ping/tests/test_ping.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index b1721ad72a5c..299b582e29c1 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -227,7 +227,6 @@ static char *pr_ntime(n_time); static void pr_icmph(struct icmp *, struct ip *, const u_char *const); static void pr_iph(struct ip *, const u_char *); static void pr_pack(char *, ssize_t, struct sockaddr_in *, struct timespec *); -static void pr_retip(struct ip *, const u_char *); static void status(int); static void stopit(int); @@ -1571,11 +1570,11 @@ pr_icmph(struct icmp *icp, struct ip *oip, const u_char *const oicmp_raw) break; } /* Print returned IP header information */ - pr_retip(oip, oicmp_raw); + pr_iph(oip, oicmp_raw); break; case ICMP_SOURCEQUENCH: (void)printf("Source Quench\n"); - pr_retip(oip, oicmp_raw); + pr_iph(oip, oicmp_raw); break; case ICMP_REDIRECT: switch(icp->icmp_code) { @@ -1596,7 +1595,7 @@ pr_icmph(struct icmp *icp, struct ip *oip, const u_char *const oicmp_raw) break; } (void)printf("(New addr: %s)\n", inet_ntoa(icp->icmp_gwaddr)); - pr_retip(oip, oicmp_raw); + pr_iph(oip, oicmp_raw); break; case ICMP_ECHO: (void)printf("Echo Request\n"); @@ -1615,12 +1614,12 @@ pr_icmph(struct icmp *icp, struct ip *oip, const u_char *const oicmp_raw) icp->icmp_code); break; } - pr_retip(oip, oicmp_raw); + pr_iph(oip, oicmp_raw); break; case ICMP_PARAMPROB: (void)printf("Parameter problem: pointer = 0x%02x\n", icp->icmp_hun.ih_pptr); - pr_retip(oip, oicmp_raw); + pr_iph(oip, oicmp_raw); break; case ICMP_TSTAMP: (void)printf("Timestamp\n"); @@ -1712,28 +1711,6 @@ pr_addr(struct in_addr ina) return(buf); } -/* - * pr_retip -- - * Dump some info on a returned (via ICMP) IP packet. - */ -static void -pr_retip(struct ip *ip, const u_char *cp) -{ - int8_t hlen; - - pr_iph(ip, cp); - - hlen = ip->ip_hl << 2; - cp = cp + hlen; - - if (ip->ip_p == 6) - (void)printf("TCP: from port %u, to port %u (decimal)\n", - (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3))); - else if (ip->ip_p == 17) - (void)printf("UDP: from port %u, to port %u (decimal)\n", - (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3))); -} - static char * pr_ntime(n_time timestamp) { diff --git a/sbin/ping/tests/test_ping.py b/sbin/ping/tests/test_ping.py index 79fd332f1c18..639973d093d4 100644 --- a/sbin/ping/tests/test_ping.py +++ b/sbin/ping/tests/test_ping.py @@ -920,6 +920,54 @@ Vr HL TOS Len ID Flg off TTL Pro cks Src Dst }, id="_3_1_flags_DF", ), + pytest.param( + { + "src": "192.0.2.1", + "dst": "192.0.2.2", + "icmp_type": 3, + "icmp_code": 1, + "special": "tcp", + }, + { + "returncode": 2, + "stdout": """\ +PATTERN: 0x01 +PING 192.0.2.2 (192.0.2.2): 56 data bytes + +--- 192.0.2.2 ping statistics --- +1 packets transmitted, 0 packets received, 100.0% packet loss +""", + "stderr": """\ +ping: quoted data too short (40 bytes) from 192.0.2.2 +""", + "redacted": False, + }, + id="_3_1_special_tcp", + ), + pytest.param( + { + "src": "192.0.2.1", + "dst": "192.0.2.2", + "icmp_type": 3, + "icmp_code": 1, + "special": "udp", + }, + { + "returncode": 2, + "stdout": """\ +PATTERN: 0x01 +PING 192.0.2.2 (192.0.2.2): 56 data bytes + +--- 192.0.2.2 ping statistics --- +1 packets transmitted, 0 packets received, 100.0% packet loss +""", + "stderr": """\ +ping: quoted data too short (28 bytes) from 192.0.2.2 +""", + "redacted": False, + }, + id="_3_1_special_udp", + ), ] @pytest.mark.parametrize("pinger_kargs, expected", pinger_testdata)