Mon Aug 19 14:27:16 2019 UTC ()
Pull up following revision(s) (requested by ozaki-r in ticket #1339):

	sys/net/if.c: revision 1.458
	tests/net/if/t_ifconfig.sh: revision 1.21

Restore if_ioctl on error of ifc_destroy

Otherwise subsequence ioctls won't work.

Patch from Harold Gutch on PR kern/54434 (tweaked a bit by me)
tests: check if ifconfig (ioctl) works after a failure of ifconfig destroy

This is a test for PR kern/54434.


(martin)
diff -r1.394.2.16 -r1.394.2.17 src/sys/net/if.c
diff -r1.18 -r1.18.4.1 src/tests/net/if/t_ifconfig.sh

cvs diff -r1.394.2.16 -r1.394.2.17 src/sys/net/if.c (expand / switch to unified diff)

--- src/sys/net/if.c 2019/04/19 09:12:58 1.394.2.16
+++ src/sys/net/if.c 2019/08/19 14:27:16 1.394.2.17
@@ -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 */
1598static int 1598static int
1599if_clone_destroy(const char *name) 1599if_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
1632static bool 1644static bool
1633if_is_unit(const char *name) 1645if_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;

cvs diff -r1.18 -r1.18.4.1 src/tests/net/if/t_ifconfig.sh (expand / switch to unified diff)

--- src/tests/net/if/t_ifconfig.sh 2017/03/16 09:43:56 1.18
+++ src/tests/net/if/t_ifconfig.sh 2019/08/19 14:27:16 1.18.4.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: t_ifconfig.sh,v 1.18 2017/03/16 09:43:56 ozaki-r Exp $ 1# $NetBSD: t_ifconfig.sh,v 1.18.4.1 2019/08/19 14:27:16 martin Exp $
2# 2#
3# Copyright (c) 2015 The NetBSD Foundation, Inc. 3# Copyright (c) 2015 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
@@ -59,26 +59,31 @@ ifconfig_create_destroy_body() @@ -59,26 +59,31 @@ ifconfig_create_destroy_body()
59 atf_check -s exit:0 rump.ifconfig shmif0 create 59 atf_check -s exit:0 rump.ifconfig shmif0 create
60 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus 60 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
61 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1/24 61 atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1/24
62 atf_check -s exit:0 rump.ifconfig shmif0 up 62 atf_check -s exit:0 rump.ifconfig shmif0 up
63 atf_check -s exit:0 rump.ifconfig shmif0 destroy 63 atf_check -s exit:0 rump.ifconfig shmif0 destroy
64 64
65 # Create and destroy (with an IPv6 address) 65 # Create and destroy (with an IPv6 address)
66 atf_check -s exit:0 rump.ifconfig shmif0 create 66 atf_check -s exit:0 rump.ifconfig shmif0 create
67 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus 67 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
68 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1 68 atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::1
69 atf_check -s exit:0 rump.ifconfig shmif0 up 69 atf_check -s exit:0 rump.ifconfig shmif0 up
70 atf_check -s exit:0 rump.ifconfig shmif0 destroy 70 atf_check -s exit:0 rump.ifconfig shmif0 destroy
71 71
 72 # Check if ifconfig (ioctl) works after a failure of ifconfig destroy
 73 atf_check -s exit:0 -o ignore rump.ifconfig lo0
 74 atf_check -s not-exit:0 -e ignore rump.ifconfig lo0 destroy
 75 atf_check -s exit:0 -o ignore rump.ifconfig lo0
 76
72 unset RUMP_SERVER 77 unset RUMP_SERVER
73} 78}
74 79
75ifconfig_create_destroy_cleanup() 80ifconfig_create_destroy_cleanup()
76{ 81{
77 82
78 RUMP_SERVER=${RUMP_SERVER1} rump.halt 83 RUMP_SERVER=${RUMP_SERVER1} rump.halt
79} 84}
80 85
81atf_test_case ifconfig_options cleanup 86atf_test_case ifconfig_options cleanup
82ifconfig_options_head() 87ifconfig_options_head()
83{ 88{
84 89