Skip to content

Commit ec2bb58

Browse files
MarcusWichelmannKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: fix file descriptor assertion in open_tuntap helper
The open_tuntap helper function uses open() to get a file descriptor for /dev/net/tun. The open(2) manpage writes this about its return value: On success, open(), openat(), and creat() return the new file descriptor (a nonnegative integer). On error, -1 is returned and errno is set to indicate the error. This means that the fd > 0 assertion in the open_tuntap helper is incorrect and should rather check for fd >= 0. When running the BPF selftests locally, this incorrect assertion was not an issue, but the BPF kernel-patches CI failed because of this: open_tuntap:FAIL:open(/dev/net/tun) unexpected open(/dev/net/tun): actual 0 <= expected 0 Signed-off-by: Marcus Wichelmann <[email protected]>
1 parent 70a8be8 commit ec2bb58

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/testing/selftests/bpf/network_helpers.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ int open_tuntap(const char *dev_name, bool need_mac)
571571
struct ifreq ifr;
572572
int fd = open("/dev/net/tun", O_RDWR);
573573

574-
if (!ASSERT_GT(fd, 0, "open(/dev/net/tun)"))
574+
if (!ASSERT_GE(fd, 0, "open(/dev/net/tun)"))
575575
return -1;
576576

577577
ifr.ifr_flags = IFF_NO_PI | (need_mac ? IFF_TAP : IFF_TUN);

0 commit comments

Comments
 (0)