From nobody Sun Mar 19 16:33:25 2023 X-Original-To: dev-commits-src-main@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 4Pfk2G1hg5z40PJp; Sun, 19 Mar 2023 16:33:26 +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 4Pfk2G19qYz4TDk; Sun, 19 Mar 2023 16:33:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679243606; 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=DnkD1/Y8lbZ15wGR+ek+lmt//O8IApLA3DOYefzLuiQ=; b=LMCe/yo7RiSZWtfUKQqPg25F/a3HwAMjw751fmsHaTf+29kkKTNLdwVT+Fj1MrtWV7mRIg R4I4Hbzsr26K+JC98o6qbfNfu4blRGYnrsN39coZsABvlK1I35U6bjetWVTmehZfdyGnBn xfqpEL9vRp+k2lobmpOROjjXPQRkJJ9cwV0tnH3WnYdYv8lgCUTsposvJNyTzFImh6BBRk cppmbT6lPPUoyLvszmmUUJ7S6DQ2rRu20ycfJeTITJJkDLZejRrcLsLKAs4HUDaoVXLkVF zhG96ByKKmk2iZIJ2Y3ZBE4dIicSZIifr8kRbRv76EElnIBHnvTPiemqJP6sOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679243606; 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=DnkD1/Y8lbZ15wGR+ek+lmt//O8IApLA3DOYefzLuiQ=; b=ff9w8NTtC73aq3OuYDf/07BmkuK4GBNS3x6cvP/tqy06ECxlw8LeKDQEEhNSyfhNwdlo7G PsA+q3bUC4U8Y9hH+uimSOH+dXRQnCk4SazdhKFzVJ99RmFz8KihZ1Z7/OOfiwlEA8QUw8 5zQ38tu1dDHwJ2xCSBcr2i7ggD7lFNlXVQjlIYh63mdT3nvsvgS8BpmKg8z949jT4zLMuJ Cci1FoPYQ4Unq/fXr096ayCTL1JYaj104jdsylCaJo4qaHW1Jti9duaxS0XlaCj6ACi4C+ R5fZZi8oCIyhCc6DNQK6IQNCxOn0oQfHfgNKUWIwxi4cH1wrSdZENO7//xVN3g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679243606; a=rsa-sha256; cv=none; b=PQdKXEX8gAxcDk0SM1ZJsGFsq44aIxD8BgAfYff3HBupaYSqDrwlkZxzF2CT9sNQhTnVK+ cBR7rAs/JuqCkt6SNSLznhbWOdaUH5+ZXAxVy67B4IsHHBEYMCm0QFcAopn6jf5NFsNRgW 4LqPRzRgFmkQJcYTC+f2iVxbiIix198Ym3tI6dS26IMgA1tFw3D0R19cKt+T9EJpaZ/D0a CLh3fSX1syYh9aUzIIZ6qNiMHpOchfM2rbItY39ja0qEmi1C7ZpB/Jwt5WZLEUUWCkc6vI VKyWwvHYrwSUTpxE8iI2oHhHaH1ON26Vp4zK2WCFUYNaVV3KrCLb7bPBmq3fIg== 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 4Pfk2G0CnXzwPn; Sun, 19 Mar 2023 16:33:26 +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 32JGXPhR003164; Sun, 19 Mar 2023 16:33:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32JGXPov003163; Sun, 19 Mar 2023 16:33:25 GMT (envelope-from git) Date: Sun, 19 Mar 2023 16:33:25 GMT Message-Id: <202303191633.32JGXPov003163@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: 20b41303140e - main - ping: Print the IP options of the original packet List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 20b41303140eee4dfb896558fb83600c5f013d39 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=20b41303140eee4dfb896558fb83600c5f013d39 commit 20b41303140eee4dfb896558fb83600c5f013d39 Author: Jose Luis Duran AuthorDate: 2023-02-09 15:47:53 +0000 Commit: Mark Johnston CommitDate: 2023-03-19 16:23:06 +0000 ping: Print the IP options of the original packet When an ICMP packet contains an IP packet in its payload, and that original IP packet contains options, these options were not displayed accordingly in pr_iph(). pr_iph() is a function that prints the original "quoted packet" IP header, with only an IP struct as an argument. The IP struct does not contain IP options, and it is not guaranteed that the options will be contiguous in memory to the IP struct after d9cacf605e2ac0f704e1ce76357cbfbe6cb63d52. Pass the raw ICMP data along with the IP struct, in order to print the options, if any. Reviewed by: markj MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D38469 --- sbin/ping/ping.c | 19 ++++++++++--------- sbin/ping/tests/ping_test.sh | 2 +- sbin/ping/tests/test_ping.py | 1 - 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index fe319bfb70a5..b1721ad72a5c 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -225,7 +225,7 @@ static void pinger(void); static char *pr_addr(struct in_addr); static char *pr_ntime(n_time); static void pr_icmph(struct icmp *, struct ip *, const u_char *const); -static void pr_iph(struct ip *); +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); @@ -1157,7 +1157,6 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) struct ip oip; u_char oip_header_len; struct icmp oicmp; - const u_char *oicmp_raw; /* * Get size of IP header of the received packet. @@ -1355,8 +1354,6 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) } memcpy(&oip, icmp_data_raw, sizeof(struct ip)); - oicmp_raw = icmp_data_raw + oip_header_len; - memcpy(&oicmp, oicmp_raw, sizeof(struct icmp)); if (((options & F_VERBOSE) && uid == 0) || (!(options & F_QUIET2) && @@ -1366,7 +1363,7 @@ pr_pack(char *buf, ssize_t cc, struct sockaddr_in *from, struct timespec *tv) (oicmp.icmp_id == ident))) { (void)printf("%zd bytes from %s: ", cc, pr_addr(from->sin_addr)); - pr_icmph(&icp, &oip, oicmp_raw); + pr_icmph(&icp, &oip, icmp_data_raw); } else return; } @@ -1663,14 +1660,13 @@ pr_icmph(struct icmp *icp, struct ip *oip, const u_char *const oicmp_raw) * Print an IP header with options. */ static void -pr_iph(struct ip *ip) +pr_iph(struct ip *ip, const u_char *cp) { struct in_addr ina; - u_char *cp; int hlen; hlen = ip->ip_hl << 2; - cp = (u_char *)ip + sizeof(struct ip); /* point to options */ + cp = cp + sizeof(struct ip); /* point to options */ (void)printf("Vr HL TOS Len ID Flg off TTL Pro cks Src Dst\n"); (void)printf(" %1x %1x %02x %04x %04x", @@ -1723,7 +1719,12 @@ pr_addr(struct in_addr ina) static void pr_retip(struct ip *ip, const u_char *cp) { - pr_iph(ip); + 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", diff --git a/sbin/ping/tests/ping_test.sh b/sbin/ping/tests/ping_test.sh index 9f821ed96360..53383f2fb7bc 100644 --- a/sbin/ping/tests/ping_test.sh +++ b/sbin/ping/tests/ping_test.sh @@ -178,7 +178,7 @@ inject_pip_head() } inject_pip_body() { - atf_check -s exit:2 -o match:"Destination Host Unreachable" -o not-match:"01010101" python3 $(atf_get_srcdir)/injection.py pip + atf_check -s exit:2 -o match:"Destination Host Unreachable" -o match:"(01){40}" python3 $(atf_get_srcdir)/injection.py pip } inject_pip_cleanup() { diff --git a/sbin/ping/tests/test_ping.py b/sbin/ping/tests/test_ping.py index a9b760ff7aca..79fd332f1c18 100644 --- a/sbin/ping/tests/test_ping.py +++ b/sbin/ping/tests/test_ping.py @@ -893,7 +893,6 @@ Vr HL TOS Len ID Flg off TTL Pro cks Src Dst "stderr": "", "redacted": False, }, - marks=pytest.mark.skip("XXX currently failing"), id="_3_1_opts_NOP_40", ), pytest.param(