netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: tuntap: add ioctl() TUNGETQUEUEINDEX to fetch queue index
@ 2024-08-01 13:49 Randy Li
  2024-08-06 19:00 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Randy Li @ 2024-08-01 13:49 UTC (permalink / raw)
  To: netdev
  Cc: willemdebruijn.kernel, jasowang, davem, edumazet, kuba, pabeni,
	linux-kernel, Randy Li

We need the queue index in qdisc mapping rule. There is no way to
fetch that.

Changelog:
v2:
Fixes the flow when the queue is disabled in the tap type device.
Put this ioctl() under the lock protection for the tun device.

Signed-off-by: Randy Li <ayaka@soulik.info>
---
 drivers/net/tap.c           | 10 ++++++++++
 drivers/net/tun.c           | 13 +++++++++++++
 include/uapi/linux/if_tun.h |  1 +
 3 files changed, 24 insertions(+)

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 77574f7a3bd4..bbd717cf78a5 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -1120,6 +1120,16 @@ static long tap_ioctl(struct file *file, unsigned int cmd,
 		rtnl_unlock();
 		return ret;
 
+	case TUNGETQUEUEINDEX:
+		rtnl_lock();
+		if (!q->enabled)
+			ret = -EINVAL;
+		else
+			ret = put_user(q->queue_index, up);
+
+		rtnl_unlock();
+		return ret;
+
 	case SIOCGIFHWADDR:
 		rtnl_lock();
 		tap = tap_get_tap_dev(q);
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 1d06c560c5e6..05fa9727721e 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -3151,6 +3151,19 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 		tfile->ifindex = ifindex;
 		goto unlock;
 	}
+	if (cmd == TUNGETQUEUEINDEX) {
+		ret = -EINVAL;
+		if (tfile->detached)
+			goto unlock;
+
+		ret = -EFAULT;
+		if(put_user(tfile->queue_index, (unsigned int __user*)argp))
+			goto unlock;
+
+		ret = 0;
+		goto unlock;
+	}
+
 
 	ret = -EBADFD;
 	if (!tun)
diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h
index 287cdc81c939..2668ca3b06a5 100644
--- a/include/uapi/linux/if_tun.h
+++ b/include/uapi/linux/if_tun.h
@@ -61,6 +61,7 @@
 #define TUNSETFILTEREBPF _IOR('T', 225, int)
 #define TUNSETCARRIER _IOW('T', 226, int)
 #define TUNGETDEVNETNS _IO('T', 227)
+#define TUNGETQUEUEINDEX _IOR('T', 228, unsigned int)
 
 /* TUNSETIFF ifr flags */
 #define IFF_TUN		0x0001
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next v2] net: tuntap: add ioctl() TUNGETQUEUEINDEX to fetch queue index
  2024-08-01 13:49 [PATCH net-next v2] net: tuntap: add ioctl() TUNGETQUEUEINDEX to fetch queue index Randy Li
@ 2024-08-06 19:00 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2024-08-06 19:00 UTC (permalink / raw)
  To: Randy Li
  Cc: netdev, willemdebruijn.kernel, jasowang, davem, edumazet, pabeni,
	linux-kernel

On Thu,  1 Aug 2024 21:49:21 +0800 Randy Li wrote:
> +		if(put_user(tfile->queue_index, (unsigned int __user*)argp))

Checkpatch has some legitimate complains about this line:

ERROR: "(foo*)" should be "(foo *)"
#58: FILE: drivers/net/tun.c:3160:
+		if(put_user(tfile->queue_index, (unsigned int __user*)argp))

ERROR: space required before the open parenthesis '('
#58: FILE: drivers/net/tun.c:3160:
+		if(put_user(tfile->queue_index, (unsigned int __user*)argp))


Assuming Willem is okay with the feature, please add appropriate tests
in tools/testing/selftests/net/tap.c
-- 
pw-bot: cr

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-06 19:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-01 13:49 [PATCH net-next v2] net: tuntap: add ioctl() TUNGETQUEUEINDEX to fetch queue index Randy Li
2024-08-06 19:00 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).