mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 21:05:08 +00:00
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. Afteref9e6dc7ee
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. After46d7b45a26
this code path can never be reached. Remove the code. Reviewed by: markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D38475
This commit is contained in:
parent
20b4130314
commit
1dc1f6bd31
|
@ -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_icmph(struct icmp *, struct ip *, const u_char *const);
|
||||||
static void pr_iph(struct ip *, const u_char *);
|
static void pr_iph(struct ip *, const u_char *);
|
||||||
static void pr_pack(char *, ssize_t, struct sockaddr_in *, struct timespec *);
|
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 status(int);
|
||||||
static void stopit(int);
|
static void stopit(int);
|
||||||
|
|
||||||
|
@ -1571,11 +1570,11 @@ pr_icmph(struct icmp *icp, struct ip *oip, const u_char *const oicmp_raw)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Print returned IP header information */
|
/* Print returned IP header information */
|
||||||
pr_retip(oip, oicmp_raw);
|
pr_iph(oip, oicmp_raw);
|
||||||
break;
|
break;
|
||||||
case ICMP_SOURCEQUENCH:
|
case ICMP_SOURCEQUENCH:
|
||||||
(void)printf("Source Quench\n");
|
(void)printf("Source Quench\n");
|
||||||
pr_retip(oip, oicmp_raw);
|
pr_iph(oip, oicmp_raw);
|
||||||
break;
|
break;
|
||||||
case ICMP_REDIRECT:
|
case ICMP_REDIRECT:
|
||||||
switch(icp->icmp_code) {
|
switch(icp->icmp_code) {
|
||||||
|
@ -1596,7 +1595,7 @@ pr_icmph(struct icmp *icp, struct ip *oip, const u_char *const oicmp_raw)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(void)printf("(New addr: %s)\n", inet_ntoa(icp->icmp_gwaddr));
|
(void)printf("(New addr: %s)\n", inet_ntoa(icp->icmp_gwaddr));
|
||||||
pr_retip(oip, oicmp_raw);
|
pr_iph(oip, oicmp_raw);
|
||||||
break;
|
break;
|
||||||
case ICMP_ECHO:
|
case ICMP_ECHO:
|
||||||
(void)printf("Echo Request\n");
|
(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);
|
icp->icmp_code);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pr_retip(oip, oicmp_raw);
|
pr_iph(oip, oicmp_raw);
|
||||||
break;
|
break;
|
||||||
case ICMP_PARAMPROB:
|
case ICMP_PARAMPROB:
|
||||||
(void)printf("Parameter problem: pointer = 0x%02x\n",
|
(void)printf("Parameter problem: pointer = 0x%02x\n",
|
||||||
icp->icmp_hun.ih_pptr);
|
icp->icmp_hun.ih_pptr);
|
||||||
pr_retip(oip, oicmp_raw);
|
pr_iph(oip, oicmp_raw);
|
||||||
break;
|
break;
|
||||||
case ICMP_TSTAMP:
|
case ICMP_TSTAMP:
|
||||||
(void)printf("Timestamp\n");
|
(void)printf("Timestamp\n");
|
||||||
|
@ -1712,28 +1711,6 @@ pr_addr(struct in_addr ina)
|
||||||
return(buf);
|
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 *
|
static char *
|
||||||
pr_ntime(n_time timestamp)
|
pr_ntime(n_time timestamp)
|
||||||
{
|
{
|
||||||
|
|
|
@ -920,6 +920,54 @@ def test_ping_46(self, expected):
|
||||||
},
|
},
|
||||||
id="_3_1_flags_DF",
|
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)
|
@pytest.mark.parametrize("pinger_kargs, expected", pinger_testdata)
|
||||||
|
|
Loading…
Reference in a new issue