From nobody Sun Feb 8 10:49:21 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD94C258EFF for ; Mon, 19 Jan 2026 05:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768801255; cv=none; b=mcpcuuYizikqWS+wQSWGcCwNUGOkyVVfQvjnlPt4HYkcpHlk9u1Hao6VKErb0irgBEjB+GuRUbHYwqPgEnBI2QHIw3JHVohD5KKJGJkfJF/CZdSZHfDQACIR1gujo8oE7saOcrl+KHqO7w677QbwXJuURjmz/CTUjSXGRsVdjzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768801255; c=relaxed/simple; bh=YAvQxpdgt1WKlRFO7jvB0fVvQE9KxlMsOksUbfY7JkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hs73lME5adwl7yf8JF3Y94Vp4TbBeZgfYLpxAw2jtzMd5jFvMvKnQkD3NsIQlfMRyLkWghIcO5919nP9v8VV0f/wr7fdYLYOBQQZ+GWVMgsB5QYPoDibsGzVWBucwiZ7mV9F4NOJ95EnxPwYVVSAN70OvWQoWpLTc1Rc+NE6Fco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SMKI6WUV; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SMKI6WUV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768801251; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TSymtOAz4BKjHE60zeB8jOJnB2lXibwng+Q6/NjtkGw=; b=SMKI6WUVW0gk90wiQuEXPW2fMA0O6pgF+L1Py4ZlabUUNV4hqJAB+LcYcnBCP6rMcuOlLD fkovL8GzAmNB6XV74fzOqbWYdkZ181alyaK5RFrvxcxggQSd+IQEubBn8xPu3yHVN3g8Zr efq0XzyeL3lkzRmQSjlEoszkPNey6c4= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-106-jK19atPxOFq02Fkrudv-UA-1; Mon, 19 Jan 2026 00:40:46 -0500 X-MC-Unique: jK19atPxOFq02Fkrudv-UA-1 X-Mimecast-MFC-AGG-ID: jK19atPxOFq02Fkrudv-UA_1768801245 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D21EA1800350; Mon, 19 Jan 2026 05:40:44 +0000 (UTC) Received: from xudu-thinkpadx1carbongen9.nay.csb (unknown [10.72.116.28]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4261818004D8; Mon, 19 Jan 2026 05:40:38 +0000 (UTC) From: Xu Du 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 v5 3/7] selftest: tun: Refactor tun_delete to use tuntap_helpers Date: Mon, 19 Jan 2026 13:40:00 +0800 Message-ID: <58c5767a8a82352fb784d8d51ec844055b6d7ff2.1768800198.git.xudu@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" 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 --- v4 -> v5: - Delete device using the new ip link YNL API. - Linked YNL library to the tun program. tools/testing/selftests/net/Makefile | 7 ++--- tools/testing/selftests/net/tun.c | 39 ++-------------------------- 2 files changed, 6 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests= /net/Makefile index b66ba04f19d9..64e941e6a88f 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -180,7 +180,6 @@ TEST_GEN_PROGS :=3D \ tap \ tcp_port_share \ tls \ - tun \ # end of TEST_GEN_PROGS =20 TEST_FILES :=3D \ @@ -192,7 +191,9 @@ TEST_FILES :=3D \ =20 # YNL files, must be before "include ..lib.mk" YNL_GEN_FILES :=3D busy_poller -YNL_GEN_PROGS :=3D netlink-dumps +YNL_GEN_PROGS :=3D \ + netlink-dumps \ + tun \ TEST_GEN_FILES +=3D $(YNL_GEN_FILES) TEST_GEN_PROGS +=3D $(YNL_GEN_PROGS) =20 @@ -203,7 +204,7 @@ TEST_INCLUDES :=3D forwarding/lib.sh include ../lib.mk =20 # YNL build -YNL_GENS :=3D netdev +YNL_GENS :=3D netdev rt-route rt-addr rt-neigh rt-link include ynl.mk =20 $(OUTPUT)/epoll_busy_poll: LDLIBS +=3D -lcap diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/ne= t/tun.c index 128b0a5327d4..d9030bdd2e06 100644 --- a/tools/testing/selftests/net/tun.c +++ b/tools/testing/selftests/net/tun.c @@ -8,14 +8,12 @@ #include #include #include -#include #include -#include -#include #include #include =20 #include "kselftest_harness.h" +#include "tuntap_helpers.h" =20 static int tun_attach(int fd, char *dev) { @@ -66,40 +64,7 @@ static int tun_alloc(char *dev) =20 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 =3D 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 =3D NLMSG_ALIGN(NLMSG_LENGTH(sizeof(req.ifm))); - req.nh.nlmsg_flags =3D NLM_F_REQUEST; - req.nh.nlmsg_type =3D RTM_DELLINK; - - req.ifm.ifi_family =3D AF_UNSPEC; - - rta =3D (struct rtattr *)(((char *)&req) + NLMSG_ALIGN(req.nh.nlmsg_len)); - rta->rta_type =3D IFLA_IFNAME; - rta->rta_len =3D RTA_LENGTH(IFNAMSIZ); - req.nh.nlmsg_len +=3D rta->rta_len; - memcpy(RTA_DATA(rta), dev, IFNAMSIZ); - - ret =3D send(rtnl, &req, req.nh.nlmsg_len, 0); - if (ret < 0) - fprintf(stderr, "can't send: %s\n", strerror(errno)); - ret =3D (unsigned int)ret !=3D req.nh.nlmsg_len; - - close(rtnl); - return ret; + return ip_link_del(dev); } =20 FIXTURE(tun) --=20 2.49.0