Wed Apr 17 18:52:39 2024 UTC (22d)
tap(4): Use DETACH_FORCE with config_detach.

It doesn't make a difference here, because tap_detach never fails,
but let's make it more obvious at the call site that failure is
forbidden here.

No functional change intended.

PR kern/58166


(riastradh)
diff -r1.130 -r1.131 src/sys/net/if_tap.c

cvs diff -r1.130 -r1.131 src/sys/net/if_tap.c (expand / switch to unified diff)

--- src/sys/net/if_tap.c 2024/04/17 18:52:25 1.130
+++ src/sys/net/if_tap.c 2024/04/17 18:52:39 1.131
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_tap.c,v 1.130 2024/04/17 18:52:25 riastradh Exp $ */ 1/* $NetBSD: if_tap.c,v 1.131 2024/04/17 18:52:39 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation. 4 * Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * tap(4) is a virtual Ethernet interface. It appears as a real Ethernet 30 * tap(4) is a virtual Ethernet interface. It appears as a real Ethernet
31 * device to the system, but can also be accessed by userland through a 31 * device to the system, but can also be accessed by userland through a
32 * character device interface, which allows reading and injecting frames. 32 * character device interface, which allows reading and injecting frames.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.130 2024/04/17 18:52:25 riastradh Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.131 2024/04/17 18:52:39 riastradh Exp $");
37 37
38#if defined(_KERNEL_OPT) 38#if defined(_KERNEL_OPT)
39 39
40#include "opt_modular.h" 40#include "opt_modular.h"
41#endif 41#endif
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/atomic.h> 44#include <sys/atomic.h>
45#include <sys/conf.h> 45#include <sys/conf.h>
46#include <sys/cprng.h> 46#include <sys/cprng.h>
47#include <sys/device.h> 47#include <sys/device.h>
48#include <sys/file.h> 48#include <sys/file.h>
49#include <sys/filedesc.h> 49#include <sys/filedesc.h>
@@ -631,27 +631,27 @@ tap_clone_destroy(struct ifnet *ifp) @@ -631,27 +631,27 @@ tap_clone_destroy(struct ifnet *ifp)
631 struct tap_softc *sc = ifp->if_softc; 631 struct tap_softc *sc = ifp->if_softc;
632 632
633 tap_clone_destroyer(sc->sc_dev); 633 tap_clone_destroyer(sc->sc_dev);
634 atomic_dec_uint(&tap_count); 634 atomic_dec_uint(&tap_count);
635 return 0; 635 return 0;
636} 636}
637 637
638static void 638static void
639tap_clone_destroyer(device_t dev) 639tap_clone_destroyer(device_t dev)
640{ 640{
641 cfdata_t cf = device_cfdata(dev); 641 cfdata_t cf = device_cfdata(dev);
642 int error; 642 int error;
643 643
644 error = config_detach(dev, 0); 644 error = config_detach(dev, DETACH_FORCE);
645 KASSERTMSG(error == 0, "error=%d", error); 645 KASSERTMSG(error == 0, "error=%d", error);
646 kmem_free(cf, sizeof(*cf)); 646 kmem_free(cf, sizeof(*cf));
647} 647}
648 648
649/* 649/*
650 * tap(4) is a bit of an hybrid device. It can be used in two different 650 * tap(4) is a bit of an hybrid device. It can be used in two different
651 * ways: 651 * ways:
652 * 1. ifconfig tapN create, then use /dev/tapN to read/write off it. 652 * 1. ifconfig tapN create, then use /dev/tapN to read/write off it.
653 * 2. open /dev/tap, get a new interface created and read/write off it. 653 * 2. open /dev/tap, get a new interface created and read/write off it.
654 * That interface is destroyed when the process that had it created exits. 654 * That interface is destroyed when the process that had it created exits.
655 * 655 *
656 * The first way is managed by the cdevsw structure, and you access interfaces 656 * The first way is managed by the cdevsw structure, and you access interfaces
657 * through a (major, minor) mapping: tap4 is obtained by the minor number 657 * through a (major, minor) mapping: tap4 is obtained by the minor number