| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if.c,v 1.406 2017/12/06 09:54:47 ozaki-r Exp $ */ | | 1 | /* $NetBSD: if.c,v 1.407 2017/12/07 01:23:53 ozaki-r 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.406 2017/12/06 09:54:47 ozaki-r Exp $"); | | 93 | __KERNEL_RCSID(0, "$NetBSD: if.c,v 1.407 2017/12/07 01:23:53 ozaki-r 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 | | | 98 | |
99 | #include "opt_atalk.h" | | 99 | #include "opt_atalk.h" |
100 | #include "opt_natm.h" | | 100 | #include "opt_natm.h" |
101 | #include "opt_wlan.h" | | 101 | #include "opt_wlan.h" |
102 | #include "opt_net_mpsafe.h" | | 102 | #include "opt_net_mpsafe.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> |
| @@ -1368,29 +1368,31 @@ if_detach(struct ifnet *ifp) | | | @@ -1368,29 +1368,31 @@ if_detach(struct ifnet *ifp) |
1368 | * | | 1368 | * |
1369 | * pr_usrreq calls can remove an arbitrary number of ifaddrs | | 1369 | * pr_usrreq calls can remove an arbitrary number of ifaddrs |
1370 | * from the list, including our "cursor", ifa. For safety, | | 1370 | * from the list, including our "cursor", ifa. For safety, |
1371 | * and to honor the TAILQ abstraction, I just restart the | | 1371 | * and to honor the TAILQ abstraction, I just restart the |
1372 | * loop after each removal. Note that the loop will exit | | 1372 | * loop after each removal. Note that the loop will exit |
1373 | * when all of the remaining ifaddrs belong to the AF_LINK | | 1373 | * when all of the remaining ifaddrs belong to the AF_LINK |
1374 | * family. I am counting on the historical fact that at | | 1374 | * family. I am counting on the historical fact that at |
1375 | * least one pr_usrreq in each address domain removes at | | 1375 | * least one pr_usrreq in each address domain removes at |
1376 | * least one ifaddr. | | 1376 | * least one ifaddr. |
1377 | */ | | 1377 | */ |
1378 | again: | | 1378 | again: |
1379 | /* | | 1379 | /* |
1380 | * At this point, no other one tries to remove ifa in the list, | | 1380 | * At this point, no other one tries to remove ifa in the list, |
1381 | * so we don't need to take a lock or psref. | | 1381 | * so we don't need to take a lock or psref. Avoid using |
| | | 1382 | * IFADDR_READER_FOREACH to pass over an inspection of contract |
| | | 1383 | * violations of pserialize. |
1382 | */ | | 1384 | */ |
1383 | IFADDR_READER_FOREACH(ifa, ifp) { | | 1385 | IFADDR_WRITER_FOREACH(ifa, ifp) { |
1384 | family = ifa->ifa_addr->sa_family; | | 1386 | family = ifa->ifa_addr->sa_family; |
1385 | #ifdef IFAREF_DEBUG | | 1387 | #ifdef IFAREF_DEBUG |
1386 | printf("if_detach: ifaddr %p, family %d, refcnt %d\n", | | 1388 | printf("if_detach: ifaddr %p, family %d, refcnt %d\n", |
1387 | ifa, family, ifa->ifa_refcnt); | | 1389 | ifa, family, ifa->ifa_refcnt); |
1388 | if (last_ifa != NULL && ifa == last_ifa) | | 1390 | if (last_ifa != NULL && ifa == last_ifa) |
1389 | panic("if_detach: loop detected"); | | 1391 | panic("if_detach: loop detected"); |
1390 | last_ifa = ifa; | | 1392 | last_ifa = ifa; |
1391 | #endif | | 1393 | #endif |
1392 | if (family == AF_LINK) | | 1394 | if (family == AF_LINK) |
1393 | continue; | | 1395 | continue; |
1394 | dp = pffinddomain(family); | | 1396 | dp = pffinddomain(family); |
1395 | KASSERTMSG(dp != NULL, "no domain for AF %d", family); | | 1397 | KASSERTMSG(dp != NULL, "no domain for AF %d", family); |
1396 | /* | | 1398 | /* |