git: 1dc1f6bd3138 - main - ping: Remove pr_retip()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 19 Mar 2023 16:33:27 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=1dc1f6bd3138760a9e96e13017cc3c05e5e1b1e9
commit 1dc1f6bd3138760a9e96e13017cc3c05e5e1b1e9
Author: Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2023-02-09 21:05:58 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
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)