lsfd: add TUN.DEVNETNS column
lsfd can show the name of the network device behind a file descriptor
pointing to a tun/tap device.
# lsfd -Q 'SOURCE == "misc:tun"'
COMMAND PID USER ASSOC XMODE TYPE SOURCE MNTID INODE NAME
qemu-system-x86 846384 qemu 35 rw---- CHR misc:tun 36 1145 iface=vnet21
pasta.avx2
1837933 yamato 8 rw---m CHR misc:tun 2143 1145 iface=ens8191
...
This feature helps users inspect target processes, containers, and/or
VMs with tools such as tcpdump, wireshark, or ip-link.
However, I found a case where the device name was not sufficient.
pasta (https://passt.top/) provides networking for rootless
containers. It creates a tap device whose name matches the name of a
network device on the host:
$ ip link show ens8191
5: ens8191: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
$ ethtool -i ens8191 | head -1
driver: atlantic
$ podman exec
9fbbed215871 ip link show ens8191
2: ens8191: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 65520 ...
$ podman exec
9fbbed215871 ethtool -i ens8191 | head -1
driver: tun
A name alone is not enough to identify a network device on the system.
With this change, lsfd reports the network namespace to which the
tun/tap device belongs:
# lsfd -Q 'SOURCE == "misc:tun"' -oCOMMAND,PID,SOURCE,TUN.DEVNETNS,NAME
COMMAND PID SOURCE TUN.DEVNETNS NAME
qemu-system-x86 846384 misc:tun
4026531840 iface=vnet21 devnetns=
4026531840
pasta.avx2
1837933 misc:tun
4026536354 iface=ens8191 devnetns=
4026536354
...
This change relies on the TUNGETDEVNETNS ioctl added in:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=
0c3e0e3bb623c3735b8c9ab8aa8332f944f83a9f
Signed-off-by: Masatake YAMATO <yamato@redhat.com>