| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if.c,v 1.394.2.16 2019/04/19 09:12:58 martin Exp $ */ | | 1 | /* $NetBSD: if.c,v 1.394.2.17 2019/08/19 14:27:16 martin Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by William Studenmund and Jason R. Thorpe. | | 8 | * by William Studenmund and Jason R. Thorpe. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -80,27 +80,27 @@ | | | @@ -80,27 +80,27 @@ |
80 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 80 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
81 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 81 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
82 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 82 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
83 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 83 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
84 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 84 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
85 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 85 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
86 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 86 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
87 | * SUCH DAMAGE. | | 87 | * SUCH DAMAGE. |
88 | * | | 88 | * |
89 | * @(#)if.c 8.5 (Berkeley) 1/9/95 | | 89 | * @(#)if.c 8.5 (Berkeley) 1/9/95 |
90 | */ | | 90 | */ |
91 | | | 91 | |
92 | #include <sys/cdefs.h> | | 92 | #include <sys/cdefs.h> |
93 | __KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.16 2019/04/19 09:12:58 martin Exp $"); | | 93 | __KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.17 2019/08/19 14:27:16 martin Exp $"); |
94 | | | 94 | |
95 | #if defined(_KERNEL_OPT) | | 95 | #if defined(_KERNEL_OPT) |
96 | #include "opt_inet.h" | | 96 | #include "opt_inet.h" |
97 | #include "opt_ipsec.h" | | 97 | #include "opt_ipsec.h" |
98 | #include "opt_atalk.h" | | 98 | #include "opt_atalk.h" |
99 | #include "opt_natm.h" | | 99 | #include "opt_natm.h" |
100 | #include "opt_wlan.h" | | 100 | #include "opt_wlan.h" |
101 | #include "opt_net_mpsafe.h" | | 101 | #include "opt_net_mpsafe.h" |
102 | #include "opt_mrouting.h" | | 102 | #include "opt_mrouting.h" |
103 | #endif | | 103 | #endif |
104 | | | 104 | |
105 | #include <sys/param.h> | | 105 | #include <sys/param.h> |
106 | #include <sys/mbuf.h> | | 106 | #include <sys/mbuf.h> |
| @@ -1591,52 +1591,64 @@ if_clone_create(const char *name) | | | @@ -1591,52 +1591,64 @@ if_clone_create(const char *name) |
1591 | | | 1591 | |
1592 | return (*ifc->ifc_create)(ifc, unit); | | 1592 | return (*ifc->ifc_create)(ifc, unit); |
1593 | } | | 1593 | } |
1594 | | | 1594 | |
1595 | /* | | 1595 | /* |
1596 | * Destroy a clone network interface. | | 1596 | * Destroy a clone network interface. |
1597 | */ | | 1597 | */ |
1598 | static int | | 1598 | static int |
1599 | if_clone_destroy(const char *name) | | 1599 | if_clone_destroy(const char *name) |
1600 | { | | 1600 | { |
1601 | struct if_clone *ifc; | | 1601 | struct if_clone *ifc; |
1602 | struct ifnet *ifp; | | 1602 | struct ifnet *ifp; |
1603 | struct psref psref; | | 1603 | struct psref psref; |
| | | 1604 | int error; |
| | | 1605 | int (*if_ioctl)(struct ifnet *, u_long, void *); |
1604 | | | 1606 | |
1605 | KASSERT(mutex_owned(&if_clone_mtx)); | | 1607 | KASSERT(mutex_owned(&if_clone_mtx)); |
1606 | | | 1608 | |
1607 | ifc = if_clone_lookup(name, NULL); | | 1609 | ifc = if_clone_lookup(name, NULL); |
1608 | if (ifc == NULL) | | 1610 | if (ifc == NULL) |
1609 | return EINVAL; | | 1611 | return EINVAL; |
1610 | | | 1612 | |
1611 | if (ifc->ifc_destroy == NULL) | | 1613 | if (ifc->ifc_destroy == NULL) |
1612 | return EOPNOTSUPP; | | 1614 | return EOPNOTSUPP; |
1613 | | | 1615 | |
1614 | ifp = if_get(name, &psref); | | 1616 | ifp = if_get(name, &psref); |
1615 | if (ifp == NULL) | | 1617 | if (ifp == NULL) |
1616 | return ENXIO; | | 1618 | return ENXIO; |
1617 | | | 1619 | |
1618 | /* We have to disable ioctls here */ | | 1620 | /* We have to disable ioctls here */ |
1619 | IFNET_LOCK(ifp); | | 1621 | IFNET_LOCK(ifp); |
| | | 1622 | if_ioctl = ifp->if_ioctl; |
1620 | ifp->if_ioctl = if_nullioctl; | | 1623 | ifp->if_ioctl = if_nullioctl; |
1621 | IFNET_UNLOCK(ifp); | | 1624 | IFNET_UNLOCK(ifp); |
1622 | | | 1625 | |
1623 | /* | | 1626 | /* |
1624 | * We cannot call ifc_destroy with holding ifp. | | 1627 | * We cannot call ifc_destroy with holding ifp. |
1625 | * Releasing ifp here is safe thanks to if_clone_mtx. | | 1628 | * Releasing ifp here is safe thanks to if_clone_mtx. |
1626 | */ | | 1629 | */ |
1627 | if_put(ifp, &psref); | | 1630 | if_put(ifp, &psref); |
1628 | | | 1631 | |
1629 | return (*ifc->ifc_destroy)(ifp); | | 1632 | error = (*ifc->ifc_destroy)(ifp); |
| | | 1633 | |
| | | 1634 | if (error != 0) { |
| | | 1635 | /* We have to restore if_ioctl on error */ |
| | | 1636 | IFNET_LOCK(ifp); |
| | | 1637 | ifp->if_ioctl = if_ioctl; |
| | | 1638 | IFNET_UNLOCK(ifp); |
| | | 1639 | } |
| | | 1640 | |
| | | 1641 | return error; |
1630 | } | | 1642 | } |
1631 | | | 1643 | |
1632 | static bool | | 1644 | static bool |
1633 | if_is_unit(const char *name) | | 1645 | if_is_unit(const char *name) |
1634 | { | | 1646 | { |
1635 | | | 1647 | |
1636 | while(*name != '\0') { | | 1648 | while(*name != '\0') { |
1637 | if (*name < '0' || *name > '9') | | 1649 | if (*name < '0' || *name > '9') |
1638 | return false; | | 1650 | return false; |
1639 | name++; | | 1651 | name++; |
1640 | } | | 1652 | } |
1641 | | | 1653 | |
1642 | return true; | | 1654 | return true; |