* [PATCH] tun: add device name(iff) field to proc fdinfo entry
@ 2014-01-28 16:54 Masatake YAMATO
2014-01-29 2:08 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Masatake YAMATO @ 2014-01-28 16:54 UTC (permalink / raw)
To: netdev; +Cc: yamato
A file descriptor opened for /dev/net/tun and a tun device are
connected with ioctl. Though understanding the connection is
important for trouble shooting, no way is given to a user to know
the connected device for a given file descriptor at userland.
This patch adds a new fdinfo field for the device name connected to
a file descriptor opened for /dev/net/tun.
Here is an example of the field:
# lsof | grep tun
qemu-syst 4565 qemu 25u CHR 10,200 0t138 12921 /dev/net/tun
...
# cat /proc/4565/fdinfo/25
pos: 138
flags: 0104002
iff: vnet0
# ip link show dev vnet0
8: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
drivers/net/tun.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index bcf01af..f0a1e1d 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -69,6 +69,7 @@
#include <net/netns/generic.h>
#include <net/rtnetlink.h>
#include <net/sock.h>
+#include <linux/seq_file.h>
#include <asm/uaccess.h>
@@ -2228,6 +2229,28 @@ static int tun_chr_close(struct inode *inode, struct file *file)
return 0;
}
+#ifdef CONFIG_PROC_FS
+static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
+{
+ struct tun_struct *tun;
+ struct ifreq ifr;
+ int ret;
+
+ memset(&ifr, 0, sizeof(ifr));
+
+ rtnl_lock();
+ tun = tun_get(f);
+ if (tun)
+ tun_get_iff(current->nsproxy->net_ns, tun, &ifr);
+ rtnl_unlock();
+
+ if (tun)
+ tun_put(tun);
+
+ return seq_printf(m, "iff: %s\n", ifr.ifr_name);
+}
+#endif
+
static const struct file_operations tun_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
@@ -2242,7 +2265,10 @@ static const struct file_operations tun_fops = {
#endif
.open = tun_chr_open,
.release = tun_chr_close,
- .fasync = tun_chr_fasync
+ .fasync = tun_chr_fasync,
+#ifdef CONFIG_PROC_FS
+ .show_fdinfo = tun_chr_show_fdinfo,
+#endif
};
static struct miscdevice tun_miscdev = {
--
1.8.5.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] tun: add device name(iff) field to proc fdinfo entry
2014-01-28 16:54 [PATCH] tun: add device name(iff) field to proc fdinfo entry Masatake YAMATO
@ 2014-01-29 2:08 ` David Miller
2014-01-29 5:33 ` [PATCH v2] " Masatake YAMATO
0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2014-01-29 2:08 UTC (permalink / raw)
To: yamato; +Cc: netdev
From: Masatake YAMATO <yamato@redhat.com>
Date: Wed, 29 Jan 2014 01:54:11 +0900
> # cat /proc/4565/fdinfo/25
> pos: 138
> flags: 0104002
> iff: vnet0
Please properly indent iff just like the other fdinfo fields
are.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] tun: add device name(iff) field to proc fdinfo entry
2014-01-29 2:08 ` David Miller
@ 2014-01-29 5:33 ` Masatake YAMATO
2014-01-29 7:19 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Masatake YAMATO @ 2014-01-29 5:33 UTC (permalink / raw)
To: davem; +Cc: netdev, yamato
A file descriptor opened for /dev/net/tun and a tun device are
connected with ioctl. Though understanding the connection is
important for trouble shooting, no way is given to a user to know
the connected device for a given file descriptor at userland.
This patch adds a new fdinfo field for the device name connected to
a file descriptor opened for /dev/net/tun.
Here is an example of the field:
# lsof | grep tun
qemu-syst 4565 qemu 25u CHR 10,200 0t138 12921 /dev/net/tun
...
# cat /proc/4565/fdinfo/25
pos: 138
flags: 0104002
iff: vnet0
# ip link show dev vnet0
8: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
changelog:
(v2): indent iff just like the other fdinfo fields are.
Suggested by David Miller <davem@davemloft.net>.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
drivers/net/tun.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index bcf01af..8651c31 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -69,6 +69,7 @@
#include <net/netns/generic.h>
#include <net/rtnetlink.h>
#include <net/sock.h>
+#include <linux/seq_file.h>
#include <asm/uaccess.h>
@@ -2228,6 +2229,28 @@ static int tun_chr_close(struct inode *inode, struct file *file)
return 0;
}
+#ifdef CONFIG_PROC_FS
+static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
+{
+ struct tun_struct *tun;
+ struct ifreq ifr;
+ int ret;
+
+ memset(&ifr, 0, sizeof(ifr));
+
+ rtnl_lock();
+ tun = tun_get(f);
+ if (tun)
+ tun_get_iff(current->nsproxy->net_ns, tun, &ifr);
+ rtnl_unlock();
+
+ if (tun)
+ tun_put(tun);
+
+ return seq_printf(m, "iff:\t%s\n", ifr.ifr_name);
+}
+#endif
+
static const struct file_operations tun_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
@@ -2242,7 +2265,10 @@ static const struct file_operations tun_fops = {
#endif
.open = tun_chr_open,
.release = tun_chr_close,
- .fasync = tun_chr_fasync
+ .fasync = tun_chr_fasync,
+#ifdef CONFIG_PROC_FS
+ .show_fdinfo = tun_chr_show_fdinfo,
+#endif
};
static struct miscdevice tun_miscdev = {
--
1.8.5.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2] tun: add device name(iff) field to proc fdinfo entry
2014-01-29 5:33 ` [PATCH v2] " Masatake YAMATO
@ 2014-01-29 7:19 ` David Miller
2014-01-29 7:43 ` [PATCH v3] " Masatake YAMATO
0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2014-01-29 7:19 UTC (permalink / raw)
To: yamato; +Cc: netdev
From: Masatake YAMATO <yamato@redhat.com>
Date: Wed, 29 Jan 2014 14:33:34 +0900
> (v2): indent iff just like the other fdinfo fields are.
> Suggested by David Miller <davem@davemloft.net>.
Please fix the build warnings generated by your changes:
drivers/net/tun.c: In function ‘tun_chr_show_fdinfo’:
drivers/net/tun.c:2237:6: warning: unused variable ‘ret’ [-Wunused-variable]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3] tun: add device name(iff) field to proc fdinfo entry
2014-01-29 7:19 ` David Miller
@ 2014-01-29 7:43 ` Masatake YAMATO
2014-01-29 7:47 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Masatake YAMATO @ 2014-01-29 7:43 UTC (permalink / raw)
To: davem; +Cc: netdev, yamato
A file descriptor opened for /dev/net/tun and a tun device are
connected with ioctl. Though understanding the connection is
important for trouble shooting, no way is given to a user to know
the connected device for a given file descriptor at userland.
This patch adds a new fdinfo field for the device name connected to
a file descriptor opened for /dev/net/tun.
Here is an example of the field:
# lsof | grep tun
qemu-syst 4565 qemu 25u CHR 10,200 0t138 12921 /dev/net/tun
...
# cat /proc/4565/fdinfo/25
pos: 138
flags: 0104002
iff: vnet0
# ip link show dev vnet0
8: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
changelog:
v2: indent iff just like the other fdinfo fields are.
v3: remove unused variable.
Both are suggested by David Miller <davem@davemloft.net>.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
drivers/net/tun.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index bcf01af..44c4db8 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -69,6 +69,7 @@
#include <net/netns/generic.h>
#include <net/rtnetlink.h>
#include <net/sock.h>
+#include <linux/seq_file.h>
#include <asm/uaccess.h>
@@ -2228,6 +2229,27 @@ static int tun_chr_close(struct inode *inode, struct file *file)
return 0;
}
+#ifdef CONFIG_PROC_FS
+static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
+{
+ struct tun_struct *tun;
+ struct ifreq ifr;
+
+ memset(&ifr, 0, sizeof(ifr));
+
+ rtnl_lock();
+ tun = tun_get(f);
+ if (tun)
+ tun_get_iff(current->nsproxy->net_ns, tun, &ifr);
+ rtnl_unlock();
+
+ if (tun)
+ tun_put(tun);
+
+ return seq_printf(m, "iff:\t%s\n", ifr.ifr_name);
+}
+#endif
+
static const struct file_operations tun_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
@@ -2242,7 +2264,10 @@ static const struct file_operations tun_fops = {
#endif
.open = tun_chr_open,
.release = tun_chr_close,
- .fasync = tun_chr_fasync
+ .fasync = tun_chr_fasync,
+#ifdef CONFIG_PROC_FS
+ .show_fdinfo = tun_chr_show_fdinfo,
+#endif
};
static struct miscdevice tun_miscdev = {
--
1.8.5.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v3] tun: add device name(iff) field to proc fdinfo entry
2014-01-29 7:43 ` [PATCH v3] " Masatake YAMATO
@ 2014-01-29 7:47 ` David Miller
0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2014-01-29 7:47 UTC (permalink / raw)
To: yamato; +Cc: netdev
From: Masatake YAMATO <yamato@redhat.com>
Date: Wed, 29 Jan 2014 16:43:31 +0900
> A file descriptor opened for /dev/net/tun and a tun device are
> connected with ioctl. Though understanding the connection is
> important for trouble shooting, no way is given to a user to know
> the connected device for a given file descriptor at userland.
>
> This patch adds a new fdinfo field for the device name connected to
> a file descriptor opened for /dev/net/tun.
>
> Here is an example of the field:
...
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
This looks a lot better, applied, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-01-29 7:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-28 16:54 [PATCH] tun: add device name(iff) field to proc fdinfo entry Masatake YAMATO
2014-01-29 2:08 ` David Miller
2014-01-29 5:33 ` [PATCH v2] " Masatake YAMATO
2014-01-29 7:19 ` David Miller
2014-01-29 7:43 ` [PATCH v3] " Masatake YAMATO
2014-01-29 7:47 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox