diff options
| author | Johannes Berg <[email protected]> | 2025-03-18 08:45:23 +0000 |
|---|---|---|
| committer | Johannes Berg <[email protected]> | 2025-03-18 08:46:36 +0000 |
| commit | c924c5e9b8c65b3a479a90e5e37d74cc8cd9fe0a (patch) | |
| tree | 9626c13418dd3770f2772980a7dacdc110c442b6 /tools/testing/selftests/bpf/network_helpers.c | |
| parent | wifi: iwlwifi: Fix uninitialized variable with __free() (diff) | |
| parent | Merge branch 'net-phy-rework-linkmodes-handling-in-a-dedicated-file' (diff) | |
| download | kernel-c924c5e9b8c65b3a479a90e5e37d74cc8cd9fe0a.tar.gz kernel-c924c5e9b8c65b3a479a90e5e37d74cc8cd9fe0a.zip | |
Merge net-next/main to resolve conflicts
There are a few conflicts between the work that went
into wireless and that's here now, resolve them.
Signed-off-by: Johannes Berg <[email protected]>
Diffstat (limited to 'tools/testing/selftests/bpf/network_helpers.c')
| -rw-r--r-- | tools/testing/selftests/bpf/network_helpers.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 80844a5fb1fe..29541d486c5e 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -548,6 +548,34 @@ void close_netns(struct nstoken *token) free(token); } +int open_tuntap(const char *dev_name, bool need_mac) +{ + int err = 0; + struct ifreq ifr; + int fd = open("/dev/net/tun", O_RDWR); + + if (!ASSERT_GE(fd, 0, "open(/dev/net/tun)")) + return -1; + + ifr.ifr_flags = IFF_NO_PI | (need_mac ? IFF_TAP : IFF_TUN); + strncpy(ifr.ifr_name, dev_name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; + + err = ioctl(fd, TUNSETIFF, &ifr); + if (!ASSERT_OK(err, "ioctl(TUNSETIFF)")) { + close(fd); + return -1; + } + + err = fcntl(fd, F_SETFL, O_NONBLOCK); + if (!ASSERT_OK(err, "fcntl(O_NONBLOCK)")) { + close(fd); + return -1; + } + + return fd; +} + int get_socket_local_port(int sock_fd) { struct sockaddr_storage addr; |
