aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorMasatake YAMATO <yamato@redhat.com>2014-01-29 02:43:31 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-29 02:46:56 -0500
commit93e14b6d776e850a371fe4234a06088f210d8651 (patch)
tree18422336d2b25bc595dfea498d553e0d71ae3130 /drivers/net
parent52efcea59eeae9f850e544c41764954273b0912c (diff)
tun: add device name(iff) field to proc fdinfo entry
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> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/tun.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index bcf01af4b879..44c4db8450f0 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -69,6 +69,7 @@
69#include <net/netns/generic.h> 69#include <net/netns/generic.h>
70#include <net/rtnetlink.h> 70#include <net/rtnetlink.h>
71#include <net/sock.h> 71#include <net/sock.h>
72#include <linux/seq_file.h>
72 73
73#include <asm/uaccess.h> 74#include <asm/uaccess.h>
74 75
@@ -2228,6 +2229,27 @@ static int tun_chr_close(struct inode *inode, struct file *file)
2228 return 0; 2229 return 0;
2229} 2230}
2230 2231
2232#ifdef CONFIG_PROC_FS
2233static int tun_chr_show_fdinfo(struct seq_file *m, struct file *f)
2234{
2235 struct tun_struct *tun;
2236 struct ifreq ifr;
2237
2238 memset(&ifr, 0, sizeof(ifr));
2239
2240 rtnl_lock();
2241 tun = tun_get(f);
2242 if (tun)
2243 tun_get_iff(current->nsproxy->net_ns, tun, &ifr);
2244 rtnl_unlock();
2245
2246 if (tun)
2247 tun_put(tun);
2248
2249 return seq_printf(m, "iff:\t%s\n", ifr.ifr_name);
2250}
2251#endif
2252
2231static const struct file_operations tun_fops = { 2253static const struct file_operations tun_fops = {
2232 .owner = THIS_MODULE, 2254 .owner = THIS_MODULE,
2233 .llseek = no_llseek, 2255 .llseek = no_llseek,
@@ -2242,7 +2264,10 @@ static const struct file_operations tun_fops = {
2242#endif 2264#endif
2243 .open = tun_chr_open, 2265 .open = tun_chr_open,
2244 .release = tun_chr_close, 2266 .release = tun_chr_close,
2245 .fasync = tun_chr_fasync 2267 .fasync = tun_chr_fasync,
2268#ifdef CONFIG_PROC_FS
2269 .show_fdinfo = tun_chr_show_fdinfo,
2270#endif
2246}; 2271};
2247 2272
2248static struct miscdevice tun_miscdev = { 2273static struct miscdevice tun_miscdev = {