From nobody Sat Feb 7 06:21:11 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 3A874481ABF for ; Wed, 21 Jan 2026 10:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768989933; cv=none; b=SE0x5pDCjJr6JVVvbK5wge/1ZxBe1w/ZsKvaUNnpNlvt2Q5Yl5PQgTdgvtWy8HY4REk/WmHrVEorPszYyQehBVW6Q5rJpGHV4HnVPbZyzCs4dWeTbY72mE8ZSy6Wzacb7DCN/LmZFPA6jX4F5Y66WL026AXySNMichEiRnxyLkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768989933; c=relaxed/simple; bh=n+m2VuVXUv3lxLyuNjmRYwc0S4tL9Oik60u26VWwd3Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jLfeie41uv3NKmG0GshwO8NjkM9kUID4VgYFy7Svw1+XmxLijajOjESII6tkK7gzIVRxE8Z4HuCOn9IZmdzLrOwYyMayReAsxxsSKI7a5ihkVzSBpyc/aSY5aXXqgbtdh2idCfcv8KQ6l2C9+Qsk8eqps/tdbyYHAASdbuNGlAQ= 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=jAQkP8/A; arc=none smtp.client-ip=170.10.129.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="jAQkP8/A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768989931; 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=E5aWAKuKoeXw5s3C5RFqgR1rdzlyWibIsmBE/Run9AQ=; b=jAQkP8/Alqm0EwwI1V459/W/kpojGnLCuuvje8fjBp67pg5ZcYZ+hTDqOBo0Dq7AnAp3FB n4YqP6pQW5yyafDp+IY8p3JMh0V8ONeAarLf1aBA5//QlrVrR1DC+Di2CUBM71YUhcogJT iT2EBqSmlIZbPA8vG6iVr44+6PEVk3k= 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-625-FuuvoICMMge7RG5MmyPsXQ-1; Wed, 21 Jan 2026 05:05:28 -0500 X-MC-Unique: FuuvoICMMge7RG5MmyPsXQ-1 X-Mimecast-MFC-AGG-ID: FuuvoICMMge7RG5MmyPsXQ_1768989926 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 84A2818002C3; Wed, 21 Jan 2026 10:05:26 +0000 (UTC) Received: from xudu-thinkpadx1carbongen9.nay.csb (unknown [10.72.116.124]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 53D781800995; Wed, 21 Jan 2026 10:05:21 +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 v6 3/7] selftest: tun: Refactor tun_delete to use tuntap_helpers Date: Wed, 21 Jan 2026 18:04:57 +0800 Message-ID: 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 --- v5 -> v6: - Fix the Makefile format errors. v4 -> v5: - Delete device using the new ip link YNL API. - Linked YNL library to the tun program. tools/testing/selftests/net/Makefile | 16 +++++++++--- tools/testing/selftests/net/tun.c | 39 ++-------------------------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests= /net/Makefile index b66ba04f19d9..11a5f5ab514f 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,11 @@ 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 \ +# end of YNL_GEN_PROGS + TEST_GEN_FILES +=3D $(YNL_GEN_FILES) TEST_GEN_PROGS +=3D $(YNL_GEN_PROGS) =20 @@ -203,7 +206,14 @@ TEST_INCLUDES :=3D forwarding/lib.sh include ../lib.mk =20 # YNL build -YNL_GENS :=3D netdev +YNL_GENS :=3D \ + netdev \ + rt-addr \ + rt-link \ + rt-neigh \ + rt-route \ +# end of YNL_GENS + 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.52.0