[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241008-rss-v5-8-f3cf68df005d@daynix.com>
Date: Tue, 08 Oct 2024 15:54:28 +0900
From: Akihiko Odaki <akihiko.odaki@...nix.com>
To: Jonathan Corbet <corbet@....net>,
Willem de Bruijn <willemdebruijn.kernel@...il.com>,
Jason Wang <jasowang@...hat.com>, "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, "Michael S. Tsirkin" <mst@...hat.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>, Shuah Khan <shuah@...nel.org>,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
netdev@...r.kernel.org, kvm@...r.kernel.org,
virtualization@...ts.linux-foundation.org, linux-kselftest@...r.kernel.org,
Yuri Benditovich <yuri.benditovich@...nix.com>,
Andrew Melnychenko <andrew@...nix.com>,
Stephen Hemminger <stephen@...workplumber.org>, gur.stavi@...wei.com,
Akihiko Odaki <akihiko.odaki@...nix.com>
Subject: [PATCH RFC v5 08/10] selftest: tun: Test vnet ioctls without
device
Ensure that vnet ioctls result in EBADFD when the underlying device is
deleted.
Signed-off-by: Akihiko Odaki <akihiko.odaki@...nix.com>
---
tools/testing/selftests/net/tun.c | 74 +++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
index fa83918b62d1..463dd98f2b80 100644
--- a/tools/testing/selftests/net/tun.c
+++ b/tools/testing/selftests/net/tun.c
@@ -159,4 +159,78 @@ TEST_F(tun, reattach_close_delete) {
EXPECT_EQ(tun_delete(self->ifname), 0);
}
+FIXTURE(tun_deleted)
+{
+ char ifname[IFNAMSIZ];
+ int fd;
+};
+
+FIXTURE_SETUP(tun_deleted)
+{
+ self->ifname[0] = 0;
+ self->fd = tun_alloc(self->ifname);
+ ASSERT_LE(0, self->fd);
+
+ ASSERT_EQ(0, tun_delete(self->ifname))
+ EXPECT_EQ(0, close(self->fd));
+}
+
+FIXTURE_TEARDOWN(tun_deleted)
+{
+ EXPECT_EQ(0, close(self->fd));
+}
+
+TEST_F(tun_deleted, getvnethdrsz)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNGETVNETHDRSZ));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, setvnethdrsz)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNSETVNETHDRSZ));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, getvnetle)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNGETVNETLE));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, setvnetle)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNSETVNETLE));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, getvnetbe)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNGETVNETBE));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, setvnetbe)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNSETVNETBE));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, getvnethashcap)
+{
+ struct tun_vnet_hash cap;
+ int i = ioctl(self->fd, TUNGETVNETHASHCAP, &cap);
+
+ if (i == -1 && errno == EBADFD)
+ SKIP(return, "TUNGETVNETHASHCAP not supported");
+
+ EXPECT_EQ(0, i);
+}
+
+TEST_F(tun_deleted, setvnethash)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNSETVNETHASH));
+ EXPECT_EQ(EBADFD, errno);
+}
+
TEST_HARNESS_MAIN
--
2.46.2
Powered by blists - more mailing lists