Blame SOURCES/0006-ping-Fix-unwanted-bell-on-unreachable-address.patch

76c671
From dc4f836759887a6edf141aa55adbdb9bc63f5e69 Mon Sep 17 00:00:00 2001
76c671
From: Jan Macku <jamacku@redhat.com>
76c671
Date: Tue, 22 Mar 2022 12:59:21 +0100
76c671
Subject: [PATCH] ping: Fix unwanted bell on unreachable address
76c671
76c671
Commit 4471ac629cf2603f4b8b45e042e072c992ce25a5 caused regression for IPv6
76c671
that ping -a IP6_ADDR beeps also on wrong address (i.e.  when "Address
76c671
unreachable"):
76c671
76c671
    $ ping -a -c1 fd00:1:1:1::15
76c671
    PING fd00:1:1:1::15(fd00:1:1:1::15) 56 data bytes
76c671
    From fd00:1:1:1::2 icmp_seq=1 Destination unreachable: Address unreachable
76c671
76c671
    --- fd00:1:1:1::15 ping statistics ---
76c671
    1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0m
76c671
76c671
It should only bell when ping returns correctly.
76c671
76c671
Another (fixed) regression was that ping after exit printed error "pipe N",
76c671
where N is number of counts. Error was result of code from ping_common.c:
76c671
printf("%spipe %d", comma, pipesize);
76c671
76c671
4471ac6 was wrong that code for sock->working_recverr == 1 should stay,
76c671
sock->working_recverr should be removed.
76c671
76c671
Thus changes:
76c671
* ping.c: put back "stronger filter" for raw socket but (unlike before
76c671
  4471ac6) exit with 2 if setsockopt(ICMP_FILTER) fails
76c671
* ping6_common.c: put back setsockopt(IPV6_RECVERR), but (unlike before
76c671
  4471ac6) exit with 2 if it fails
76c671
* ping6_common.c: remove ICMP6_FILTER_SETPASS calls. These caused error "pipe N".
76c671
* ping6_common.c: return 0 after acknowledge() in ping6_parse_reply
76c671
76c671
Fixes: 4471ac6 ("ping: Remove workaround for bug in IP_RECVERR on raw sockets")
76c671
Fixes: https://github.com/iputils/iputils/issues/182
76c671
Reported-by: Luiz Angelo Daros de Luca <luizluca@tre-sc.jus.br>
76c671
Signed-off-by: Petr Vorel <pvorel@suse.cz>
76c671
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
76c671
76c671
---
76c671
Patch has been adjusted to be applicable to RHEL8 codebase
76c671
76c671
Resolves: #2057570
76c671
---
76c671
 ping.c         | 11 +++++++++++
76c671
 ping6_common.c | 15 +++------------
76c671
 2 files changed, 14 insertions(+), 12 deletions(-)
76c671
76c671
diff --git a/ping.c b/ping.c
76c671
index d9a3f5d..c870390 100644
76c671
--- a/ping.c
76c671
+++ b/ping.c
76c671
@@ -949,6 +949,17 @@ int ping4_receive_error_msg(socket_st *sock)
76c671
 
76c671
 		acknowledge(ntohs(icmph.un.echo.sequence));
76c671
 
76c671
+		if (sock->socktype == SOCK_RAW)
76c671
+		{
76c671
+			struct icmp_filter filt;
76c671
+
76c671
+			filt.data = ~((1 << ICMP_SOURCE_QUENCH) |
76c671
+						  (1 << ICMP_REDIRECT) |
76c671
+						  (1 << ICMP_ECHOREPLY));
76c671
+			if (setsockopt(sock->fd, SOL_RAW, ICMP_FILTER, (const void *)&filt,
76c671
+						   sizeof(filt)) == -1)
76c671
+				error(2, errno, "setsockopt(ICMP_FILTER)");
76c671
+		}
76c671
 		net_errors++;
76c671
 		nerrors++;
76c671
 		if (options & F_QUIET)
76c671
diff --git a/ping6_common.c b/ping6_common.c
76c671
index 5991c2a..1181341 100644
76c671
--- a/ping6_common.c
76c671
+++ b/ping6_common.c
76c671
@@ -879,6 +879,8 @@ int ping6_run(int argc, char **argv, struct addrinfo *ai, struct socket_st *sock
76c671
 	}
76c671
 
76c671
 	hold = 1;
76c671
+	if (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_RECVERR, (const void *)&hold, sizeof hold))
76c671
+		error(2, errno, "IPV6_RECVERR");
76c671
 
76c671
 	/* Estimate memory eaten by single packet. It is rough estimate.
76c671
 	 * Actually, for small datalen's it depends on kernel side a lot. */
76c671
@@ -906,11 +908,6 @@ int ping6_run(int argc, char **argv, struct addrinfo *ai, struct socket_st *sock
76c671
 
76c671
 		ICMP6_FILTER_SETBLOCKALL(&filter);
76c671
 
76c671
-		ICMP6_FILTER_SETPASS(ICMP6_DST_UNREACH, &filter);
76c671
-		ICMP6_FILTER_SETPASS(ICMP6_PACKET_TOO_BIG, &filter);
76c671
-		ICMP6_FILTER_SETPASS(ICMP6_TIME_EXCEEDED, &filter);
76c671
-		ICMP6_FILTER_SETPASS(ICMP6_PARAM_PROB, &filter);
76c671
-
76c671
 		if (niquery_is_enabled())
76c671
 			ICMP6_FILTER_SETPASS(ICMPV6_NI_REPLY, &filter);
76c671
 		else
76c671
@@ -1437,13 +1434,7 @@ ping6_parse_reply(socket_st *sock, struct msghdr *msg, int cc, void *addr, struc
76c671
 			    !is_ours(sock, icmph1->icmp6_id))
76c671
 				return 1;
76c671
 			acknowledge(ntohs(icmph1->icmp6_seq));
76c671
-			nerrors++;
76c671
-			if (options & F_FLOOD) {
76c671
-				write_stdout("\bE", 2);
76c671
-				return 0;
76c671
-			}
76c671
-			print_timestamp();
76c671
-			printf("From %s: icmp_seq=%u ", pr_addr(from, sizeof *from), ntohs(icmph1->icmp6_seq));
76c671
+			return 0;
76c671
 		} else {
76c671
 			/* We've got something other than an ECHOREPLY */
76c671
 			if (!(options & F_VERBOSE) || uid)
76c671
-- 
76c671
2.35.1
76c671