]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lsfd: add TUN.DEVNETNS column
authorMasatake YAMATO <yamato@redhat.com>
Sun, 23 Nov 2025 07:18:48 +0000 (16:18 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sun, 23 Nov 2025 20:10:56 +0000 (05:10 +0900)
commitff2650962f09b9abef33116b9b4ecd1da2feacae
treedae10089f2ae6607acb4f5df59bf0a71077b6c30
parentaed371507cc18cd613449396aa35b3303484e2c8
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>
lsfd-cmd/cdev.c
lsfd-cmd/lsfd.1.adoc
lsfd-cmd/lsfd.c
lsfd-cmd/lsfd.h
tests/expected/lsfd/mkfds-cdev-tun-domestic [moved from tests/expected/lsfd/mkfds-cdev-tun with 100% similarity]
tests/expected/lsfd/mkfds-cdev-tun-domestic-devnetns [new file with mode: 0644]
tests/expected/lsfd/mkfds-cdev-tun-foreign [new file with mode: 0644]
tests/expected/lsfd/mkfds-cdev-tun-foreign-devnetns [new file with mode: 0644]
tests/ts/lsfd/mkfds-cdev-tun