diff mbox series

[net-next,v3] net: tuntap: add ioctl() TUNGETQUEUEINDEX to fetch queue index

Message ID 20240807190236.136388-1-ayaka@soulik.info (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v3] net: tuntap: add ioctl() TUNGETQUEUEINDEX to fetch queue index | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 29 this patch: 29
netdev/build_tools success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 29 this patch: 29
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 30 this patch: 30
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 42 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-08--03-00 (tests: 705)

Commit Message

ayaka Aug. 7, 2024, 7:02 p.m. UTC
We need the queue index in qdisc mapping rule and the result
value for the steering eBPF.
There was no way to know that.

Changelog:
v3:
fixes two style issues in the previous commit
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(+)

Comments

Willem de Bruijn Aug. 8, 2024, 2:16 a.m. UTC | #1
On Wed, Aug 7, 2024 at 3:02 PM Randy Li <ayaka@soulik.info> wrote:
>
> We need the queue index in qdisc mapping rule and the result
> value for the steering eBPF.
> There was no way to know that.

This commit message is very short.

There's an ongoing conversation in v2 on whether this feature is
needed, given that tc and tun already have a variety of ways to both
drop and steer traffic.

So a bit too soon for a v3.

The big question that the commit message should answer is why this
feature is needed given the alternatives. Essentially, in v4 please
include the short conclusion of the discussion.

Also add a Link: to the full discussion on lore.

> Changelog:
> v3:
> fixes two style issues in the previous commit
> 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..0c527ccdeab3 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
>
diff mbox series

Patch

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..0c527ccdeab3 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