]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
MFC tun/tap merge: r347241, r347394, r347404, r347483, r351220, r351229,
authorKyle Evans <kevans@FreeBSD.org>
Fri, 25 Oct 2019 01:10:08 +0000 (01:10 +0000)
committerKyle Evans <kevans@FreeBSD.org>
Fri, 25 Oct 2019 01:10:08 +0000 (01:10 +0000)
commitc19053e4c701a49395e59226d3e447fe03a4389f
tree4d55aa56320d168693c517c15f1e2b8ab8700b6f
parent7f647351455158790760129eb817342901352a37
MFC tun/tap merge: r347241, r347394, r347404, r347483, r351220, r351229,
r352148, r353056-r353057, r353781-r353782, r353785-r353786, r353877

Note: A little more than just the tun/tap merge has been MFC'd to ease
auditing correctness/differences, as some later commits were cherry-picked
back to tun+tap.

r347241:
tun/tap: merge and rename to `tuntap`

tun(4) and tap(4) share the same general management interface and have a lot
in common. Bugs exist in tap(4) that have been fixed in tun(4), and
vice-versa. Let's reduce the maintenance requirements by merging them
together and using flags to differentiate between the three interface types
(tun, tap, vmnet).

This fixes a couple of tap(4)/vmnet(4) issues right out of the gate:
- tap devices may no longer be destroyed while they're open [0]
- VIMAGE issues already addressed in tun by kp

[0] emaste had removed an easy-panic-button in r240938 due to devdrn
blocking. A naive glance over this leads me to believe that this isn't quite
complete -- destroy_devl will only block while executing d_* functions, but
doesn't block the device from being destroyed while a process has it open.
The latter is the intent of the condvar in tun, so this is "fixed" (for
certain definitions of the word -- it wasn't really broken in tap, it just
wasn't quite ideal).

ifconfig(8) also grew the ability to map an interface name to a kld, so
that `ifconfig {tun,tap}0` can continue to autoload the correct module, and
`ifconfig vmnet0 create` will now autoload the correct module. This is a
low overhead addition.

r347394:
tuntap: Properly detach tap ifp

r347404:
tuntap: Don't down tap interfaces if LINK0 is set

r347483:
tuntap: Improve style

No functional change.

tun_flags of the tuntap_driver was renamed to ident_flags to reflect the
fact that it's a subset of the tun_flags that identifies a tuntap device.
This maps more easily (visually) to the TUN_DRIVER_IDENT_MASK that masks off
the bits of tun_flags that are applicable to tuntap driver ident. This is a
purely cosmetic change.

r351220:
if_tuntap: minor improvements

Rewrite a loop to avoid duplicating the exit condition.
Simplify mask processing in tunpoll().
Fix minor typos.

r351229:
tuntap: belatedly add MODULE_VERSION for if_tun and if_tap

When tun/tap were merged, appropriate MODULE_VERSION should have been added
for things like modfind(2) to continue to do the right thing with the old
names.

r352148:
Remove empty tap/tun modules directories after r347241

r353056:
if_tuntap: add a busy/unbusy mechanism, replace destroy OPEN check

A future commit will create device aliases when a tuntap device is renamed
so that it's still easily found in /dev after the rename.  Said mechanism
will want to keep the tun alive long enough to either realize that it's
about to go away or complete the alias creation, even if the alias is about
to get destroyed.

While we're introducing it, using it to prevent open devices from going away
makes plenty of sense and keeps the logic on waking up tun_destroy clean, so
we don't have multiple places trying to cv_broadcast unless it's still in
use elsewhere.

r353057:
if_tuntap: create /dev aliases when a tuntap device gets renamed

Currently, if you do:

$ ifconfig tun0 create
$ ifconfig tun0 name wg0
$ ls -l /dev | egrep 'wg|tun'

You will see tun0, but no wg0. In fact, it's slightly more annoying to make
the association between the new name and the old name in order to open the
device (if it hadn't been opened during the rename).

Register an eventhandler for ifnet_arrival_events and catch interface
renames. We can determine if the ifnet is a tun easily enough from the
if_dname, which matches the cevsw.d_name from the associated tuntap_driver.

Some locking dance is required because renames don't require the device to
be opened, so it could go away in the middle of handling the ioctl, but as
soon as we've verified this isn't the case we can attempt to busy the tun
and either bail out if the tun device is dying, or we can proceed with the
rename.

We only create these aliases on a best-effort basis. Renaming a tun device
to "usbctl", which doesn't exist as an ifnet but does as a /dev, is clearly
not that disastrous, but we can't and won't create a /dev for that.

r353781:
tuntap(4): Drop TUN_IASET

This flag appears to have been effectively unused since introduction to
if_tun(4) -- drop it now.

r353782:
tuntap(4): break out after setting TUN_DSTADDR

This is now the only flag we set in this loop, terminate early.

r353785:
tuntap(4): Use make_dev_s to avoid si_drv1 race

This allows us to avoid some dance in tunopen for dealing with the
possibility of dev->si_drv1 being NULL as it's set prior to the devfs node
being created in all cases.

There's still the possibility that the tun device hasn't been fully
initialized, since that's done after the devfs node was created. Alleviate
this by returning ENXIO if we're not to that point of tuncreate yet.

This work is what sparked r353128, full initialization of cloned devices
w/ specified make_dev_args.

r353786:
tuntap(4): use cdevpriv w/ dtor for last close instead of d_close

cdevpriv dtors will be called when the reference count on the associated
struct file drops to 0, while d_close can be unreliable for cleaning up
state at "last close" for a number of reasons. As far as tunclose/tundtor is
concerned the difference is minimal, so make the switch.

r353877:
tuntap(4): properly declare if_tun and if_tap modules

Simply adding MODULE_VERSION does not do the trick, because the modules
haven't been declared. This should actually fix modfind/kldstat, which
r351229 aimed and failed to do.

This should make vm-bhyve do the right thing again when using the ports
version, rather than the latest version not in ports.

Relnotes: yes
34 files changed:
UPDATING
sbin/ifconfig/ifconfig.c
share/man/man4/tap.4
share/man/man4/tun.4
sys/amd64/conf/GENERIC
sys/amd64/conf/MINIMAL
sys/arm/conf/DOCKSTAR
sys/arm/conf/DREAMPLUG-1001
sys/arm/conf/EFIKA_MX
sys/arm/conf/IMX53
sys/arm/conf/IMX6
sys/arm/conf/TEGRA124
sys/arm64/conf/GENERIC
sys/conf/NOTES
sys/conf/files
sys/i386/conf/GENERIC
sys/mips/conf/ERL
sys/mips/conf/OCTEON1
sys/modules/Makefile
sys/modules/if_tap/Makefile [deleted file]
sys/modules/if_tun/Makefile [deleted file]
sys/modules/if_tuntap/Makefile [new file with mode: 0644]
sys/net/if_tap.c [deleted file]
sys/net/if_tap.h
sys/net/if_tapvar.h [deleted file]
sys/net/if_tun.c [deleted file]
sys/net/if_tuntap.c [new file with mode: 0644]
sys/powerpc/conf/GENERIC
sys/powerpc/conf/GENERIC64
sys/powerpc/conf/MPC85XX
sys/powerpc/conf/MPC85XXSPE
sys/powerpc/conf/QORIQ64
sys/riscv/conf/GENERIC
sys/sparc64/conf/GENERIC