Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Xu Du <xudu@redhat.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, shuah@kernel.org
Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH net-next v3 3/8] selftest: tun: Refactor tun_delete to use tuntap_helpers
Date: Mon,  5 Jan 2026 11:44:38 +0800	[thread overview]
Message-ID: <832ffbf4ec570342e29c75a02457e3f4e2beb14a.1767580224.git.xudu@redhat.com> (raw)
In-Reply-To: <cover.1767580224.git.xudu@redhat.com>

The previous patch introduced common tuntap helpers to simplify
tuntap test code. This patch refactors the tun_delete function
to use these new helpers.

Signed-off-by: Xu Du <xudu@redhat.com>
---
 tools/testing/selftests/net/tun.c | 39 ++-----------------------------
 1 file changed, 2 insertions(+), 37 deletions(-)

diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
index 128b0a5327d4..08e760fa5d15 100644
--- a/tools/testing/selftests/net/tun.c
+++ b/tools/testing/selftests/net/tun.c
@@ -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 dev_delete(dev);
 }
 
 FIXTURE(tun)
-- 
2.49.0


  parent reply	other threads:[~2026-01-05  3:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05  3:44 [PATCH net-next v3 0/8] selftest: Extend tun/virtio coverage for GSO over UDP tunnel Xu Du
2026-01-05  3:44 ` [PATCH net-next v3 1/8] selftest: tun: Format tun.c existing code Xu Du
2026-01-05  3:44 ` [PATCH net-next v3 2/8] selftest: tun: Introduce tuntap_helpers.h header for TUN/TAP testing Xu Du
2026-01-05  3:44 ` Xu Du [this message]
2026-01-05  3:44 ` [PATCH net-next v3 4/8] selftest: tap: Refactor tap test to use tuntap_helpers Xu Du
2026-01-05  3:44 ` [PATCH net-next v3 5/8] selftest: tun: Add helpers for GSO over UDP tunnel Xu Du
2026-01-05  3:44 ` [PATCH net-next v3 6/8] selftest: tun: Add test for sending gso packet into tun Xu Du
2026-01-05  3:44 ` [PATCH net-next v3 7/8] selftest: tun: Add test for receiving gso packet from tun Xu Du
2026-01-05  3:44 ` [PATCH net-next v3 8/8] selftest: tun: Add test data for success and failure paths Xu Du
2026-01-06  1:36 ` [PATCH net-next v3 0/8] selftest: Extend tun/virtio coverage for GSO over UDP tunnel Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=832ffbf4ec570342e29c75a02457e3f4e2beb14a.1767580224.git.xudu@redhat.com \
    --to=xudu@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox