From 79d713eab6181e219bf932b404706f6f59ff2539 Mon Sep 17 00:00:00 2001 From: Byron Stanoszek Date: Thu, 16 Sep 2021 23:38:54 +0200 Subject: [PATCH] ping: Remove 'unsupported IPv6' warning on disabled IPv6 Regression was introduced in d141cb6 as introduced condition if ((errno == EAFNOSUPPORT && socktype == AF_INET6) || options & F_VERBOSE || requisite) was wrong, it should have been: if ((errno == EAFNOSUPPORT && family == AF_INET6 && requisite) || options & F_VERBOSE) but bug was hidden as `family == AF_INET6' was always false until otherwise correct fix 904cdb6 ("ping: AF_INET6 is address family not socket type [lgtm scan]") propagated the error. Tested on kernel booted with ipv6.disable=1 (disabling via sysctl, i.e. sysctl -w net.ipv6.conf.all.disable_ipv6=1; sysctl -w net.ipv6.conf.default.disable_ipv6=1 does not trigger the issue as it exit with "socket: Address family not supported by protocol" - errno EADDRNOTAVAIL). Fixes: d141cb6 ("ping: work with older kernels that don't support ping sockets") Closes: https://github.com/iputils/iputils/issues/293 Closes: https://github.com/iputils/iputils/pull/370 Reported-by: lekto Reviewed-by: Andrew Clayton Reviewed-by: Petr Vorel Signed-off-by: Byron Stanoszek [ pvorel: create commit from Byron's patch on the issue, do analysis and wrote commit message ] Signed-off-by: Petr Vorel --- ping/ping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ping/ping.c b/ping/ping.c index 6fcb44f2..0655bf4a 100644 --- a/ping/ping.c +++ b/ping/ping.c @@ -150,8 +150,8 @@ static void create_socket(struct ping_rts *rts, socket_st *sock, int family, /* Report error related to disabled IPv6 only when IPv6 also failed or in * verbose mode. Report other errors always. */ - if ((errno == EAFNOSUPPORT && family == AF_INET6) || - rts->opt_verbose || requisite) + if ((errno == EAFNOSUPPORT && family == AF_INET6 && requisite) || + rts->opt_verbose) error(0, errno, "socket"); if (requisite) exit(2);