diff mbox series

[bpf] selftests/bpf: Use ping6 only if available in tc_redirect

Message ID 20210708021727.5538-1-joamaki@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: BPF
Headers show
Series [bpf] selftests/bpf: Use ping6 only if available in tc_redirect | expand

Commit Message

Jussi Maki July 8, 2021, 2:17 a.m. UTC
In the tc_redirect test only use ping6 if it's available and
otherwise fall back to using "ping -6".

Signed-off-by: Jussi Maki <joamaki@gmail.com>
---
 .../selftests/bpf/prog_tests/tc_redirect.c    | 23 ++++++++++++++-----
 1 file changed, 17 insertions(+), 6 deletions(-)

Comments

Andrii Nakryiko July 27, 2021, 6:02 p.m. UTC | #1
On Mon, Jul 26, 2021 at 7:20 AM Jussi Maki <joamaki@gmail.com> wrote:
>
> In the tc_redirect test only use ping6 if it's available and
> otherwise fall back to using "ping -6".
>
> Signed-off-by: Jussi Maki <joamaki@gmail.com>
> ---

The tests weren't broken per se, they just required a more particular
environment set up. So I consider this an improvement rather than bug
fix and applied this to bpf-next, where it's much more important to
have all the tests passing in an ongoing fashion. Thanks!

>  .../selftests/bpf/prog_tests/tc_redirect.c    | 23 ++++++++++++++-----
>  1 file changed, 17 insertions(+), 6 deletions(-)
>

[...]
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
index 5703c918812b..932e4ee3f97c 100644
--- a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
+++ b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
@@ -13,15 +13,16 @@ 
 #define _GNU_SOURCE
 
 #include <arpa/inet.h>
+#include <linux/if.h>
+#include <linux/if_tun.h>
 #include <linux/limits.h>
 #include <linux/sysctl.h>
-#include <linux/if_tun.h>
-#include <linux/if.h>
 #include <sched.h>
 #include <stdbool.h>
 #include <stdio.h>
-#include <sys/stat.h>
 #include <sys/mount.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include "test_progs.h"
 #include "network_helpers.h"
@@ -389,11 +390,21 @@  static void test_tcp(int family, const char *addr, __u16 port)
 		close(client_fd);
 }
 
-static int test_ping(int family, const char *addr)
+static char *ping_command(int family)
 {
-	const char *ping = family == AF_INET6 ? "ping6" : "ping";
+	if (family == AF_INET6) {
+		/* On some systems 'ping' doesn't support IPv6, so use ping6 if it is present. */
+		if (!system("which ping6 >/dev/null 2>&1"))
+			return "ping6";
+		else
+			return "ping -6";
+	}
+	return "ping";
+}
 
-	SYS("ip netns exec " NS_SRC " %s " PING_ARGS " %s > /dev/null", ping, addr);
+static int test_ping(int family, const char *addr)
+{
+	SYS("ip netns exec " NS_SRC " %s " PING_ARGS " %s > /dev/null", ping_command(family), addr);
 	return 0;
 fail:
 	return -1;