selftests/bpf: Use if_nametoindex instead of reading the /sys/net/class/*/ifindex
authorMartin KaFai Lau <martin.lau@kernel.org>
Tue, 29 Nov 2022 07:08:54 +0000 (23:08 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 30 Nov 2022 21:47:42 +0000 (22:47 +0100)
commit052c82dcdcbb6eb89d0967c309c010cd293076d0
tree23fb7c74c389e6a8ecaaf97b4b147016d4a73099
parent91a7de85600d5dfa272cea3cef83052e067dc0ab
selftests/bpf: Use if_nametoindex instead of reading the /sys/net/class/*/ifindex

When switching netns, the setns_by_fd() is doing dances in mount/umounting
the /sys directories.  One reason is the tc_redirect.c test is depending
on the /sys/net/class/*/ifindex instead of using the if_nametoindex().
if_nametoindex() uses ioctl() to get the ifindex.

This patch is to move all /sys/net/class/*/ifindex usages to
if_nametoindex().  The current code checks ifindex >= 0 which is
incorrect.  ifindex > 0 should be checked instead.  This patch also
stores ifindex_veth_src and ifindex_veth_dst since the latter patch
will need them.

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/20221129070900.3142427-2-martin.lau@linux.dev
tools/testing/selftests/bpf/prog_tests/tc_redirect.c