]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftest: tun: Refactor tun_delete to use tuntap_helpers
authorXu Du <xudu@redhat.com>
Wed, 21 Jan 2026 10:04:57 +0000 (18:04 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 23 Jan 2026 19:43:28 +0000 (11:43 -0800)
The previous patch introduced common tuntap helpers to simplify
tun test code. This patch refactors the tun_delete function to
use these new helpers.

Signed-off-by: Xu Du <xudu@redhat.com>
Link: https://patch.msgid.link/ecc7c0c2d75d87cb814e97579e731650339703ab.1768979440.git.xudu@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/Makefile
tools/testing/selftests/net/tun.c

index 33f56fcbde095bd2b63ee61a20af727bdf77c4a4..afdea6d95bde035406cf8f7d7e78c9756731b615 100644 (file)
@@ -183,7 +183,6 @@ TEST_GEN_PROGS := \
        tap \
        tcp_port_share \
        tls \
-       tun \
 # end of TEST_GEN_PROGS
 
 TEST_FILES := \
@@ -195,7 +194,11 @@ TEST_FILES := \
 
 # YNL files, must be before "include ..lib.mk"
 YNL_GEN_FILES := busy_poller
-YNL_GEN_PROGS := netlink-dumps
+YNL_GEN_PROGS := \
+       netlink-dumps \
+       tun \
+# end of YNL_GEN_PROGS
+
 TEST_GEN_FILES += $(YNL_GEN_FILES)
 TEST_GEN_PROGS += $(YNL_GEN_PROGS)
 
@@ -206,7 +209,14 @@ TEST_INCLUDES := forwarding/lib.sh
 include ../lib.mk
 
 # YNL build
-YNL_GENS := netdev
+YNL_GENS := \
+       netdev \
+       rt-addr \
+       rt-link \
+       rt-neigh \
+       rt-route \
+# end of YNL_GENS
+
 include ynl.mk
 
 $(OUTPUT)/epoll_busy_poll: LDLIBS += -lcap
index 128b0a5327d4210fd8aa6d9ed7cf158985bc61a6..d9030bdd2e0623f90a4a0e81a62b6ef990179412 100644 (file)
@@ -8,14 +8,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <linux/if.h>
 #include <linux/if_tun.h>
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 
 #include "kselftest_harness.h"
+#include "tuntap_helpers.h"
 
 static int tun_attach(int fd, char *dev)
 {
@@ -66,40 +64,7 @@ static int tun_alloc(char *dev)
 
 static int tun_delete(char *dev)
 {
-       struct {
-               struct nlmsghdr nh;
-               struct ifinfomsg ifm;
-               unsigned char data[64];
-       } req;
-       struct rtattr *rta;
-       int ret, rtnl;
-
-       rtnl = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
-       if (rtnl < 0) {
-               fprintf(stderr, "can't open rtnl: %s\n", strerror(errno));
-               return 1;
-       }
-
-       memset(&req, 0, sizeof(req));
-       req.nh.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(req.ifm)));
-       req.nh.nlmsg_flags = NLM_F_REQUEST;
-       req.nh.nlmsg_type = RTM_DELLINK;
-
-       req.ifm.ifi_family = AF_UNSPEC;
-
-       rta = (struct rtattr *)(((char *)&req) + NLMSG_ALIGN(req.nh.nlmsg_len));
-       rta->rta_type = IFLA_IFNAME;
-       rta->rta_len = RTA_LENGTH(IFNAMSIZ);
-       req.nh.nlmsg_len += rta->rta_len;
-       memcpy(RTA_DATA(rta), dev, IFNAMSIZ);
-
-       ret = send(rtnl, &req, req.nh.nlmsg_len, 0);
-       if (ret < 0)
-               fprintf(stderr, "can't send: %s\n", strerror(errno));
-       ret = (unsigned int)ret != req.nh.nlmsg_len;
-
-       close(rtnl);
-       return ret;
+       return ip_link_del(dev);
 }
 
 FIXTURE(tun)