Commit 93e14b6d authored by Masatake YAMATO's avatar Masatake YAMATO Committed by David S. Miller
Browse files

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


    v2: indent iff just like the other fdinfo fields are.
    v3: remove unused variable.
        Both are suggested by David Miller <>.

Signed-off-by: default avatarMasatake YAMATO <>
Signed-off-by: default avatarDavid S. Miller <>
parent 52efcea5
......@@ -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;
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));
tun = tun_get(f);
if (tun)
tun_get_iff(current->nsproxy->net_ns, tun, &ifr);
if (tun)
return seq_printf(m, "iff:\t%s\n", ifr.ifr_name);
static const struct file_operations tun_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
......@@ -2242,7 +2264,10 @@ static const struct file_operations tun_fops = {
.open = tun_chr_open,
.release = tun_chr_close,
.fasync = tun_chr_fasync
.fasync = tun_chr_fasync,
.show_fdinfo = tun_chr_show_fdinfo,
static struct miscdevice tun_miscdev = {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment