Pull up following revision(s) (requested by ozaki-r in ticket #456): sys/arch/arm/sunxi/sunxi_emac.c: 1.9 sys/dev/ic/dwc_gmac.c: 1.43-1.44 sys/dev/pci/if_iwm.c: 1.75 sys/dev/pci/if_wm.c: 1.543 sys/dev/pci/ixgbe/ixgbe.c: 1.112 sys/dev/pci/ixgbe/ixv.c: 1.74 sys/kern/sys_socket.c: 1.75 sys/net/agr/if_agr.c: 1.43 sys/net/bpf.c: 1.219 sys/net/if.c: 1.397, 1.399, 1.401-1.403, 1.406-1.410, 1.412-1.416 sys/net/if.h: 1.242-1.247, 1.250, 1.252-1.257 sys/net/if_bridge.c: 1.140 via patch, 1.142-1.146 sys/net/if_etherip.c: 1.40 sys/net/if_ethersubr.c: 1.243, 1.246 sys/net/if_faith.c: 1.57 sys/net/if_gif.c: 1.132 sys/net/if_l2tp.c: 1.15, 1.17 sys/net/if_loop.c: 1.98-1.101 sys/net/if_media.c: 1.35 sys/net/if_pppoe.c: 1.131-1.132 sys/net/if_spppsubr.c: 1.176-1.177 sys/net/if_tun.c: 1.142 sys/net/if_vlan.c: 1.107, 1.109, 1.114-1.121 sys/net/npf/npf_ifaddr.c: 1.3 sys/net/npf/npf_os.c: 1.8-1.9 sys/net/rtsock.c: 1.230 sys/netcan/if_canloop.c: 1.3-1.5 sys/netinet/if_arp.c: 1.255 sys/netinet/igmp.c: 1.65 sys/netinet/in.c: 1.210-1.211 sys/netinet/in_pcb.c: 1.180 sys/netinet/ip_carp.c: 1.92, 1.94 sys/netinet/ip_flow.c: 1.81 sys/netinet/ip_input.c: 1.362 sys/netinet/ip_mroute.c: 1.147 sys/netinet/ip_output.c: 1.283, 1.285, 1.287 sys/netinet6/frag6.c: 1.61 sys/netinet6/in6.c: 1.251, 1.255 sys/netinet6/in6_pcb.c: 1.162 sys/netinet6/ip6_flow.c: 1.35 sys/netinet6/ip6_input.c: 1.183 sys/netinet6/ip6_output.c: 1.196 sys/netinet6/mld6.c: 1.90 sys/netinet6/nd6.c: 1.239-1.240 sys/netinet6/nd6_nbr.c: 1.139 sys/netinet6/nd6_rtr.c: 1.136 sys/netipsec/ipsec_output.c: 1.65 sys/rump/net/lib/libnetinet/netinet_component.c: 1.9-1.10 kmem_intr_free kmem_intr_[z]alloced memory the underlying pools are the same but api-wise those should match Unify IFEF_*_MPSAFE into IFEF_MPSAFE There are already two flags for if_output and if_start, however, it seems such MPSAFE flags are eventually needed for all if_XXX operations. Having discrete flags for each operation is wasteful of if_extflags bits. So let's unify the flags into one: IFEF_MPSAFE. Fortunately IFEF_*_MPSAFE flags have never been included in any releases, so we can change them without breaking backward compatibility of the releases (though the kernel version of -current should be bumped). Note that if an interface have both MP-safe and non-MP-safe operations at a time, we have to set the IFEF_MPSAFE flag and let callees of non-MP-safe opeartions take the kernel lock. Proposed on tech-kern@ and tech-net@ Provide macros for softnet_lock and KERNEL_LOCK hiding NET_MPSAFE switch It reduces C&P codes such as "#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); ..." scattered all over the source code and makes it easy to identify remaining KERNEL_LOCK and/or softnet_lock that are held even if NET_MPSAFE. No functional change Hold KERNEL_LOCK on if_ioctl selectively based on IFEF_MPSAFE If IFEF_MPSAFE is set, hold the lock and otherwise don't hold. This change requires additions of KERNEL_LOCK to subsequence functions from if_ioctl such as ifmedia_ioctl and ifioctl_common to protect non-MP-safe components. Proposed on tech-kern@ and tech-net@ Ensure to hold if_ioctl_lock when calling if_flags_set Fix locking against myself on ifpromisc vlan_unconfig_locked could be called with holding if_ioctl_lock. Ensure to not turn on IFF_RUNNING of an interface until its initialization completes And ensure to turn off it before destruction as per IFF_RUNNING's description "resource allocated". (The description is a bit doubtful though, I believe the change is still proper.) Ensure to hold if_ioctl_lock on if_up and if_down One exception for if_down is if_detach; in the case the lock isn't needed because it's guaranteed that no other one can access ifp at that point. Make if_link_queue MP-safe if IFEF_MPSAFE if_link_queue is a queue to store events of link state changes, which is used to pass events from (typically) an interrupt handler to if_link_state_change softint. The queue was protected by KERNEL_LOCK so far, but if IFEF_MPSAFE is enabled, it becomes unsafe because (perhaps) an interrupt handler of an interface with IFEF_MPSAFE doesn't take KERNEL_LOCK. Protect it by a spin mutex. Additionally with this change KERNEL_LOCK of if_link_state_change softint is omitted if NET_MPSAFE is enabled. Note that the spin mutex is now ifp->if_snd.ifq_lock as well as the case of if_timer (see the comment). Use IFADDR_WRITER_FOREACH instead of IFADDR_READER_FOREACH At that point no other one modifies the list so IFADDR_READER_FOREACH is unnecessary. Use of IFADDR_READER_FOREACH is harmless in general though, if we try to detect contract violations of pserialize, using it violates the contract. So avoid using it makes life easy. Ensure to call if_addr_init with holding if_ioctl_lock Get rid of outdated comments Fix build of kernels without ether By throwing out if_enable_vlan_mtu and if_disable_vlan_mtu that created a unnecessary dependency from if.c to if_ethersubr.c. PR kern/52790 Rename IFNET_LOCK to IFNET_GLOBAL_LOCK IFNET_LOCK will be used in another lock, if_ioctl_lock (might be renamed then). Wrap if_ioctl_lock with IFNET_* macros (NFC) Also if_ioctl_lock perhaps needs to be renamed to something because it's now not just for ioctl... Reorder some destruction routines in if_detach - Destroy if_ioctl_lock at the end of the if_detach because it's used in various destruction routines - Move psref_target_destroy after pr_purgeif because we want to use psref in pr_purgeif (otherwise destruction procedures can be tricky) Ensure to call if_mcast_op with holding IFNET_LOCK Note that CARP doesn't deal with IFNET_LOCK yet. Remove IFNET_GLOBAL_LOCK where it's unnecessary because IFNET_LOCK is held Describe which lock is used to protect each member variable of struct ifnet Requested by skrll@ Write a guideline for converting an interface to IFEF_MPSAFE Requested by skrll@ Note that IFNET_LOCK must not be held in softint Don't set IFEF_MPSAFE unless NET_MPSAFE at this point Because recent investigations show that interfaces with IFEF_MPSAFE need to follow additional restrictions to work with the flag safely. We should enable it on an interface by default only if the interface surely satisfies the restrictions, which are described in if.h. Note that enabling IFEF_MPSAFE solely gains a few benefit on performance because the network stack is still serialized by the big kernel locks by default.diff -r1.4.4.3 -r1.4.4.4 src/sys/arch/arm/sunxi/sunxi_emac.c
(snj)
--- src/sys/arch/arm/sunxi/sunxi_emac.c 2017/09/11 05:24:16 1.4.4.3
+++ src/sys/arch/arm/sunxi/sunxi_emac.c 2018/01/02 10:20:32 1.4.4.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: sunxi_emac.c,v 1.4.4.3 2017/09/11 05:24:16 snj Exp $ */ | 1 | /* $NetBSD: sunxi_emac.c,v 1.4.4.4 2018/01/02 10:20:32 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2016-2017 Jared McNeill <jmcneill@invisible.ca> | 4 | * Copyright (c) 2016-2017 Jared McNeill <jmcneill@invisible.ca> | |
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 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | /* | 29 | /* | |
30 | * Allwinner Gigabit Ethernet MAC (EMAC) controller | 30 | * Allwinner Gigabit Ethernet MAC (EMAC) controller | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | #include "opt_net_mpsafe.h" | 33 | #include "opt_net_mpsafe.h" | |
34 | 34 | |||
35 | #include <sys/cdefs.h> | 35 | #include <sys/cdefs.h> | |
36 | __KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.4.4.3 2017/09/11 05:24:16 snj Exp $"); | 36 | __KERNEL_RCSID(0, "$NetBSD: sunxi_emac.c,v 1.4.4.4 2018/01/02 10:20:32 snj Exp $"); | |
37 | 37 | |||
38 | #include <sys/param.h> | 38 | #include <sys/param.h> | |
39 | #include <sys/bus.h> | 39 | #include <sys/bus.h> | |
40 | #include <sys/device.h> | 40 | #include <sys/device.h> | |
41 | #include <sys/intr.h> | 41 | #include <sys/intr.h> | |
42 | #include <sys/systm.h> | 42 | #include <sys/systm.h> | |
43 | #include <sys/kernel.h> | 43 | #include <sys/kernel.h> | |
44 | #include <sys/mutex.h> | 44 | #include <sys/mutex.h> | |
45 | #include <sys/callout.h> | 45 | #include <sys/callout.h> | |
46 | #include <sys/gpio.h> | 46 | #include <sys/gpio.h> | |
47 | #include <sys/cprng.h> | 47 | #include <sys/cprng.h> | |
48 | 48 | |||
49 | #include <net/if.h> | 49 | #include <net/if.h> | |
@@ -1358,27 +1358,27 @@ sunxi_emac_attach(device_t parent, devic | @@ -1358,27 +1358,27 @@ sunxi_emac_attach(device_t parent, devic | |||
1358 | FDT_INTR_FLAGS, sunxi_emac_intr, sc); | 1358 | FDT_INTR_FLAGS, sunxi_emac_intr, sc); | |
1359 | if (sc->ih == NULL) { | 1359 | if (sc->ih == NULL) { | |
1360 | aprint_error_dev(self, "failed to establish interrupt on %s\n", | 1360 | aprint_error_dev(self, "failed to establish interrupt on %s\n", | |
1361 | intrstr); | 1361 | intrstr); | |
1362 | return; | 1362 | return; | |
1363 | } | 1363 | } | |
1364 | aprint_normal_dev(self, "interrupting on %s\n", intrstr); | 1364 | aprint_normal_dev(self, "interrupting on %s\n", intrstr); | |
1365 | 1365 | |||
1366 | /* Setup ethernet interface */ | 1366 | /* Setup ethernet interface */ | |
1367 | ifp->if_softc = sc; | 1367 | ifp->if_softc = sc; | |
1368 | snprintf(ifp->if_xname, IFNAMSIZ, EMAC_IFNAME, device_unit(self)); | 1368 | snprintf(ifp->if_xname, IFNAMSIZ, EMAC_IFNAME, device_unit(self)); | |
1369 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | 1369 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | |
1370 | #ifdef EMAC_MPSAFE | 1370 | #ifdef EMAC_MPSAFE | |
1371 | ifp->if_extflags = IFEF_START_MPSAFE; | 1371 | ifp->if_extflags = IFEF_MPSAFE; | |
1372 | #endif | 1372 | #endif | |
1373 | ifp->if_start = sunxi_emac_start; | 1373 | ifp->if_start = sunxi_emac_start; | |
1374 | ifp->if_ioctl = sunxi_emac_ioctl; | 1374 | ifp->if_ioctl = sunxi_emac_ioctl; | |
1375 | ifp->if_init = sunxi_emac_init; | 1375 | ifp->if_init = sunxi_emac_init; | |
1376 | ifp->if_stop = sunxi_emac_stop; | 1376 | ifp->if_stop = sunxi_emac_stop; | |
1377 | ifp->if_capabilities = IFCAP_CSUM_IPv4_Rx | | 1377 | ifp->if_capabilities = IFCAP_CSUM_IPv4_Rx | | |
1378 | IFCAP_CSUM_IPv4_Tx | | 1378 | IFCAP_CSUM_IPv4_Tx | | |
1379 | IFCAP_CSUM_TCPv4_Rx | | 1379 | IFCAP_CSUM_TCPv4_Rx | | |
1380 | IFCAP_CSUM_TCPv4_Tx | | 1380 | IFCAP_CSUM_TCPv4_Tx | | |
1381 | IFCAP_CSUM_UDPv4_Rx | | 1381 | IFCAP_CSUM_UDPv4_Rx | | |
1382 | IFCAP_CSUM_UDPv4_Tx; | 1382 | IFCAP_CSUM_UDPv4_Tx; | |
1383 | IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); | 1383 | IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); | |
1384 | IFQ_SET_READY(&ifp->if_snd); | 1384 | IFQ_SET_READY(&ifp->if_snd); |
--- src/sys/dev/ic/dwc_gmac.c 2017/12/10 10:10:23 1.40.6.1
+++ src/sys/dev/ic/dwc_gmac.c 2018/01/02 10:20:32 1.40.6.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: dwc_gmac.c,v 1.40.6.1 2017/12/10 10:10:23 snj Exp $ */ | 1 | /* $NetBSD: dwc_gmac.c,v 1.40.6.2 2018/01/02 10:20:32 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2013, 2014 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 Matt Thomas of 3am Software Foundry and Martin Husemann. | 8 | * by Matt Thomas of 3am Software Foundry and Martin Husemann. | |
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. | |
@@ -31,27 +31,27 @@ | @@ -31,27 +31,27 @@ | |||
31 | 31 | |||
32 | /* | 32 | /* | |
33 | * This driver supports the Synopsis Designware GMAC core, as found | 33 | * This driver supports the Synopsis Designware GMAC core, as found | |
34 | * on Allwinner A20 cores and others. | 34 | * on Allwinner A20 cores and others. | |
35 | * | 35 | * | |
36 | * Real documentation seems to not be available, the marketing product | 36 | * Real documentation seems to not be available, the marketing product | |
37 | * documents could be found here: | 37 | * documents could be found here: | |
38 | * | 38 | * | |
39 | * http://www.synopsys.com/dw/ipdir.php?ds=dwc_ether_mac10_100_1000_unive | 39 | * http://www.synopsys.com/dw/ipdir.php?ds=dwc_ether_mac10_100_1000_unive | |
40 | */ | 40 | */ | |
41 | 41 | |||
42 | #include <sys/cdefs.h> | 42 | #include <sys/cdefs.h> | |
43 | 43 | |||
44 | __KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.40.6.1 2017/12/10 10:10:23 snj Exp $"); | 44 | __KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.40.6.2 2018/01/02 10:20:32 snj Exp $"); | |
45 | 45 | |||
46 | /* #define DWC_GMAC_DEBUG 1 */ | 46 | /* #define DWC_GMAC_DEBUG 1 */ | |
47 | 47 | |||
48 | #ifdef _KERNEL_OPT | 48 | #ifdef _KERNEL_OPT | |
49 | #include "opt_inet.h" | 49 | #include "opt_inet.h" | |
50 | #include "opt_net_mpsafe.h" | 50 | #include "opt_net_mpsafe.h" | |
51 | #endif | 51 | #endif | |
52 | 52 | |||
53 | #include <sys/param.h> | 53 | #include <sys/param.h> | |
54 | #include <sys/bus.h> | 54 | #include <sys/bus.h> | |
55 | #include <sys/device.h> | 55 | #include <sys/device.h> | |
56 | #include <sys/intr.h> | 56 | #include <sys/intr.h> | |
57 | #include <sys/systm.h> | 57 | #include <sys/systm.h> | |
@@ -213,27 +213,29 @@ dwc_gmac_attach(struct dwc_gmac_softc *s | @@ -213,27 +213,29 @@ dwc_gmac_attach(struct dwc_gmac_softc *s | |||
213 | goto fail; | 213 | goto fail; | |
214 | } | 214 | } | |
215 | 215 | |||
216 | sc->sc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET); | 216 | sc->sc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET); | |
217 | mutex_init(&sc->sc_txq.t_mtx, MUTEX_DEFAULT, IPL_NET); | 217 | mutex_init(&sc->sc_txq.t_mtx, MUTEX_DEFAULT, IPL_NET); | |
218 | mutex_init(&sc->sc_rxq.r_mtx, MUTEX_DEFAULT, IPL_NET); | 218 | mutex_init(&sc->sc_rxq.r_mtx, MUTEX_DEFAULT, IPL_NET); | |
219 | 219 | |||
220 | /* | 220 | /* | |
221 | * Prepare interface data | 221 | * Prepare interface data | |
222 | */ | 222 | */ | |
223 | ifp->if_softc = sc; | 223 | ifp->if_softc = sc; | |
224 | strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); | 224 | strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); | |
225 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | 225 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | |
226 | ifp->if_extflags = IFEF_START_MPSAFE; | 226 | #ifdef DWCGMAC_MPSAFE | |
227 | ifp->if_extflags = IFEF_MPSAFE; | |||
228 | #endif | |||
227 | ifp->if_ioctl = dwc_gmac_ioctl; | 229 | ifp->if_ioctl = dwc_gmac_ioctl; | |
228 | ifp->if_start = dwc_gmac_start; | 230 | ifp->if_start = dwc_gmac_start; | |
229 | ifp->if_init = dwc_gmac_init; | 231 | ifp->if_init = dwc_gmac_init; | |
230 | ifp->if_stop = dwc_gmac_stop; | 232 | ifp->if_stop = dwc_gmac_stop; | |
231 | IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); | 233 | IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); | |
232 | IFQ_SET_READY(&ifp->if_snd); | 234 | IFQ_SET_READY(&ifp->if_snd); | |
233 | 235 | |||
234 | /* | 236 | /* | |
235 | * Attach MII subdevices | 237 | * Attach MII subdevices | |
236 | */ | 238 | */ | |
237 | sc->sc_ec.ec_mii = &sc->sc_mii; | 239 | sc->sc_ec.ec_mii = &sc->sc_mii; | |
238 | ifmedia_init(&mii->mii_media, 0, ether_mediachange, ether_mediastatus); | 240 | ifmedia_init(&mii->mii_media, 0, ether_mediachange, ether_mediastatus); | |
239 | mii->mii_ifp = ifp; | 241 | mii->mii_ifp = ifp; | |
@@ -826,27 +828,27 @@ dwc_gmac_init_locked(struct ifnet *ifp) | @@ -826,27 +828,27 @@ dwc_gmac_init_locked(struct ifnet *ifp) | |||
826 | 828 | |||
827 | sc->sc_stopping = false; | 829 | sc->sc_stopping = false; | |
828 | 830 | |||
829 | ifp->if_flags |= IFF_RUNNING; | 831 | ifp->if_flags |= IFF_RUNNING; | |
830 | ifp->if_flags &= ~IFF_OACTIVE; | 832 | ifp->if_flags &= ~IFF_OACTIVE; | |
831 | 833 | |||
832 | return 0; | 834 | return 0; | |
833 | } | 835 | } | |
834 | 836 | |||
835 | static void | 837 | static void | |
836 | dwc_gmac_start(struct ifnet *ifp) | 838 | dwc_gmac_start(struct ifnet *ifp) | |
837 | { | 839 | { | |
838 | struct dwc_gmac_softc *sc = ifp->if_softc; | 840 | struct dwc_gmac_softc *sc = ifp->if_softc; | |
839 | KASSERT(ifp->if_extflags & IFEF_START_MPSAFE); | 841 | KASSERT(if_is_mpsafe(ifp)); | |
840 | 842 | |||
841 | mutex_enter(sc->sc_lock); | 843 | mutex_enter(sc->sc_lock); | |
842 | if (!sc->sc_stopping) { | 844 | if (!sc->sc_stopping) { | |
843 | mutex_enter(&sc->sc_txq.t_mtx); | 845 | mutex_enter(&sc->sc_txq.t_mtx); | |
844 | dwc_gmac_start_locked(ifp); | 846 | dwc_gmac_start_locked(ifp); | |
845 | mutex_exit(&sc->sc_txq.t_mtx); | 847 | mutex_exit(&sc->sc_txq.t_mtx); | |
846 | } | 848 | } | |
847 | mutex_exit(sc->sc_lock); | 849 | mutex_exit(sc->sc_lock); | |
848 | } | 850 | } | |
849 | 851 | |||
850 | static void | 852 | static void | |
851 | dwc_gmac_start_locked(struct ifnet *ifp) | 853 | dwc_gmac_start_locked(struct ifnet *ifp) | |
852 | { | 854 | { |
--- src/sys/dev/pci/if_iwm.c 2017/12/10 10:10:24 1.73.2.2
+++ src/sys/dev/pci/if_iwm.c 2018/01/02 10:20:33 1.73.2.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_iwm.c,v 1.73.2.2 2017/12/10 10:10:24 snj Exp $ */ | 1 | /* $NetBSD: if_iwm.c,v 1.73.2.3 2018/01/02 10:20:33 snj Exp $ */ | |
2 | /* OpenBSD: if_iwm.c,v 1.148 2016/11/19 21:07:08 stsp Exp */ | 2 | /* OpenBSD: if_iwm.c,v 1.148 2016/11/19 21:07:08 stsp Exp */ | |
3 | #define IEEE80211_NO_HT | 3 | #define IEEE80211_NO_HT | |
4 | /* | 4 | /* | |
5 | * Copyright (c) 2014, 2016 genua gmbh <info@genua.de> | 5 | * Copyright (c) 2014, 2016 genua gmbh <info@genua.de> | |
6 | * Author: Stefan Sperling <stsp@openbsd.org> | 6 | * Author: Stefan Sperling <stsp@openbsd.org> | |
7 | * Copyright (c) 2014 Fixup Software Ltd. | 7 | * Copyright (c) 2014 Fixup Software Ltd. | |
8 | * | 8 | * | |
9 | * Permission to use, copy, modify, and distribute this software for any | 9 | * Permission to use, copy, modify, and distribute this software for any | |
10 | * purpose with or without fee is hereby granted, provided that the above | 10 | * purpose with or without fee is hereby granted, provided that the above | |
11 | * copyright notice and this permission notice appear in all copies. | 11 | * copyright notice and this permission notice appear in all copies. | |
12 | * | 12 | * | |
13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
@@ -96,27 +96,27 @@ | @@ -96,27 +96,27 @@ | |||
96 | * purpose with or without fee is hereby granted, provided that the above | 96 | * purpose with or without fee is hereby granted, provided that the above | |
97 | * copyright notice and this permission notice appear in all copies. | 97 | * copyright notice and this permission notice appear in all copies. | |
98 | * | 98 | * | |
99 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 99 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
100 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 100 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
101 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 101 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
102 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 102 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
103 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 103 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
104 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 104 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
105 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 105 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
106 | */ | 106 | */ | |
107 | 107 | |||
108 | #include <sys/cdefs.h> | 108 | #include <sys/cdefs.h> | |
109 | __KERNEL_RCSID(0, "$NetBSD: if_iwm.c,v 1.73.2.2 2017/12/10 10:10:24 snj Exp $"); | 109 | __KERNEL_RCSID(0, "$NetBSD: if_iwm.c,v 1.73.2.3 2018/01/02 10:20:33 snj Exp $"); | |
110 | 110 | |||
111 | #include <sys/param.h> | 111 | #include <sys/param.h> | |
112 | #include <sys/conf.h> | 112 | #include <sys/conf.h> | |
113 | #include <sys/kernel.h> | 113 | #include <sys/kernel.h> | |
114 | #include <sys/kmem.h> | 114 | #include <sys/kmem.h> | |
115 | #include <sys/mbuf.h> | 115 | #include <sys/mbuf.h> | |
116 | #include <sys/mutex.h> | 116 | #include <sys/mutex.h> | |
117 | #include <sys/proc.h> | 117 | #include <sys/proc.h> | |
118 | #include <sys/socket.h> | 118 | #include <sys/socket.h> | |
119 | #include <sys/sockio.h> | 119 | #include <sys/sockio.h> | |
120 | #include <sys/sysctl.h> | 120 | #include <sys/sysctl.h> | |
121 | #include <sys/systm.h> | 121 | #include <sys/systm.h> | |
122 | 122 | |||
@@ -6311,27 +6311,27 @@ iwm_do_newstate(struct ieee80211com *ic, | @@ -6311,27 +6311,27 @@ iwm_do_newstate(struct ieee80211com *ic, | |||
6311 | } | 6311 | } | |
6312 | 6312 | |||
6313 | static void | 6313 | static void | |
6314 | iwm_newstate_cb(struct work *wk, void *v) | 6314 | iwm_newstate_cb(struct work *wk, void *v) | |
6315 | { | 6315 | { | |
6316 | struct iwm_softc *sc = v; | 6316 | struct iwm_softc *sc = v; | |
6317 | struct ieee80211com *ic = &sc->sc_ic; | 6317 | struct ieee80211com *ic = &sc->sc_ic; | |
6318 | struct iwm_newstate_state *iwmns = (struct iwm_newstate_state *)wk; | 6318 | struct iwm_newstate_state *iwmns = (struct iwm_newstate_state *)wk; | |
6319 | enum ieee80211_state nstate = iwmns->ns_nstate; | 6319 | enum ieee80211_state nstate = iwmns->ns_nstate; | |
6320 | int generation = iwmns->ns_generation; | 6320 | int generation = iwmns->ns_generation; | |
6321 | int arg = iwmns->ns_arg; | 6321 | int arg = iwmns->ns_arg; | |
6322 | int s; | 6322 | int s; | |
6323 | 6323 | |||
6324 | kmem_free(iwmns, sizeof(*iwmns)); | 6324 | kmem_intr_free(iwmns, sizeof(*iwmns)); | |
6325 | 6325 | |||
6326 | s = splnet(); | 6326 | s = splnet(); | |
6327 | 6327 | |||
6328 | DPRINTF(("Prepare to switch state %d->%d\n", ic->ic_state, nstate)); | 6328 | DPRINTF(("Prepare to switch state %d->%d\n", ic->ic_state, nstate)); | |
6329 | if (sc->sc_generation != generation) { | 6329 | if (sc->sc_generation != generation) { | |
6330 | DPRINTF(("newstate_cb: someone pulled the plug meanwhile\n")); | 6330 | DPRINTF(("newstate_cb: someone pulled the plug meanwhile\n")); | |
6331 | if (nstate == IEEE80211_S_INIT) { | 6331 | if (nstate == IEEE80211_S_INIT) { | |
6332 | DPRINTF(("newstate_cb: nstate == IEEE80211_S_INIT: " | 6332 | DPRINTF(("newstate_cb: nstate == IEEE80211_S_INIT: " | |
6333 | "calling sc_newstate()\n")); | 6333 | "calling sc_newstate()\n")); | |
6334 | (void) sc->sc_newstate(ic, nstate, arg); | 6334 | (void) sc->sc_newstate(ic, nstate, arg); | |
6335 | } | 6335 | } | |
6336 | } else | 6336 | } else | |
6337 | (void) iwm_do_newstate(ic, nstate, arg); | 6337 | (void) iwm_do_newstate(ic, nstate, arg); |
--- src/sys/dev/pci/if_wm.c 2017/12/10 10:16:09 1.508.4.10
+++ src/sys/dev/pci/if_wm.c 2018/01/02 10:20:33 1.508.4.11
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_wm.c,v 1.508.4.10 2017/12/10 10:16:09 snj Exp $ */ | 1 | /* $NetBSD: if_wm.c,v 1.508.4.11 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc. | 4 | * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. | 7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -73,27 +73,27 @@ | @@ -73,27 +73,27 @@ | |||
73 | * TODO (in order of importance): | 73 | * TODO (in order of importance): | |
74 | * | 74 | * | |
75 | * - Check XXX'ed comments | 75 | * - Check XXX'ed comments | |
76 | * - TX Multi queue improvement (refine queue selection logic) | 76 | * - TX Multi queue improvement (refine queue selection logic) | |
77 | * - Split header buffer for newer descriptors | 77 | * - Split header buffer for newer descriptors | |
78 | * - EEE (Energy Efficiency Ethernet) | 78 | * - EEE (Energy Efficiency Ethernet) | |
79 | * - Virtual Function | 79 | * - Virtual Function | |
80 | * - Set LED correctly (based on contents in EEPROM) | 80 | * - Set LED correctly (based on contents in EEPROM) | |
81 | * - Rework how parameters are loaded from the EEPROM. | 81 | * - Rework how parameters are loaded from the EEPROM. | |
82 | * - Image Unique ID | 82 | * - Image Unique ID | |
83 | */ | 83 | */ | |
84 | 84 | |||
85 | #include <sys/cdefs.h> | 85 | #include <sys/cdefs.h> | |
86 | __KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.10 2017/12/10 10:16:09 snj Exp $"); | 86 | __KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.11 2018/01/02 10:20:33 snj Exp $"); | |
87 | 87 | |||
88 | #ifdef _KERNEL_OPT | 88 | #ifdef _KERNEL_OPT | |
89 | #include "opt_net_mpsafe.h" | 89 | #include "opt_net_mpsafe.h" | |
90 | #include "opt_if_wm.h" | 90 | #include "opt_if_wm.h" | |
91 | #endif | 91 | #endif | |
92 | 92 | |||
93 | #include <sys/param.h> | 93 | #include <sys/param.h> | |
94 | #include <sys/systm.h> | 94 | #include <sys/systm.h> | |
95 | #include <sys/callout.h> | 95 | #include <sys/callout.h> | |
96 | #include <sys/mbuf.h> | 96 | #include <sys/mbuf.h> | |
97 | #include <sys/malloc.h> | 97 | #include <sys/malloc.h> | |
98 | #include <sys/kmem.h> | 98 | #include <sys/kmem.h> | |
99 | #include <sys/kernel.h> | 99 | #include <sys/kernel.h> | |
@@ -2626,27 +2626,27 @@ alloc_retry: | @@ -2626,27 +2626,27 @@ alloc_retry: | |||
2626 | 2626 | |||
2627 | /* Initialize the media structures accordingly. */ | 2627 | /* Initialize the media structures accordingly. */ | |
2628 | if (sc->sc_mediatype == WM_MEDIATYPE_COPPER) | 2628 | if (sc->sc_mediatype == WM_MEDIATYPE_COPPER) | |
2629 | wm_gmii_mediainit(sc, wmp->wmp_product); | 2629 | wm_gmii_mediainit(sc, wmp->wmp_product); | |
2630 | else | 2630 | else | |
2631 | wm_tbi_mediainit(sc); /* All others */ | 2631 | wm_tbi_mediainit(sc); /* All others */ | |
2632 | 2632 | |||
2633 | ifp = &sc->sc_ethercom.ec_if; | 2633 | ifp = &sc->sc_ethercom.ec_if; | |
2634 | xname = device_xname(sc->sc_dev); | 2634 | xname = device_xname(sc->sc_dev); | |
2635 | strlcpy(ifp->if_xname, xname, IFNAMSIZ); | 2635 | strlcpy(ifp->if_xname, xname, IFNAMSIZ); | |
2636 | ifp->if_softc = sc; | 2636 | ifp->if_softc = sc; | |
2637 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | 2637 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | |
2638 | #ifdef WM_MPSAFE | 2638 | #ifdef WM_MPSAFE | |
2639 | ifp->if_extflags = IFEF_START_MPSAFE; | 2639 | ifp->if_extflags = IFEF_MPSAFE; | |
2640 | #endif | 2640 | #endif | |
2641 | ifp->if_ioctl = wm_ioctl; | 2641 | ifp->if_ioctl = wm_ioctl; | |
2642 | if ((sc->sc_flags & WM_F_NEWQUEUE) != 0) { | 2642 | if ((sc->sc_flags & WM_F_NEWQUEUE) != 0) { | |
2643 | ifp->if_start = wm_nq_start; | 2643 | ifp->if_start = wm_nq_start; | |
2644 | /* | 2644 | /* | |
2645 | * When the number of CPUs is one and the controller can use | 2645 | * When the number of CPUs is one and the controller can use | |
2646 | * MSI-X, wm(4) use MSI-X but *does not* use multiqueue. | 2646 | * MSI-X, wm(4) use MSI-X but *does not* use multiqueue. | |
2647 | * That is, wm(4) use two interrupts, one is used for Tx/Rx | 2647 | * That is, wm(4) use two interrupts, one is used for Tx/Rx | |
2648 | * and the other is used for link status changing. | 2648 | * and the other is used for link status changing. | |
2649 | * In this situation, wm_nq_transmit() is disadvantageous | 2649 | * In this situation, wm_nq_transmit() is disadvantageous | |
2650 | * because of wm_select_txqueue() and pcq(9) overhead. | 2650 | * because of wm_select_txqueue() and pcq(9) overhead. | |
2651 | */ | 2651 | */ | |
2652 | if (wm_is_using_multiqueue(sc)) | 2652 | if (wm_is_using_multiqueue(sc)) | |
@@ -6991,27 +6991,27 @@ wm_select_txqueue(struct ifnet *ifp, str | @@ -6991,27 +6991,27 @@ wm_select_txqueue(struct ifnet *ifp, str | |||
6991 | 6991 | |||
6992 | /* | 6992 | /* | |
6993 | * wm_start: [ifnet interface function] | 6993 | * wm_start: [ifnet interface function] | |
6994 | * | 6994 | * | |
6995 | * Start packet transmission on the interface. | 6995 | * Start packet transmission on the interface. | |
6996 | */ | 6996 | */ | |
6997 | static void | 6997 | static void | |
6998 | wm_start(struct ifnet *ifp) | 6998 | wm_start(struct ifnet *ifp) | |
6999 | { | 6999 | { | |
7000 | struct wm_softc *sc = ifp->if_softc; | 7000 | struct wm_softc *sc = ifp->if_softc; | |
7001 | struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq; | 7001 | struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq; | |
7002 | 7002 | |||
7003 | #ifdef WM_MPSAFE | 7003 | #ifdef WM_MPSAFE | |
7004 | KASSERT(ifp->if_extflags & IFEF_START_MPSAFE); | 7004 | KASSERT(if_is_mpsafe(ifp)); | |
7005 | #endif | 7005 | #endif | |
7006 | /* | 7006 | /* | |
7007 | * ifp->if_obytes and ifp->if_omcasts are added in if_transmit()@if.c. | 7007 | * ifp->if_obytes and ifp->if_omcasts are added in if_transmit()@if.c. | |
7008 | */ | 7008 | */ | |
7009 | 7009 | |||
7010 | mutex_enter(txq->txq_lock); | 7010 | mutex_enter(txq->txq_lock); | |
7011 | if (!txq->txq_stopping) | 7011 | if (!txq->txq_stopping) | |
7012 | wm_start_locked(ifp); | 7012 | wm_start_locked(ifp); | |
7013 | mutex_exit(txq->txq_lock); | 7013 | mutex_exit(txq->txq_lock); | |
7014 | } | 7014 | } | |
7015 | 7015 | |||
7016 | static void | 7016 | static void | |
7017 | wm_start_locked(struct ifnet *ifp) | 7017 | wm_start_locked(struct ifnet *ifp) | |
@@ -7584,27 +7584,27 @@ wm_nq_tx_offload(struct wm_softc *sc, st | @@ -7584,27 +7584,27 @@ wm_nq_tx_offload(struct wm_softc *sc, st | |||
7584 | 7584 | |||
7585 | /* | 7585 | /* | |
7586 | * wm_nq_start: [ifnet interface function] | 7586 | * wm_nq_start: [ifnet interface function] | |
7587 | * | 7587 | * | |
7588 | * Start packet transmission on the interface for NEWQUEUE devices | 7588 | * Start packet transmission on the interface for NEWQUEUE devices | |
7589 | */ | 7589 | */ | |
7590 | static void | 7590 | static void | |
7591 | wm_nq_start(struct ifnet *ifp) | 7591 | wm_nq_start(struct ifnet *ifp) | |
7592 | { | 7592 | { | |
7593 | struct wm_softc *sc = ifp->if_softc; | 7593 | struct wm_softc *sc = ifp->if_softc; | |
7594 | struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq; | 7594 | struct wm_txqueue *txq = &sc->sc_queue[0].wmq_txq; | |
7595 | 7595 | |||
7596 | #ifdef WM_MPSAFE | 7596 | #ifdef WM_MPSAFE | |
7597 | KASSERT(ifp->if_extflags & IFEF_START_MPSAFE); | 7597 | KASSERT(if_is_mpsafe(ifp)); | |
7598 | #endif | 7598 | #endif | |
7599 | /* | 7599 | /* | |
7600 | * ifp->if_obytes and ifp->if_omcasts are added in if_transmit()@if.c. | 7600 | * ifp->if_obytes and ifp->if_omcasts are added in if_transmit()@if.c. | |
7601 | */ | 7601 | */ | |
7602 | 7602 | |||
7603 | mutex_enter(txq->txq_lock); | 7603 | mutex_enter(txq->txq_lock); | |
7604 | if (!txq->txq_stopping) | 7604 | if (!txq->txq_stopping) | |
7605 | wm_nq_start_locked(ifp); | 7605 | wm_nq_start_locked(ifp); | |
7606 | mutex_exit(txq->txq_lock); | 7606 | mutex_exit(txq->txq_lock); | |
7607 | } | 7607 | } | |
7608 | 7608 | |||
7609 | static void | 7609 | static void | |
7610 | wm_nq_start_locked(struct ifnet *ifp) | 7610 | wm_nq_start_locked(struct ifnet *ifp) |
--- src/sys/dev/pci/ixgbe/ixgbe.c 2017/12/21 19:28:54 1.88.2.6
+++ src/sys/dev/pci/ixgbe/ixgbe.c 2018/01/02 10:20:33 1.88.2.7
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ixgbe.c,v 1.88.2.6 2017/12/21 19:28:54 snj Exp $ */ | 1 | /* $NetBSD: ixgbe.c,v 1.88.2.7 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /****************************************************************************** | 3 | /****************************************************************************** | |
4 | 4 | |||
5 | Copyright (c) 2001-2017, Intel Corporation | 5 | Copyright (c) 2001-2017, Intel Corporation | |
6 | All rights reserved. | 6 | All rights reserved. | |
7 | 7 | |||
8 | Redistribution and use in source and binary forms, with or without | 8 | Redistribution and use in source and binary forms, with or without | |
9 | modification, are permitted provided that the following conditions are met: | 9 | modification, are permitted provided that the following conditions are met: | |
10 | 10 | |||
11 | 1. Redistributions of source code must retain the above copyright notice, | 11 | 1. Redistributions of source code must retain the above copyright notice, | |
12 | this list of conditions and the following disclaimer. | 12 | this list of conditions and the following disclaimer. | |
13 | 13 | |||
14 | 2. Redistributions in binary form must reproduce the above copyright | 14 | 2. Redistributions in binary form must reproduce the above copyright | |
@@ -1209,27 +1209,27 @@ ixgbe_setup_interface(device_t dev, stru | @@ -1209,27 +1209,27 @@ ixgbe_setup_interface(device_t dev, stru | |||
1209 | struct ifnet *ifp; | 1209 | struct ifnet *ifp; | |
1210 | int rv; | 1210 | int rv; | |
1211 | 1211 | |||
1212 | INIT_DEBUGOUT("ixgbe_setup_interface: begin"); | 1212 | INIT_DEBUGOUT("ixgbe_setup_interface: begin"); | |
1213 | 1213 | |||
1214 | ifp = adapter->ifp = &ec->ec_if; | 1214 | ifp = adapter->ifp = &ec->ec_if; | |
1215 | strlcpy(ifp->if_xname, device_xname(dev), IFNAMSIZ); | 1215 | strlcpy(ifp->if_xname, device_xname(dev), IFNAMSIZ); | |
1216 | ifp->if_baudrate = IF_Gbps(10); | 1216 | ifp->if_baudrate = IF_Gbps(10); | |
1217 | ifp->if_init = ixgbe_init; | 1217 | ifp->if_init = ixgbe_init; | |
1218 | ifp->if_stop = ixgbe_ifstop; | 1218 | ifp->if_stop = ixgbe_ifstop; | |
1219 | ifp->if_softc = adapter; | 1219 | ifp->if_softc = adapter; | |
1220 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | 1220 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | |
1221 | #ifdef IXGBE_MPSAFE | 1221 | #ifdef IXGBE_MPSAFE | |
1222 | ifp->if_extflags = IFEF_START_MPSAFE; | 1222 | ifp->if_extflags = IFEF_MPSAFE; | |
1223 | #endif | 1223 | #endif | |
1224 | ifp->if_ioctl = ixgbe_ioctl; | 1224 | ifp->if_ioctl = ixgbe_ioctl; | |
1225 | #if __FreeBSD_version >= 1100045 | 1225 | #if __FreeBSD_version >= 1100045 | |
1226 | /* TSO parameters */ | 1226 | /* TSO parameters */ | |
1227 | ifp->if_hw_tsomax = 65518; | 1227 | ifp->if_hw_tsomax = 65518; | |
1228 | ifp->if_hw_tsomaxsegcount = IXGBE_82599_SCATTER; | 1228 | ifp->if_hw_tsomaxsegcount = IXGBE_82599_SCATTER; | |
1229 | ifp->if_hw_tsomaxsegsize = 2048; | 1229 | ifp->if_hw_tsomaxsegsize = 2048; | |
1230 | #endif | 1230 | #endif | |
1231 | if (adapter->feat_en & IXGBE_FEATURE_LEGACY_TX) { | 1231 | if (adapter->feat_en & IXGBE_FEATURE_LEGACY_TX) { | |
1232 | #if 0 | 1232 | #if 0 | |
1233 | ixgbe_start_locked = ixgbe_legacy_start_locked; | 1233 | ixgbe_start_locked = ixgbe_legacy_start_locked; | |
1234 | #endif | 1234 | #endif | |
1235 | } else { | 1235 | } else { |
--- src/sys/dev/pci/ixgbe/ixv.c 2017/12/21 19:28:54 1.56.2.3
+++ src/sys/dev/pci/ixgbe/ixv.c 2018/01/02 10:20:33 1.56.2.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /*$NetBSD: ixv.c,v 1.56.2.3 2017/12/21 19:28:54 snj Exp $*/ | 1 | /*$NetBSD: ixv.c,v 1.56.2.4 2018/01/02 10:20:33 snj Exp $*/ | |
2 | 2 | |||
3 | /****************************************************************************** | 3 | /****************************************************************************** | |
4 | 4 | |||
5 | Copyright (c) 2001-2017, Intel Corporation | 5 | Copyright (c) 2001-2017, Intel Corporation | |
6 | All rights reserved. | 6 | All rights reserved. | |
7 | 7 | |||
8 | Redistribution and use in source and binary forms, with or without | 8 | Redistribution and use in source and binary forms, with or without | |
9 | modification, are permitted provided that the following conditions are met: | 9 | modification, are permitted provided that the following conditions are met: | |
10 | 10 | |||
11 | 1. Redistributions of source code must retain the above copyright notice, | 11 | 1. Redistributions of source code must retain the above copyright notice, | |
12 | this list of conditions and the following disclaimer. | 12 | this list of conditions and the following disclaimer. | |
13 | 13 | |||
14 | 2. Redistributions in binary form must reproduce the above copyright | 14 | 2. Redistributions in binary form must reproduce the above copyright | |
@@ -1388,27 +1388,27 @@ ixv_setup_interface(device_t dev, struct | @@ -1388,27 +1388,27 @@ ixv_setup_interface(device_t dev, struct | |||
1388 | struct ifnet *ifp; | 1388 | struct ifnet *ifp; | |
1389 | int rv; | 1389 | int rv; | |
1390 | 1390 | |||
1391 | INIT_DEBUGOUT("ixv_setup_interface: begin"); | 1391 | INIT_DEBUGOUT("ixv_setup_interface: begin"); | |
1392 | 1392 | |||
1393 | ifp = adapter->ifp = &ec->ec_if; | 1393 | ifp = adapter->ifp = &ec->ec_if; | |
1394 | strlcpy(ifp->if_xname, device_xname(dev), IFNAMSIZ); | 1394 | strlcpy(ifp->if_xname, device_xname(dev), IFNAMSIZ); | |
1395 | ifp->if_baudrate = IF_Gbps(10); | 1395 | ifp->if_baudrate = IF_Gbps(10); | |
1396 | ifp->if_init = ixv_init; | 1396 | ifp->if_init = ixv_init; | |
1397 | ifp->if_stop = ixv_ifstop; | 1397 | ifp->if_stop = ixv_ifstop; | |
1398 | ifp->if_softc = adapter; | 1398 | ifp->if_softc = adapter; | |
1399 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | 1399 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | |
1400 | #ifdef IXGBE_MPSAFE | 1400 | #ifdef IXGBE_MPSAFE | |
1401 | ifp->if_extflags = IFEF_START_MPSAFE; | 1401 | ifp->if_extflags = IFEF_MPSAFE; | |
1402 | #endif | 1402 | #endif | |
1403 | ifp->if_ioctl = ixv_ioctl; | 1403 | ifp->if_ioctl = ixv_ioctl; | |
1404 | if (adapter->feat_en & IXGBE_FEATURE_LEGACY_TX) { | 1404 | if (adapter->feat_en & IXGBE_FEATURE_LEGACY_TX) { | |
1405 | #if 0 | 1405 | #if 0 | |
1406 | ixv_start_locked = ixgbe_legacy_start_locked; | 1406 | ixv_start_locked = ixgbe_legacy_start_locked; | |
1407 | #endif | 1407 | #endif | |
1408 | } else { | 1408 | } else { | |
1409 | ifp->if_transmit = ixgbe_mq_start; | 1409 | ifp->if_transmit = ixgbe_mq_start; | |
1410 | #if 0 | 1410 | #if 0 | |
1411 | ixv_start_locked = ixgbe_mq_start_locked; | 1411 | ixv_start_locked = ixgbe_mq_start_locked; | |
1412 | #endif | 1412 | #endif | |
1413 | } | 1413 | } | |
1414 | ifp->if_start = ixgbe_legacy_start; | 1414 | ifp->if_start = ixgbe_legacy_start; |
--- src/sys/kern/sys_socket.c 2016/07/07 06:55:43 1.74
+++ src/sys/kern/sys_socket.c 2018/01/02 10:20:33 1.74.10.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: sys_socket.c,v 1.74 2016/07/07 06:55:43 msaitoh Exp $ */ | 1 | /* $NetBSD: sys_socket.c,v 1.74.10.1 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008, 2009 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 Andrew Doran. | 8 | * by Andrew Doran. | |
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. | |
@@ -51,27 +51,27 @@ | @@ -51,27 +51,27 @@ | |||
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
58 | * SUCH DAMAGE. | 58 | * SUCH DAMAGE. | |
59 | * | 59 | * | |
60 | * @(#)sys_socket.c 8.3 (Berkeley) 2/14/95 | 60 | * @(#)sys_socket.c 8.3 (Berkeley) 2/14/95 | |
61 | */ | 61 | */ | |
62 | 62 | |||
63 | #include <sys/cdefs.h> | 63 | #include <sys/cdefs.h> | |
64 | __KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.74 2016/07/07 06:55:43 msaitoh Exp $"); | 64 | __KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.74.10.1 2018/01/02 10:20:33 snj Exp $"); | |
65 | 65 | |||
66 | #include <sys/param.h> | 66 | #include <sys/param.h> | |
67 | #include <sys/systm.h> | 67 | #include <sys/systm.h> | |
68 | #include <sys/systm.h> | 68 | #include <sys/systm.h> | |
69 | #include <sys/file.h> | 69 | #include <sys/file.h> | |
70 | #include <sys/mbuf.h> | 70 | #include <sys/mbuf.h> | |
71 | #include <sys/protosw.h> | 71 | #include <sys/protosw.h> | |
72 | #include <sys/socket.h> | 72 | #include <sys/socket.h> | |
73 | #include <sys/socketvar.h> | 73 | #include <sys/socketvar.h> | |
74 | #include <sys/ioctl.h> | 74 | #include <sys/ioctl.h> | |
75 | #include <sys/stat.h> | 75 | #include <sys/stat.h> | |
76 | #include <sys/poll.h> | 76 | #include <sys/poll.h> | |
77 | #include <sys/proc.h> | 77 | #include <sys/proc.h> | |
@@ -187,34 +187,38 @@ soo_ioctl(file_t *fp, u_long cmd, void * | @@ -187,34 +187,38 @@ soo_ioctl(file_t *fp, u_long cmd, void * | |||
187 | error = fgetown(so->so_pgid, cmd, data); | 187 | error = fgetown(so->so_pgid, cmd, data); | |
188 | break; | 188 | break; | |
189 | 189 | |||
190 | case SIOCATMARK: | 190 | case SIOCATMARK: | |
191 | *(int *)data = (so->so_state&SS_RCVATMARK) != 0; | 191 | *(int *)data = (so->so_state&SS_RCVATMARK) != 0; | |
192 | break; | 192 | break; | |
193 | 193 | |||
194 | default: | 194 | default: | |
195 | /* | 195 | /* | |
196 | * Interface/routing/protocol specific ioctls: | 196 | * Interface/routing/protocol specific ioctls: | |
197 | * interface and routing ioctls should have a | 197 | * interface and routing ioctls should have a | |
198 | * different entry since a socket's unnecessary | 198 | * different entry since a socket's unnecessary | |
199 | */ | 199 | */ | |
200 | KERNEL_LOCK(1, NULL); | |||
201 | if (IOCGROUP(cmd) == 'i') | 200 | if (IOCGROUP(cmd) == 'i') | |
201 | /* | |||
202 | * KERNEL_LOCK will be held later if if_ioctl() of the | |||
203 | * interface isn't MP-safe. | |||
204 | */ | |||
202 | error = ifioctl(so, cmd, data, curlwp); | 205 | error = ifioctl(so, cmd, data, curlwp); | |
203 | else { | 206 | else { | |
207 | KERNEL_LOCK(1, NULL); | |||
204 | error = (*so->so_proto->pr_usrreqs->pr_ioctl)(so, | 208 | error = (*so->so_proto->pr_usrreqs->pr_ioctl)(so, | |
205 | cmd, data, NULL); | 209 | cmd, data, NULL); | |
210 | KERNEL_UNLOCK_ONE(NULL); | |||
206 | } | 211 | } | |
207 | KERNEL_UNLOCK_ONE(NULL); | |||
208 | break; | 212 | break; | |
209 | } | 213 | } | |
210 | 214 | |||
211 | 215 | |||
212 | return error; | 216 | return error; | |
213 | } | 217 | } | |
214 | 218 | |||
215 | int | 219 | int | |
216 | soo_fcntl(file_t *fp, u_int cmd, void *data) | 220 | soo_fcntl(file_t *fp, u_int cmd, void *data) | |
217 | { | 221 | { | |
218 | 222 | |||
219 | if (cmd == F_SETFL) | 223 | if (cmd == F_SETFL) | |
220 | return 0; | 224 | return 0; |
--- src/sys/net/bpf.c 2017/12/21 21:51:37 1.216.6.3
+++ src/sys/net/bpf.c 2018/01/02 10:20:33 1.216.6.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: bpf.c,v 1.216.6.3 2017/12/21 21:51:37 snj Exp $ */ | 1 | /* $NetBSD: bpf.c,v 1.216.6.4 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1990, 1991, 1993 | 4 | * Copyright (c) 1990, 1991, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from the Stanford/CMU enet packet filter, | 7 | * This code is derived from the Stanford/CMU enet packet filter, | |
8 | * (net/enet.c) distributed as part of 4.3BSD, and code contributed | 8 | * (net/enet.c) distributed as part of 4.3BSD, and code contributed | |
9 | * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence | 9 | * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence | |
10 | * Berkeley Laboratory. | 10 | * Berkeley Laboratory. | |
11 | * | 11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | 12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | 13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | 14 | * are met: | |
@@ -29,27 +29,27 @@ | @@ -29,27 +29,27 @@ | |||
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | 34 | * SUCH DAMAGE. | |
35 | * | 35 | * | |
36 | * @(#)bpf.c 8.4 (Berkeley) 1/9/95 | 36 | * @(#)bpf.c 8.4 (Berkeley) 1/9/95 | |
37 | * static char rcsid[] = | 37 | * static char rcsid[] = | |
38 | * "Header: bpf.c,v 1.67 96/09/26 22:00:52 leres Exp "; | 38 | * "Header: bpf.c,v 1.67 96/09/26 22:00:52 leres Exp "; | |
39 | */ | 39 | */ | |
40 | 40 | |||
41 | #include <sys/cdefs.h> | 41 | #include <sys/cdefs.h> | |
42 | __KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.3 2017/12/21 21:51:37 snj Exp $"); | 42 | __KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.216.6.4 2018/01/02 10:20:33 snj Exp $"); | |
43 | 43 | |||
44 | #if defined(_KERNEL_OPT) | 44 | #if defined(_KERNEL_OPT) | |
45 | #include "opt_bpf.h" | 45 | #include "opt_bpf.h" | |
46 | #include "sl.h" | 46 | #include "sl.h" | |
47 | #include "strip.h" | 47 | #include "strip.h" | |
48 | #include "opt_net_mpsafe.h" | 48 | #include "opt_net_mpsafe.h" | |
49 | #endif | 49 | #endif | |
50 | 50 | |||
51 | #include <sys/param.h> | 51 | #include <sys/param.h> | |
52 | #include <sys/systm.h> | 52 | #include <sys/systm.h> | |
53 | #include <sys/mbuf.h> | 53 | #include <sys/mbuf.h> | |
54 | #include <sys/buf.h> | 54 | #include <sys/buf.h> | |
55 | #include <sys/time.h> | 55 | #include <sys/time.h> | |
@@ -474,33 +474,29 @@ bpf_detachd(struct bpf_d *d) | @@ -474,33 +474,29 @@ bpf_detachd(struct bpf_d *d) | |||
474 | * If so, turn it off. | 474 | * If so, turn it off. | |
475 | */ | 475 | */ | |
476 | if (d->bd_promisc) { | 476 | if (d->bd_promisc) { | |
477 | int error __diagused; | 477 | int error __diagused; | |
478 | 478 | |||
479 | d->bd_promisc = 0; | 479 | d->bd_promisc = 0; | |
480 | /* | 480 | /* | |
481 | * Take device out of promiscuous mode. Since we were | 481 | * Take device out of promiscuous mode. Since we were | |
482 | * able to enter promiscuous mode, we should be able | 482 | * able to enter promiscuous mode, we should be able | |
483 | * to turn it off. But we can get an error if | 483 | * to turn it off. But we can get an error if | |
484 | * the interface was configured down, so only panic | 484 | * the interface was configured down, so only panic | |
485 | * if we don't get an unexpected error. | 485 | * if we don't get an unexpected error. | |
486 | */ | 486 | */ | |
487 | #ifndef NET_MPSAFE | 487 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
488 | KERNEL_LOCK(1, NULL); | |||
489 | #endif | |||
490 | error = ifpromisc(bp->bif_ifp, 0); | 488 | error = ifpromisc(bp->bif_ifp, 0); | |
491 | #ifndef NET_MPSAFE | 489 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
492 | KERNEL_UNLOCK_ONE(NULL); | |||
493 | #endif | |||
494 | #ifdef DIAGNOSTIC | 490 | #ifdef DIAGNOSTIC | |
495 | if (error) | 491 | if (error) | |
496 | printf("%s: ifpromisc failed: %d", __func__, error); | 492 | printf("%s: ifpromisc failed: %d", __func__, error); | |
497 | #endif | 493 | #endif | |
498 | } | 494 | } | |
499 | 495 | |||
500 | /* Remove d from the interface's descriptor list. */ | 496 | /* Remove d from the interface's descriptor list. */ | |
501 | BPFIF_DLIST_WRITER_REMOVE(d); | 497 | BPFIF_DLIST_WRITER_REMOVE(d); | |
502 | 498 | |||
503 | pserialize_perform(bpf_psz); | 499 | pserialize_perform(bpf_psz); | |
504 | 500 | |||
505 | if (BPFIF_DLIST_WRITER_EMPTY(bp)) { | 501 | if (BPFIF_DLIST_WRITER_EMPTY(bp)) { | |
506 | /* | 502 | /* | |
@@ -1015,33 +1011,29 @@ bpf_ioctl(struct file *fp, u_long cmd, v | @@ -1015,33 +1011,29 @@ bpf_ioctl(struct file *fp, u_long cmd, v | |||
1015 | * Put interface into promiscuous mode. | 1011 | * Put interface into promiscuous mode. | |
1016 | */ | 1012 | */ | |
1017 | case BIOCPROMISC: | 1013 | case BIOCPROMISC: | |
1018 | mutex_enter(d->bd_mtx); | 1014 | mutex_enter(d->bd_mtx); | |
1019 | if (d->bd_bif == NULL) { | 1015 | if (d->bd_bif == NULL) { | |
1020 | mutex_exit(d->bd_mtx); | 1016 | mutex_exit(d->bd_mtx); | |
1021 | /* | 1017 | /* | |
1022 | * No interface attached yet. | 1018 | * No interface attached yet. | |
1023 | */ | 1019 | */ | |
1024 | error = EINVAL; | 1020 | error = EINVAL; | |
1025 | break; | 1021 | break; | |
1026 | } | 1022 | } | |
1027 | if (d->bd_promisc == 0) { | 1023 | if (d->bd_promisc == 0) { | |
1028 | #ifndef NET_MPSAFE | 1024 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
1029 | KERNEL_LOCK(1, NULL); | |||
1030 | #endif | |||
1031 | error = ifpromisc(d->bd_bif->bif_ifp, 1); | 1025 | error = ifpromisc(d->bd_bif->bif_ifp, 1); | |
1032 | #ifndef NET_MPSAFE | 1026 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
1033 | KERNEL_UNLOCK_ONE(NULL); | |||
1034 | #endif | |||
1035 | if (error == 0) | 1027 | if (error == 0) | |
1036 | d->bd_promisc = 1; | 1028 | d->bd_promisc = 1; | |
1037 | } | 1029 | } | |
1038 | mutex_exit(d->bd_mtx); | 1030 | mutex_exit(d->bd_mtx); | |
1039 | break; | 1031 | break; | |
1040 | 1032 | |||
1041 | /* | 1033 | /* | |
1042 | * Get device parameters. | 1034 | * Get device parameters. | |
1043 | */ | 1035 | */ | |
1044 | case BIOCGDLT: | 1036 | case BIOCGDLT: | |
1045 | mutex_enter(d->bd_mtx); | 1037 | mutex_enter(d->bd_mtx); | |
1046 | if (d->bd_bif == NULL) | 1038 | if (d->bd_bif == NULL) | |
1047 | error = EINVAL; | 1039 | error = EINVAL; | |
@@ -2240,33 +2232,29 @@ bpf_setdlt(struct bpf_d *d, u_int dlt) | @@ -2240,33 +2232,29 @@ bpf_setdlt(struct bpf_d *d, u_int dlt) | |||
2240 | ifp = d->bd_bif->bif_ifp; | 2232 | ifp = d->bd_bif->bif_ifp; | |
2241 | BPF_IFLIST_WRITER_FOREACH(bp) { | 2233 | BPF_IFLIST_WRITER_FOREACH(bp) { | |
2242 | if (bp->bif_ifp == ifp && bp->bif_dlt == dlt) | 2234 | if (bp->bif_ifp == ifp && bp->bif_dlt == dlt) | |
2243 | break; | 2235 | break; | |
2244 | } | 2236 | } | |
2245 | if (bp == NULL) | 2237 | if (bp == NULL) | |
2246 | return EINVAL; | 2238 | return EINVAL; | |
2247 | opromisc = d->bd_promisc; | 2239 | opromisc = d->bd_promisc; | |
2248 | bpf_detachd(d); | 2240 | bpf_detachd(d); | |
2249 | BPFIF_DLIST_ENTRY_INIT(d); | 2241 | BPFIF_DLIST_ENTRY_INIT(d); | |
2250 | bpf_attachd(d, bp); | 2242 | bpf_attachd(d, bp); | |
2251 | reset_d(d); | 2243 | reset_d(d); | |
2252 | if (opromisc) { | 2244 | if (opromisc) { | |
2253 | #ifndef NET_MPSAFE | 2245 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
2254 | KERNEL_LOCK(1, NULL); | |||
2255 | #endif | |||
2256 | error = ifpromisc(bp->bif_ifp, 1); | 2246 | error = ifpromisc(bp->bif_ifp, 1); | |
2257 | #ifndef NET_MPSAFE | 2247 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
2258 | KERNEL_UNLOCK_ONE(NULL); | |||
2259 | #endif | |||
2260 | if (error) | 2248 | if (error) | |
2261 | printf("%s: bpf_setdlt: ifpromisc failed (%d)\n", | 2249 | printf("%s: bpf_setdlt: ifpromisc failed (%d)\n", | |
2262 | bp->bif_ifp->if_xname, error); | 2250 | bp->bif_ifp->if_xname, error); | |
2263 | else | 2251 | else | |
2264 | d->bd_promisc = 1; | 2252 | d->bd_promisc = 1; | |
2265 | } | 2253 | } | |
2266 | return 0; | 2254 | return 0; | |
2267 | } | 2255 | } | |
2268 | 2256 | |||
2269 | static int | 2257 | static int | |
2270 | sysctl_net_bpf_maxbufsize(SYSCTLFN_ARGS) | 2258 | sysctl_net_bpf_maxbufsize(SYSCTLFN_ARGS) | |
2271 | { | 2259 | { | |
2272 | int newsize, error; | 2260 | int newsize, error; |
--- src/sys/net/if.c 2017/12/10 10:10:24 1.394.2.3
+++ src/sys/net/if.c 2018/01/02 10:20:33 1.394.2.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if.c,v 1.394.2.3 2017/12/10 10:10:24 snj Exp $ */ | 1 | /* $NetBSD: if.c,v 1.394.2.4 2018/01/02 10:20:33 snj 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.3 2017/12/10 10:10:24 snj Exp $"); | 93 | __KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.4 2018/01/02 10:20:33 snj 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> | |
@@ -199,26 +199,29 @@ static kauth_listener_t if_listener; | @@ -199,26 +199,29 @@ static kauth_listener_t if_listener; | |||
199 | 199 | |||
200 | static int doifioctl(struct socket *, u_long, void *, struct lwp *); | 200 | static int doifioctl(struct socket *, u_long, void *, struct lwp *); | |
201 | static void if_detach_queues(struct ifnet *, struct ifqueue *); | 201 | static void if_detach_queues(struct ifnet *, struct ifqueue *); | |
202 | static void sysctl_sndq_setup(struct sysctllog **, const char *, | 202 | static void sysctl_sndq_setup(struct sysctllog **, const char *, | |
203 | struct ifaltq *); | 203 | struct ifaltq *); | |
204 | static void if_slowtimo(void *); | 204 | static void if_slowtimo(void *); | |
205 | static void if_free_sadl(struct ifnet *); | 205 | static void if_free_sadl(struct ifnet *); | |
206 | static void if_attachdomain1(struct ifnet *); | 206 | static void if_attachdomain1(struct ifnet *); | |
207 | static int ifconf(u_long, void *); | 207 | static int ifconf(u_long, void *); | |
208 | static int if_transmit(struct ifnet *, struct mbuf *); | 208 | static int if_transmit(struct ifnet *, struct mbuf *); | |
209 | static int if_clone_create(const char *); | 209 | static int if_clone_create(const char *); | |
210 | static int if_clone_destroy(const char *); | 210 | static int if_clone_destroy(const char *); | |
211 | static void if_link_state_change_si(void *); | 211 | static void if_link_state_change_si(void *); | |
212 | static void if_up_locked(struct ifnet *); | |||
213 | static void _if_down(struct ifnet *); | |||
214 | static void if_down_deactivated(struct ifnet *); | |||
212 | 215 | |||
213 | struct if_percpuq { | 216 | struct if_percpuq { | |
214 | struct ifnet *ipq_ifp; | 217 | struct ifnet *ipq_ifp; | |
215 | void *ipq_si; | 218 | void *ipq_si; | |
216 | struct percpu *ipq_ifqs; /* struct ifqueue */ | 219 | struct percpu *ipq_ifqs; /* struct ifqueue */ | |
217 | }; | 220 | }; | |
218 | 221 | |||
219 | static struct mbuf *if_percpuq_dequeue(struct if_percpuq *); | 222 | static struct mbuf *if_percpuq_dequeue(struct if_percpuq *); | |
220 | 223 | |||
221 | static void if_percpuq_drops(void *, void *, struct cpu_info *); | 224 | static void if_percpuq_drops(void *, void *, struct cpu_info *); | |
222 | static int sysctl_percpuq_drops_handler(SYSCTLFN_PROTO); | 225 | static int sysctl_percpuq_drops_handler(SYSCTLFN_PROTO); | |
223 | static void sysctl_percpuq_setup(struct sysctllog **, const char *, | 226 | static void sysctl_percpuq_setup(struct sysctllog **, const char *, | |
224 | struct if_percpuq *); | 227 | struct if_percpuq *); | |
@@ -701,43 +704,46 @@ if_initialize(ifnet_t *ifp) | @@ -701,43 +704,46 @@ if_initialize(ifnet_t *ifp) | |||
701 | ifp->if_snd.altq_flags &= ALTQF_CANTCHANGE; | 704 | ifp->if_snd.altq_flags &= ALTQF_CANTCHANGE; | |
702 | ifp->if_snd.altq_tbr = NULL; | 705 | ifp->if_snd.altq_tbr = NULL; | |
703 | ifp->if_snd.altq_ifp = ifp; | 706 | ifp->if_snd.altq_ifp = ifp; | |
704 | #endif | 707 | #endif | |
705 | 708 | |||
706 | IFQ_LOCK_INIT(&ifp->if_snd); | 709 | IFQ_LOCK_INIT(&ifp->if_snd); | |
707 | 710 | |||
708 | ifp->if_pfil = pfil_head_create(PFIL_TYPE_IFNET, ifp); | 711 | ifp->if_pfil = pfil_head_create(PFIL_TYPE_IFNET, ifp); | |
709 | pfil_run_ifhooks(if_pfil, PFIL_IFNET_ATTACH, ifp); | 712 | pfil_run_ifhooks(if_pfil, PFIL_IFNET_ATTACH, ifp); | |
710 | 713 | |||
711 | IF_AFDATA_LOCK_INIT(ifp); | 714 | IF_AFDATA_LOCK_INIT(ifp); | |
712 | 715 | |||
713 | if (if_is_link_state_changeable(ifp)) { | 716 | if (if_is_link_state_changeable(ifp)) { | |
714 | ifp->if_link_si = softint_establish(SOFTINT_NET, | 717 | u_int flags = SOFTINT_NET; | |
718 | flags |= ISSET(ifp->if_extflags, IFEF_MPSAFE) ? | |||
719 | SOFTINT_MPSAFE : 0; | |||
720 | ifp->if_link_si = softint_establish(flags, | |||
715 | if_link_state_change_si, ifp); | 721 | if_link_state_change_si, ifp); | |
716 | if (ifp->if_link_si == NULL) { | 722 | if (ifp->if_link_si == NULL) { | |
717 | rv = ENOMEM; | 723 | rv = ENOMEM; | |
718 | goto fail; | 724 | goto fail; | |
719 | } | 725 | } | |
720 | } | 726 | } | |
721 | 727 | |||
722 | PSLIST_ENTRY_INIT(ifp, if_pslist_entry); | 728 | PSLIST_ENTRY_INIT(ifp, if_pslist_entry); | |
723 | PSLIST_INIT(&ifp->if_addr_pslist); | 729 | PSLIST_INIT(&ifp->if_addr_pslist); | |
724 | psref_target_init(&ifp->if_psref, ifnet_psref_class); | 730 | psref_target_init(&ifp->if_psref, ifnet_psref_class); | |
725 | ifp->if_ioctl_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); | 731 | ifp->if_ioctl_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); | |
726 | LIST_INIT(&ifp->if_multiaddrs); | 732 | LIST_INIT(&ifp->if_multiaddrs); | |
727 | 733 | |||
728 | IFNET_LOCK(); | 734 | IFNET_GLOBAL_LOCK(); | |
729 | if_getindex(ifp); | 735 | if_getindex(ifp); | |
730 | IFNET_UNLOCK(); | 736 | IFNET_GLOBAL_UNLOCK(); | |
731 | 737 | |||
732 | return 0; | 738 | return 0; | |
733 | 739 | |||
734 | fail: | 740 | fail: | |
735 | IF_AFDATA_LOCK_DESTROY(ifp); | 741 | IF_AFDATA_LOCK_DESTROY(ifp); | |
736 | 742 | |||
737 | pfil_run_ifhooks(if_pfil, PFIL_IFNET_DETACH, ifp); | 743 | pfil_run_ifhooks(if_pfil, PFIL_IFNET_DETACH, ifp); | |
738 | (void)pfil_head_destroy(ifp->if_pfil); | 744 | (void)pfil_head_destroy(ifp->if_pfil); | |
739 | 745 | |||
740 | IFQ_LOCK_DESTROY(&ifp->if_snd); | 746 | IFQ_LOCK_DESTROY(&ifp->if_snd); | |
741 | 747 | |||
742 | return rv; | 748 | return rv; | |
743 | } | 749 | } | |
@@ -764,30 +770,30 @@ if_register(ifnet_t *ifp) | @@ -764,30 +770,30 @@ if_register(ifnet_t *ifp) | |||
764 | rt_ifannouncemsg(ifp, IFAN_ARRIVAL); | 770 | rt_ifannouncemsg(ifp, IFAN_ARRIVAL); | |
765 | 771 | |||
766 | if (ifp->if_slowtimo != NULL) { | 772 | if (ifp->if_slowtimo != NULL) { | |
767 | ifp->if_slowtimo_ch = | 773 | ifp->if_slowtimo_ch = | |
768 | kmem_zalloc(sizeof(*ifp->if_slowtimo_ch), KM_SLEEP); | 774 | kmem_zalloc(sizeof(*ifp->if_slowtimo_ch), KM_SLEEP); | |
769 | callout_init(ifp->if_slowtimo_ch, 0); | 775 | callout_init(ifp->if_slowtimo_ch, 0); | |
770 | callout_setfunc(ifp->if_slowtimo_ch, if_slowtimo, ifp); | 776 | callout_setfunc(ifp->if_slowtimo_ch, if_slowtimo, ifp); | |
771 | if_slowtimo(ifp); | 777 | if_slowtimo(ifp); | |
772 | } | 778 | } | |
773 | 779 | |||
774 | if (ifp->if_transmit == NULL || ifp->if_transmit == if_nulltransmit) | 780 | if (ifp->if_transmit == NULL || ifp->if_transmit == if_nulltransmit) | |
775 | ifp->if_transmit = if_transmit; | 781 | ifp->if_transmit = if_transmit; | |
776 | 782 | |||
777 | IFNET_LOCK(); | 783 | IFNET_GLOBAL_LOCK(); | |
778 | TAILQ_INSERT_TAIL(&ifnet_list, ifp, if_list); | 784 | TAILQ_INSERT_TAIL(&ifnet_list, ifp, if_list); | |
779 | IFNET_WRITER_INSERT_TAIL(ifp); | 785 | IFNET_WRITER_INSERT_TAIL(ifp); | |
780 | IFNET_UNLOCK(); | 786 | IFNET_GLOBAL_UNLOCK(); | |
781 | } | 787 | } | |
782 | 788 | |||
783 | /* | 789 | /* | |
784 | * The if_percpuq framework | 790 | * The if_percpuq framework | |
785 | * | 791 | * | |
786 | * It allows network device drivers to execute the network stack | 792 | * It allows network device drivers to execute the network stack | |
787 | * in softint (so called softint-based if_input). It utilizes | 793 | * in softint (so called softint-based if_input). It utilizes | |
788 | * softint and percpu ifqueue. It doesn't distribute any packets | 794 | * softint and percpu ifqueue. It doesn't distribute any packets | |
789 | * between CPUs, unlike pktqueue(9). | 795 | * between CPUs, unlike pktqueue(9). | |
790 | * | 796 | * | |
791 | * Currently we support two options for device drivers to apply the framework: | 797 | * Currently we support two options for device drivers to apply the framework: | |
792 | * - Use it implicitly with less changes | 798 | * - Use it implicitly with less changes | |
793 | * - If you use if_attach in driver's _attach function and if_input in | 799 | * - If you use if_attach in driver's _attach function and if_input in | |
@@ -1296,56 +1302,42 @@ if_detach(struct ifnet *ifp) | @@ -1296,56 +1302,42 @@ if_detach(struct ifnet *ifp) | |||
1296 | 1302 | |||
1297 | #ifdef IFAREF_DEBUG | 1303 | #ifdef IFAREF_DEBUG | |
1298 | if_build_ifa_list(ifp); | 1304 | if_build_ifa_list(ifp); | |
1299 | #endif | 1305 | #endif | |
1300 | /* | 1306 | /* | |
1301 | * XXX It's kind of lame that we have to have the | 1307 | * XXX It's kind of lame that we have to have the | |
1302 | * XXX socket structure... | 1308 | * XXX socket structure... | |
1303 | */ | 1309 | */ | |
1304 | memset(&so, 0, sizeof(so)); | 1310 | memset(&so, 0, sizeof(so)); | |
1305 | 1311 | |||
1306 | s = splnet(); | 1312 | s = splnet(); | |
1307 | 1313 | |||
1308 | sysctl_teardown(&ifp->if_sysctl_log); | 1314 | sysctl_teardown(&ifp->if_sysctl_log); | |
1309 | mutex_enter(ifp->if_ioctl_lock); | 1315 | IFNET_LOCK(ifp); | |
1310 | if_deactivate(ifp); | 1316 | if_deactivate(ifp); | |
1311 | mutex_exit(ifp->if_ioctl_lock); | 1317 | IFNET_UNLOCK(ifp); | |
1312 | ||||
1313 | IFNET_LOCK(); | |||
1314 | ifindex2ifnet[ifp->if_index] = NULL; | |||
1315 | TAILQ_REMOVE(&ifnet_list, ifp, if_list); | |||
1316 | IFNET_WRITER_REMOVE(ifp); | |||
1317 | pserialize_perform(ifnet_psz); | |||
1318 | IFNET_UNLOCK(); | |||
1319 | ||||
1320 | /* Wait for all readers to drain before freeing. */ | |||
1321 | psref_target_destroy(&ifp->if_psref, ifnet_psref_class); | |||
1322 | PSLIST_ENTRY_DESTROY(ifp, if_pslist_entry); | |||
1323 | ||||
1324 | mutex_obj_free(ifp->if_ioctl_lock); | |||
1325 | ifp->if_ioctl_lock = NULL; | |||
1326 | 1318 | |||
1327 | if (ifp->if_slowtimo != NULL && ifp->if_slowtimo_ch != NULL) { | 1319 | if (ifp->if_slowtimo != NULL && ifp->if_slowtimo_ch != NULL) { | |
1328 | ifp->if_slowtimo = NULL; | 1320 | ifp->if_slowtimo = NULL; | |
1329 | callout_halt(ifp->if_slowtimo_ch, NULL); | 1321 | callout_halt(ifp->if_slowtimo_ch, NULL); | |
1330 | callout_destroy(ifp->if_slowtimo_ch); | 1322 | callout_destroy(ifp->if_slowtimo_ch); | |
1331 | kmem_free(ifp->if_slowtimo_ch, sizeof(*ifp->if_slowtimo_ch)); | 1323 | kmem_free(ifp->if_slowtimo_ch, sizeof(*ifp->if_slowtimo_ch)); | |
1332 | } | 1324 | } | |
1333 | if_deferred_start_destroy(ifp); | 1325 | if_deferred_start_destroy(ifp); | |
1334 | 1326 | |||
1335 | /* | 1327 | /* | |
1336 | * Do an if_down() to give protocols a chance to do something. | 1328 | * Do an if_down() to give protocols a chance to do something. | |
1337 | */ | 1329 | */ | |
1338 | if_down(ifp); | 1330 | if_down_deactivated(ifp); | |
1339 | 1331 | |||
1340 | #ifdef ALTQ | 1332 | #ifdef ALTQ | |
1341 | if (ALTQ_IS_ENABLED(&ifp->if_snd)) | 1333 | if (ALTQ_IS_ENABLED(&ifp->if_snd)) | |
1342 | altq_disable(&ifp->if_snd); | 1334 | altq_disable(&ifp->if_snd); | |
1343 | if (ALTQ_IS_ATTACHED(&ifp->if_snd)) | 1335 | if (ALTQ_IS_ATTACHED(&ifp->if_snd)) | |
1344 | altq_detach(&ifp->if_snd); | 1336 | altq_detach(&ifp->if_snd); | |
1345 | #endif | 1337 | #endif | |
1346 | 1338 | |||
1347 | mutex_obj_free(ifp->if_snd.ifq_lock); | 1339 | mutex_obj_free(ifp->if_snd.ifq_lock); | |
1348 | 1340 | |||
1349 | #if NCARP > 0 | 1341 | #if NCARP > 0 | |
1350 | /* Remove the interface from any carp group it is a part of. */ | 1342 | /* Remove the interface from any carp group it is a part of. */ | |
1351 | if (ifp->if_carp != NULL && ifp->if_type != IFT_CARP) | 1343 | if (ifp->if_carp != NULL && ifp->if_type != IFT_CARP) | |
@@ -1358,29 +1350,31 @@ if_detach(struct ifnet *ifp) | @@ -1358,29 +1350,31 @@ if_detach(struct ifnet *ifp) | |||
1358 | * | 1350 | * | |
1359 | * pr_usrreq calls can remove an arbitrary number of ifaddrs | 1351 | * pr_usrreq calls can remove an arbitrary number of ifaddrs | |
1360 | * from the list, including our "cursor", ifa. For safety, | 1352 | * from the list, including our "cursor", ifa. For safety, | |
1361 | * and to honor the TAILQ abstraction, I just restart the | 1353 | * and to honor the TAILQ abstraction, I just restart the | |
1362 | * loop after each removal. Note that the loop will exit | 1354 | * loop after each removal. Note that the loop will exit | |
1363 | * when all of the remaining ifaddrs belong to the AF_LINK | 1355 | * when all of the remaining ifaddrs belong to the AF_LINK | |
1364 | * family. I am counting on the historical fact that at | 1356 | * family. I am counting on the historical fact that at | |
1365 | * least one pr_usrreq in each address domain removes at | 1357 | * least one pr_usrreq in each address domain removes at | |
1366 | * least one ifaddr. | 1358 | * least one ifaddr. | |
1367 | */ | 1359 | */ | |
1368 | again: | 1360 | again: | |
1369 | /* | 1361 | /* | |
1370 | * At this point, no other one tries to remove ifa in the list, | 1362 | * At this point, no other one tries to remove ifa in the list, | |
1371 | * so we don't need to take a lock or psref. | 1363 | * so we don't need to take a lock or psref. Avoid using | |
1364 | * IFADDR_READER_FOREACH to pass over an inspection of contract | |||
1365 | * violations of pserialize. | |||
1372 | */ | 1366 | */ | |
1373 | IFADDR_READER_FOREACH(ifa, ifp) { | 1367 | IFADDR_WRITER_FOREACH(ifa, ifp) { | |
1374 | family = ifa->ifa_addr->sa_family; | 1368 | family = ifa->ifa_addr->sa_family; | |
1375 | #ifdef IFAREF_DEBUG | 1369 | #ifdef IFAREF_DEBUG | |
1376 | printf("if_detach: ifaddr %p, family %d, refcnt %d\n", | 1370 | printf("if_detach: ifaddr %p, family %d, refcnt %d\n", | |
1377 | ifa, family, ifa->ifa_refcnt); | 1371 | ifa, family, ifa->ifa_refcnt); | |
1378 | if (last_ifa != NULL && ifa == last_ifa) | 1372 | if (last_ifa != NULL && ifa == last_ifa) | |
1379 | panic("if_detach: loop detected"); | 1373 | panic("if_detach: loop detected"); | |
1380 | last_ifa = ifa; | 1374 | last_ifa = ifa; | |
1381 | #endif | 1375 | #endif | |
1382 | if (family == AF_LINK) | 1376 | if (family == AF_LINK) | |
1383 | continue; | 1377 | continue; | |
1384 | dp = pffinddomain(family); | 1378 | dp = pffinddomain(family); | |
1385 | KASSERTMSG(dp != NULL, "no domain for AF %d", family); | 1379 | KASSERTMSG(dp != NULL, "no domain for AF %d", family); | |
1386 | /* | 1380 | /* | |
@@ -1437,26 +1431,37 @@ again: | @@ -1437,26 +1431,37 @@ again: | |||
1437 | * Because there is no invariant that multicast | 1431 | * Because there is no invariant that multicast | |
1438 | * memberships only exist for interfaces with IPv4 | 1432 | * memberships only exist for interfaces with IPv4 | |
1439 | * addresses, we must call PURGEIF regardless of | 1433 | * addresses, we must call PURGEIF regardless of | |
1440 | * addresses. (Protocols which might store ifnet | 1434 | * addresses. (Protocols which might store ifnet | |
1441 | * pointers are marked with PR_PURGEIF.) | 1435 | * pointers are marked with PR_PURGEIF.) | |
1442 | */ | 1436 | */ | |
1443 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { | 1437 | for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { | |
1444 | so.so_proto = pr; | 1438 | so.so_proto = pr; | |
1445 | if (pr->pr_usrreqs && pr->pr_flags & PR_PURGEIF) | 1439 | if (pr->pr_usrreqs && pr->pr_flags & PR_PURGEIF) | |
1446 | (void)(*pr->pr_usrreqs->pr_purgeif)(&so, ifp); | 1440 | (void)(*pr->pr_usrreqs->pr_purgeif)(&so, ifp); | |
1447 | } | 1441 | } | |
1448 | } | 1442 | } | |
1449 | 1443 | |||
1444 | /* Wait for all readers to drain before freeing. */ | |||
1445 | IFNET_GLOBAL_LOCK(); | |||
1446 | ifindex2ifnet[ifp->if_index] = NULL; | |||
1447 | TAILQ_REMOVE(&ifnet_list, ifp, if_list); | |||
1448 | IFNET_WRITER_REMOVE(ifp); | |||
1449 | pserialize_perform(ifnet_psz); | |||
1450 | IFNET_GLOBAL_UNLOCK(); | |||
1451 | ||||
1452 | psref_target_destroy(&ifp->if_psref, ifnet_psref_class); | |||
1453 | PSLIST_ENTRY_DESTROY(ifp, if_pslist_entry); | |||
1454 | ||||
1450 | pfil_run_ifhooks(if_pfil, PFIL_IFNET_DETACH, ifp); | 1455 | pfil_run_ifhooks(if_pfil, PFIL_IFNET_DETACH, ifp); | |
1451 | (void)pfil_head_destroy(ifp->if_pfil); | 1456 | (void)pfil_head_destroy(ifp->if_pfil); | |
1452 | 1457 | |||
1453 | /* Announce that the interface is gone. */ | 1458 | /* Announce that the interface is gone. */ | |
1454 | rt_ifannouncemsg(ifp, IFAN_DEPARTURE); | 1459 | rt_ifannouncemsg(ifp, IFAN_DEPARTURE); | |
1455 | 1460 | |||
1456 | IF_AFDATA_LOCK_DESTROY(ifp); | 1461 | IF_AFDATA_LOCK_DESTROY(ifp); | |
1457 | 1462 | |||
1458 | if (if_is_link_state_changeable(ifp)) { | 1463 | if (if_is_link_state_changeable(ifp)) { | |
1459 | softint_disestablish(ifp->if_link_si); | 1464 | softint_disestablish(ifp->if_link_si); | |
1460 | ifp->if_link_si = NULL; | 1465 | ifp->if_link_si = NULL; | |
1461 | } | 1466 | } | |
1462 | 1467 | |||
@@ -1483,26 +1488,29 @@ again: | @@ -1483,26 +1488,29 @@ again: | |||
1483 | #endif | 1488 | #endif | |
1484 | #ifdef INET6 | 1489 | #ifdef INET6 | |
1485 | if (in6_present) | 1490 | if (in6_present) | |
1486 | pktq_barrier(ip6_pktq); | 1491 | pktq_barrier(ip6_pktq); | |
1487 | #endif | 1492 | #endif | |
1488 | xc = xc_broadcast(0, (xcfunc_t)nullop, NULL, NULL); | 1493 | xc = xc_broadcast(0, (xcfunc_t)nullop, NULL, NULL); | |
1489 | xc_wait(xc); | 1494 | xc_wait(xc); | |
1490 | 1495 | |||
1491 | if (ifp->if_percpuq != NULL) { | 1496 | if (ifp->if_percpuq != NULL) { | |
1492 | if_percpuq_destroy(ifp->if_percpuq); | 1497 | if_percpuq_destroy(ifp->if_percpuq); | |
1493 | ifp->if_percpuq = NULL; | 1498 | ifp->if_percpuq = NULL; | |
1494 | } | 1499 | } | |
1495 | 1500 | |||
1501 | mutex_obj_free(ifp->if_ioctl_lock); | |||
1502 | ifp->if_ioctl_lock = NULL; | |||
1503 | ||||
1496 | splx(s); | 1504 | splx(s); | |
1497 | 1505 | |||
1498 | #ifdef IFAREF_DEBUG | 1506 | #ifdef IFAREF_DEBUG | |
1499 | if_check_and_free_ifa_list(ifp); | 1507 | if_check_and_free_ifa_list(ifp); | |
1500 | #endif | 1508 | #endif | |
1501 | } | 1509 | } | |
1502 | 1510 | |||
1503 | static void | 1511 | static void | |
1504 | if_detach_queues(struct ifnet *ifp, struct ifqueue *q) | 1512 | if_detach_queues(struct ifnet *ifp, struct ifqueue *q) | |
1505 | { | 1513 | { | |
1506 | struct mbuf *m, *prev, *next; | 1514 | struct mbuf *m, *prev, *next; | |
1507 | 1515 | |||
1508 | prev = NULL; | 1516 | prev = NULL; | |
@@ -1584,29 +1592,29 @@ if_clone_destroy(const char *name) | @@ -1584,29 +1592,29 @@ if_clone_destroy(const char *name) | |||
1584 | 1592 | |||
1585 | ifc = if_clone_lookup(name, NULL); | 1593 | ifc = if_clone_lookup(name, NULL); | |
1586 | if (ifc == NULL) | 1594 | if (ifc == NULL) | |
1587 | return EINVAL; | 1595 | return EINVAL; | |
1588 | 1596 | |||
1589 | if (ifc->ifc_destroy == NULL) | 1597 | if (ifc->ifc_destroy == NULL) | |
1590 | return EOPNOTSUPP; | 1598 | return EOPNOTSUPP; | |
1591 | 1599 | |||
1592 | ifp = if_get(name, &psref); | 1600 | ifp = if_get(name, &psref); | |
1593 | if (ifp == NULL) | 1601 | if (ifp == NULL) | |
1594 | return ENXIO; | 1602 | return ENXIO; | |
1595 | 1603 | |||
1596 | /* We have to disable ioctls here */ | 1604 | /* We have to disable ioctls here */ | |
1597 | mutex_enter(ifp->if_ioctl_lock); | 1605 | IFNET_LOCK(ifp); | |
1598 | ifp->if_ioctl = if_nullioctl; | 1606 | ifp->if_ioctl = if_nullioctl; | |
1599 | mutex_exit(ifp->if_ioctl_lock); | 1607 | IFNET_UNLOCK(ifp); | |
1600 | 1608 | |||
1601 | /* | 1609 | /* | |
1602 | * We cannot call ifc_destroy with holding ifp. | 1610 | * We cannot call ifc_destroy with holding ifp. | |
1603 | * Releasing ifp here is safe thanks to if_clone_mtx. | 1611 | * Releasing ifp here is safe thanks to if_clone_mtx. | |
1604 | */ | 1612 | */ | |
1605 | if_put(ifp, &psref); | 1613 | if_put(ifp, &psref); | |
1606 | 1614 | |||
1607 | return (*ifc->ifc_destroy)(ifp); | 1615 | return (*ifc->ifc_destroy)(ifp); | |
1608 | } | 1616 | } | |
1609 | 1617 | |||
1610 | static bool | 1618 | static bool | |
1611 | if_is_unit(const char *name) | 1619 | if_is_unit(const char *name) | |
1612 | { | 1620 | { | |
@@ -1773,48 +1781,60 @@ ifafree(struct ifaddr *ifa) | @@ -1773,48 +1781,60 @@ ifafree(struct ifaddr *ifa) | |||
1773 | bool | 1781 | bool | |
1774 | ifa_is_destroying(struct ifaddr *ifa) | 1782 | ifa_is_destroying(struct ifaddr *ifa) | |
1775 | { | 1783 | { | |
1776 | 1784 | |||
1777 | return ISSET(ifa->ifa_flags, IFA_DESTROYING); | 1785 | return ISSET(ifa->ifa_flags, IFA_DESTROYING); | |
1778 | } | 1786 | } | |
1779 | 1787 | |||
1780 | void | 1788 | void | |
1781 | ifa_insert(struct ifnet *ifp, struct ifaddr *ifa) | 1789 | ifa_insert(struct ifnet *ifp, struct ifaddr *ifa) | |
1782 | { | 1790 | { | |
1783 | 1791 | |||
1784 | ifa->ifa_ifp = ifp; | 1792 | ifa->ifa_ifp = ifp; | |
1785 | 1793 | |||
1786 | IFNET_LOCK(); | 1794 | /* | |
1795 | * Check !IFF_RUNNING for initialization routines that normally don't | |||
1796 | * take IFNET_LOCK but it's safe because there is no competitor. | |||
1797 | * XXX there are false positive cases because IFF_RUNNING can be off on | |||
1798 | * if_stop. | |||
1799 | */ | |||
1800 | KASSERT(!ISSET(ifp->if_flags, IFF_RUNNING) || | |||
1801 | IFNET_LOCKED(ifp)); | |||
1802 | ||||
1787 | TAILQ_INSERT_TAIL(&ifp->if_addrlist, ifa, ifa_list); | 1803 | TAILQ_INSERT_TAIL(&ifp->if_addrlist, ifa, ifa_list); | |
1788 | IFADDR_ENTRY_INIT(ifa); | 1804 | IFADDR_ENTRY_INIT(ifa); | |
1789 | IFADDR_WRITER_INSERT_TAIL(ifp, ifa); | 1805 | IFADDR_WRITER_INSERT_TAIL(ifp, ifa); | |
1790 | IFNET_UNLOCK(); | |||
1791 | 1806 | |||
1792 | ifaref(ifa); | 1807 | ifaref(ifa); | |
1793 | } | 1808 | } | |
1794 | 1809 | |||
1795 | void | 1810 | void | |
1796 | ifa_remove(struct ifnet *ifp, struct ifaddr *ifa) | 1811 | ifa_remove(struct ifnet *ifp, struct ifaddr *ifa) | |
1797 | { | 1812 | { | |
1798 | 1813 | |||
1799 | KASSERT(ifa->ifa_ifp == ifp); | 1814 | KASSERT(ifa->ifa_ifp == ifp); | |
1815 | /* | |||
1816 | * if_is_deactivated indicates ifa_remove is called form if_detach | |||
1817 | * where is safe even if IFNET_LOCK isn't held. | |||
1818 | */ | |||
1819 | KASSERT(if_is_deactivated(ifp) || IFNET_LOCKED(ifp)); | |||
1800 | 1820 | |||
1801 | IFNET_LOCK(); | |||
1802 | TAILQ_REMOVE(&ifp->if_addrlist, ifa, ifa_list); | 1821 | TAILQ_REMOVE(&ifp->if_addrlist, ifa, ifa_list); | |
1803 | IFADDR_WRITER_REMOVE(ifa); | 1822 | IFADDR_WRITER_REMOVE(ifa); | |
1804 | #ifdef NET_MPSAFE | 1823 | #ifdef NET_MPSAFE | |
1824 | IFNET_GLOBAL_LOCK(); | |||
1805 | pserialize_perform(ifnet_psz); | 1825 | pserialize_perform(ifnet_psz); | |
1826 | IFNET_GLOBAL_UNLOCK(); | |||
1806 | #endif | 1827 | #endif | |
1807 | IFNET_UNLOCK(); | |||
1808 | 1828 | |||
1809 | #ifdef NET_MPSAFE | 1829 | #ifdef NET_MPSAFE | |
1810 | psref_target_destroy(&ifa->ifa_psref, ifa_psref_class); | 1830 | psref_target_destroy(&ifa->ifa_psref, ifa_psref_class); | |
1811 | #endif | 1831 | #endif | |
1812 | IFADDR_ENTRY_DESTROY(ifa); | 1832 | IFADDR_ENTRY_DESTROY(ifa); | |
1813 | ifafree(ifa); | 1833 | ifafree(ifa); | |
1814 | } | 1834 | } | |
1815 | 1835 | |||
1816 | void | 1836 | void | |
1817 | ifa_acquire(struct ifaddr *ifa, struct psref *psref) | 1837 | ifa_acquire(struct ifaddr *ifa, struct psref *psref) | |
1818 | { | 1838 | { | |
1819 | 1839 | |||
1820 | psref_acquire(psref, &ifa->ifa_psref, ifa_psref_class); | 1840 | psref_acquire(psref, &ifa->ifa_psref, ifa_psref_class); | |
@@ -2174,54 +2194,69 @@ link_rtrequest(int cmd, struct rtentry * | @@ -2174,54 +2194,69 @@ link_rtrequest(int cmd, struct rtentry * | |||
2174 | (q) >>= LQ_ITEM_BITS; \ | 2194 | (q) >>= LQ_ITEM_BITS; \ | |
2175 | (q) |= LINK_STATE_UNSET << (LQ_MAX((q)) - 1) * LQ_ITEM_BITS; \ | 2195 | (q) |= LINK_STATE_UNSET << (LQ_MAX((q)) - 1) * LQ_ITEM_BITS; \ | |
2176 | } while (0 /* CONSTCOND */) | 2196 | } while (0 /* CONSTCOND */) | |
2177 | #define LQ_PUSH(q, v) \ | 2197 | #define LQ_PUSH(q, v) \ | |
2178 | do { \ | 2198 | do { \ | |
2179 | (q) >>= LQ_ITEM_BITS; \ | 2199 | (q) >>= LQ_ITEM_BITS; \ | |
2180 | (q) |= (v) << (LQ_MAX((q)) - 1) * LQ_ITEM_BITS; \ | 2200 | (q) |= (v) << (LQ_MAX((q)) - 1) * LQ_ITEM_BITS; \ | |
2181 | } while (0 /* CONSTCOND */) | 2201 | } while (0 /* CONSTCOND */) | |
2182 | #define LQ_FIND_UNSET(q, i) \ | 2202 | #define LQ_FIND_UNSET(q, i) \ | |
2183 | for ((i) = 0; i < LQ_MAX((q)); (i)++) { \ | 2203 | for ((i) = 0; i < LQ_MAX((q)); (i)++) { \ | |
2184 | if (LQ_ITEM((q), (i)) == LINK_STATE_UNSET) \ | 2204 | if (LQ_ITEM((q), (i)) == LINK_STATE_UNSET) \ | |
2185 | break; \ | 2205 | break; \ | |
2186 | } | 2206 | } | |
2207 | ||||
2208 | /* | |||
2209 | * XXX reusing (ifp)->if_snd->ifq_lock rather than having another spin mutex | |||
2210 | * for each ifnet. It doesn't matter because: | |||
2211 | * - if IFEF_MPSAFE is enabled, if_snd isn't used and lock contentions on | |||
2212 | * ifq_lock don't happen | |||
2213 | * - if IFEF_MPSAFE is disabled, there is no lock contention on ifq_lock | |||
2214 | * because if_snd, if_link_state_change and if_link_state_change_softint | |||
2215 | * are all called with KERNEL_LOCK | |||
2216 | */ | |||
2217 | #define IF_LINK_STATE_CHANGE_LOCK(ifp) \ | |||
2218 | mutex_enter((ifp)->if_snd.ifq_lock) | |||
2219 | #define IF_LINK_STATE_CHANGE_UNLOCK(ifp) \ | |||
2220 | mutex_exit((ifp)->if_snd.ifq_lock) | |||
2221 | ||||
2187 | /* | 2222 | /* | |
2188 | * Handle a change in the interface link state and | 2223 | * Handle a change in the interface link state and | |
2189 | * queue notifications. | 2224 | * queue notifications. | |
2190 | */ | 2225 | */ | |
2191 | void | 2226 | void | |
2192 | if_link_state_change(struct ifnet *ifp, int link_state) | 2227 | if_link_state_change(struct ifnet *ifp, int link_state) | |
2193 | { | 2228 | { | |
2194 | int s, idx; | 2229 | int idx; | |
2195 | 2230 | |||
2196 | KASSERTMSG(if_is_link_state_changeable(ifp), | 2231 | KASSERTMSG(if_is_link_state_changeable(ifp), | |
2197 | "%s: IFEF_NO_LINK_STATE_CHANGE must not be set, but if_extflags=0x%x", | 2232 | "%s: IFEF_NO_LINK_STATE_CHANGE must not be set, but if_extflags=0x%x", | |
2198 | ifp->if_xname, ifp->if_extflags); | 2233 | ifp->if_xname, ifp->if_extflags); | |
2199 | 2234 | |||
2200 | /* Ensure change is to a valid state */ | 2235 | /* Ensure change is to a valid state */ | |
2201 | switch (link_state) { | 2236 | switch (link_state) { | |
2202 | case LINK_STATE_UNKNOWN: /* FALLTHROUGH */ | 2237 | case LINK_STATE_UNKNOWN: /* FALLTHROUGH */ | |
2203 | case LINK_STATE_DOWN: /* FALLTHROUGH */ | 2238 | case LINK_STATE_DOWN: /* FALLTHROUGH */ | |
2204 | case LINK_STATE_UP: | 2239 | case LINK_STATE_UP: | |
2205 | break; | 2240 | break; | |
2206 | default: | 2241 | default: | |
2207 | #ifdef DEBUG | 2242 | #ifdef DEBUG | |
2208 | printf("%s: invalid link state %d\n", | 2243 | printf("%s: invalid link state %d\n", | |
2209 | ifp->if_xname, link_state); | 2244 | ifp->if_xname, link_state); | |
2210 | #endif | 2245 | #endif | |
2211 | return; | 2246 | return; | |
2212 | } | 2247 | } | |
2213 | 2248 | |||
2214 | s = splnet(); | 2249 | IF_LINK_STATE_CHANGE_LOCK(ifp); | |
2215 | 2250 | |||
2216 | /* Find the last unset event in the queue. */ | 2251 | /* Find the last unset event in the queue. */ | |
2217 | LQ_FIND_UNSET(ifp->if_link_queue, idx); | 2252 | LQ_FIND_UNSET(ifp->if_link_queue, idx); | |
2218 | 2253 | |||
2219 | /* | 2254 | /* | |
2220 | * Ensure link_state doesn't match the last event in the queue. | 2255 | * Ensure link_state doesn't match the last event in the queue. | |
2221 | * ifp->if_link_state is not checked and set here because | 2256 | * ifp->if_link_state is not checked and set here because | |
2222 | * that would present an inconsistent picture to the system. | 2257 | * that would present an inconsistent picture to the system. | |
2223 | */ | 2258 | */ | |
2224 | if (idx != 0 && | 2259 | if (idx != 0 && | |
2225 | LQ_ITEM(ifp->if_link_queue, idx - 1) == (uint8_t)link_state) | 2260 | LQ_ITEM(ifp->if_link_queue, idx - 1) == (uint8_t)link_state) | |
2226 | goto out; | 2261 | goto out; | |
2227 | 2262 | |||
@@ -2245,121 +2280,129 @@ if_link_state_change(struct ifnet *ifp, | @@ -2245,121 +2280,129 @@ if_link_state_change(struct ifnet *ifp, | |||
2245 | LQ_STORE(ifp->if_link_queue, 0, LINK_STATE_DOWN); | 2280 | LQ_STORE(ifp->if_link_queue, 0, LINK_STATE_DOWN); | |
2246 | } | 2281 | } | |
2247 | printf("%s: lost link state change %s\n", | 2282 | printf("%s: lost link state change %s\n", | |
2248 | ifp->if_xname, | 2283 | ifp->if_xname, | |
2249 | lost == LINK_STATE_UP ? "UP" : | 2284 | lost == LINK_STATE_UP ? "UP" : | |
2250 | lost == LINK_STATE_DOWN ? "DOWN" : | 2285 | lost == LINK_STATE_DOWN ? "DOWN" : | |
2251 | "UNKNOWN"); | 2286 | "UNKNOWN"); | |
2252 | } else | 2287 | } else | |
2253 | LQ_STORE(ifp->if_link_queue, idx, (uint8_t)link_state); | 2288 | LQ_STORE(ifp->if_link_queue, idx, (uint8_t)link_state); | |
2254 | 2289 | |||
2255 | softint_schedule(ifp->if_link_si); | 2290 | softint_schedule(ifp->if_link_si); | |
2256 | 2291 | |||
2257 | out: | 2292 | out: | |
2258 | splx(s); | 2293 | IF_LINK_STATE_CHANGE_UNLOCK(ifp); | |
2259 | } | 2294 | } | |
2260 | 2295 | |||
2261 | /* | 2296 | /* | |
2262 | * Handle interface link state change notifications. | 2297 | * Handle interface link state change notifications. | |
2263 | */ | 2298 | */ | |
2264 | void | 2299 | void | |
2265 | if_link_state_change_softint(struct ifnet *ifp, int link_state) | 2300 | if_link_state_change_softint(struct ifnet *ifp, int link_state) | |
2266 | { | 2301 | { | |
2267 | struct domain *dp; | 2302 | struct domain *dp; | |
2268 | int s = splnet(); | 2303 | int s = splnet(); | |
2304 | bool notify; | |||
2269 | 2305 | |||
2270 | KASSERT(!cpu_intr_p()); | 2306 | KASSERT(!cpu_intr_p()); | |
2271 | 2307 | |||
2308 | IF_LINK_STATE_CHANGE_LOCK(ifp); | |||
2309 | ||||
2272 | /* Ensure the change is still valid. */ | 2310 | /* Ensure the change is still valid. */ | |
2273 | if (ifp->if_link_state == link_state) { | 2311 | if (ifp->if_link_state == link_state) { | |
2274 | splx(s); | 2312 | IF_LINK_STATE_CHANGE_UNLOCK(ifp); | |
2275 | return; | 2313 | return; | |
2276 | } | 2314 | } | |
2277 | 2315 | |||
2278 | #ifdef DEBUG | 2316 | #ifdef DEBUG | |
2279 | log(LOG_DEBUG, "%s: link state %s (was %s)\n", ifp->if_xname, | 2317 | log(LOG_DEBUG, "%s: link state %s (was %s)\n", ifp->if_xname, | |
2280 | link_state == LINK_STATE_UP ? "UP" : | 2318 | link_state == LINK_STATE_UP ? "UP" : | |
2281 | link_state == LINK_STATE_DOWN ? "DOWN" : | 2319 | link_state == LINK_STATE_DOWN ? "DOWN" : | |
2282 | "UNKNOWN", | 2320 | "UNKNOWN", | |
2283 | ifp->if_link_state == LINK_STATE_UP ? "UP" : | 2321 | ifp->if_link_state == LINK_STATE_UP ? "UP" : | |
2284 | ifp->if_link_state == LINK_STATE_DOWN ? "DOWN" : | 2322 | ifp->if_link_state == LINK_STATE_DOWN ? "DOWN" : | |
2285 | "UNKNOWN"); | 2323 | "UNKNOWN"); | |
2286 | #endif | 2324 | #endif | |
2287 | 2325 | |||
2288 | /* | 2326 | /* | |
2289 | * When going from UNKNOWN to UP, we need to mark existing | 2327 | * When going from UNKNOWN to UP, we need to mark existing | |
2290 | * addresses as tentative and restart DAD as we may have | 2328 | * addresses as tentative and restart DAD as we may have | |
2291 | * erroneously not found a duplicate. | 2329 | * erroneously not found a duplicate. | |
2292 | * | 2330 | * | |
2293 | * This needs to happen before rt_ifmsg to avoid a race where | 2331 | * This needs to happen before rt_ifmsg to avoid a race where | |
2294 | * listeners would have an address and expect it to work right | 2332 | * listeners would have an address and expect it to work right | |
2295 | * away. | 2333 | * away. | |
2296 | */ | 2334 | */ | |
2297 | if (link_state == LINK_STATE_UP && | 2335 | notify = (link_state == LINK_STATE_UP && | |
2298 | ifp->if_link_state == LINK_STATE_UNKNOWN) | 2336 | ifp->if_link_state == LINK_STATE_UNKNOWN); | |
2299 | { | 2337 | ifp->if_link_state = link_state; | |
2338 | /* The following routines may sleep so release the spin mutex */ | |||
2339 | IF_LINK_STATE_CHANGE_UNLOCK(ifp); | |||
2340 | ||||
2341 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |||
2342 | if (notify) { | |||
2300 | DOMAIN_FOREACH(dp) { | 2343 | DOMAIN_FOREACH(dp) { | |
2301 | if (dp->dom_if_link_state_change != NULL) | 2344 | if (dp->dom_if_link_state_change != NULL) | |
2302 | dp->dom_if_link_state_change(ifp, | 2345 | dp->dom_if_link_state_change(ifp, | |
2303 | LINK_STATE_DOWN); | 2346 | LINK_STATE_DOWN); | |
2304 | } | 2347 | } | |
2305 | } | 2348 | } | |
2306 | 2349 | |||
2307 | ifp->if_link_state = link_state; | |||
2308 | ||||
2309 | /* Notify that the link state has changed. */ | 2350 | /* Notify that the link state has changed. */ | |
2310 | rt_ifmsg(ifp); | 2351 | rt_ifmsg(ifp); | |
2311 | 2352 | |||
2312 | #if NCARP > 0 | 2353 | #if NCARP > 0 | |
2313 | if (ifp->if_carp) | 2354 | if (ifp->if_carp) | |
2314 | carp_carpdev_state(ifp); | 2355 | carp_carpdev_state(ifp); | |
2315 | #endif | 2356 | #endif | |
2316 | 2357 | |||
2317 | DOMAIN_FOREACH(dp) { | 2358 | DOMAIN_FOREACH(dp) { | |
2318 | if (dp->dom_if_link_state_change != NULL) | 2359 | if (dp->dom_if_link_state_change != NULL) | |
2319 | dp->dom_if_link_state_change(ifp, link_state); | 2360 | dp->dom_if_link_state_change(ifp, link_state); | |
2320 | } | 2361 | } | |
2362 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |||
2321 | splx(s); | 2363 | splx(s); | |
2322 | } | 2364 | } | |
2323 | 2365 | |||
2324 | /* | 2366 | /* | |
2325 | * Process the interface link state change queue. | 2367 | * Process the interface link state change queue. | |
2326 | */ | 2368 | */ | |
2327 | static void | 2369 | static void | |
2328 | if_link_state_change_si(void *arg) | 2370 | if_link_state_change_si(void *arg) | |
2329 | { | 2371 | { | |
2330 | struct ifnet *ifp = arg; | 2372 | struct ifnet *ifp = arg; | |
2331 | int s; | 2373 | int s; | |
2332 | uint8_t state; | 2374 | uint8_t state; | |
2375 | bool schedule; | |||
2333 | 2376 | |||
2334 | #ifndef NET_MPSAFE | 2377 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
2335 | mutex_enter(softnet_lock); | |||
2336 | KERNEL_LOCK(1, NULL); | |||
2337 | #endif | |||
2338 | s = splnet(); | 2378 | s = splnet(); | |
2339 | 2379 | |||
2340 | /* Pop a link state change from the queue and process it. */ | 2380 | /* Pop a link state change from the queue and process it. */ | |
2381 | IF_LINK_STATE_CHANGE_LOCK(ifp); | |||
2341 | LQ_POP(ifp->if_link_queue, state); | 2382 | LQ_POP(ifp->if_link_queue, state); | |
2383 | IF_LINK_STATE_CHANGE_UNLOCK(ifp); | |||
2384 | ||||
2342 | if_link_state_change_softint(ifp, state); | 2385 | if_link_state_change_softint(ifp, state); | |
2343 | 2386 | |||
2344 | /* If there is a link state change to come, schedule it. */ | 2387 | /* If there is a link state change to come, schedule it. */ | |
2345 | if (LQ_ITEM(ifp->if_link_queue, 0) != LINK_STATE_UNSET) | 2388 | IF_LINK_STATE_CHANGE_LOCK(ifp); | |
2389 | schedule = (LQ_ITEM(ifp->if_link_queue, 0) != LINK_STATE_UNSET); | |||
2390 | IF_LINK_STATE_CHANGE_UNLOCK(ifp); | |||
2391 | if (schedule) | |||
2346 | softint_schedule(ifp->if_link_si); | 2392 | softint_schedule(ifp->if_link_si); | |
2347 | 2393 | |||
2348 | splx(s); | 2394 | splx(s); | |
2349 | #ifndef NET_MPSAFE | 2395 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
2350 | KERNEL_UNLOCK_ONE(NULL); | |||
2351 | mutex_exit(softnet_lock); | |||
2352 | #endif | |||
2353 | } | 2396 | } | |
2354 | 2397 | |||
2355 | /* | 2398 | /* | |
2356 | * Default action when installing a local route on a point-to-point | 2399 | * Default action when installing a local route on a point-to-point | |
2357 | * interface. | 2400 | * interface. | |
2358 | */ | 2401 | */ | |
2359 | void | 2402 | void | |
2360 | p2p_rtrequest(int req, struct rtentry *rt, | 2403 | p2p_rtrequest(int req, struct rtentry *rt, | |
2361 | __unused const struct rt_addrinfo *info) | 2404 | __unused const struct rt_addrinfo *info) | |
2362 | { | 2405 | { | |
2363 | struct ifnet *ifp = rt->rt_ifp; | 2406 | struct ifnet *ifp = rt->rt_ifp; | |
2364 | struct ifaddr *ifa, *lo0ifa; | 2407 | struct ifaddr *ifa, *lo0ifa; | |
2365 | int s = pserialize_read_enter(); | 2408 | int s = pserialize_read_enter(); | |
@@ -2394,33 +2437,28 @@ p2p_rtrequest(int req, struct rtentry *r | @@ -2394,33 +2437,28 @@ p2p_rtrequest(int req, struct rtentry *r | |||
2394 | * address we are using, otherwise we will have trouble | 2437 | * address we are using, otherwise we will have trouble | |
2395 | * with source address selection. | 2438 | * with source address selection. | |
2396 | */ | 2439 | */ | |
2397 | if (ifa != rt->rt_ifa) | 2440 | if (ifa != rt->rt_ifa) | |
2398 | rt_replace_ifa(rt, ifa); | 2441 | rt_replace_ifa(rt, ifa); | |
2399 | break; | 2442 | break; | |
2400 | case RTM_DELETE: | 2443 | case RTM_DELETE: | |
2401 | default: | 2444 | default: | |
2402 | break; | 2445 | break; | |
2403 | } | 2446 | } | |
2404 | pserialize_read_exit(s); | 2447 | pserialize_read_exit(s); | |
2405 | } | 2448 | } | |
2406 | 2449 | |||
2407 | /* | 2450 | static void | |
2408 | * Mark an interface down and notify protocols of | 2451 | _if_down(struct ifnet *ifp) | |
2409 | * the transition. | |||
2410 | * NOTE: must be called at splsoftnet or equivalent. | |||
2411 | */ | |||
2412 | void | |||
2413 | if_down(struct ifnet *ifp) | |||
2414 | { | 2452 | { | |
2415 | struct ifaddr *ifa; | 2453 | struct ifaddr *ifa; | |
2416 | struct domain *dp; | 2454 | struct domain *dp; | |
2417 | int s, bound; | 2455 | int s, bound; | |
2418 | struct psref psref; | 2456 | struct psref psref; | |
2419 | 2457 | |||
2420 | ifp->if_flags &= ~IFF_UP; | 2458 | ifp->if_flags &= ~IFF_UP; | |
2421 | nanotime(&ifp->if_lastchange); | 2459 | nanotime(&ifp->if_lastchange); | |
2422 | 2460 | |||
2423 | bound = curlwp_bind(); | 2461 | bound = curlwp_bind(); | |
2424 | s = pserialize_read_enter(); | 2462 | s = pserialize_read_enter(); | |
2425 | IFADDR_READER_FOREACH(ifa, ifp) { | 2463 | IFADDR_READER_FOREACH(ifa, ifp) { | |
2426 | ifa_acquire(ifa, &psref); | 2464 | ifa_acquire(ifa, &psref); | |
@@ -2436,39 +2474,70 @@ if_down(struct ifnet *ifp) | @@ -2436,39 +2474,70 @@ if_down(struct ifnet *ifp) | |||
2436 | 2474 | |||
2437 | IFQ_PURGE(&ifp->if_snd); | 2475 | IFQ_PURGE(&ifp->if_snd); | |
2438 | #if NCARP > 0 | 2476 | #if NCARP > 0 | |
2439 | if (ifp->if_carp) | 2477 | if (ifp->if_carp) | |
2440 | carp_carpdev_state(ifp); | 2478 | carp_carpdev_state(ifp); | |
2441 | #endif | 2479 | #endif | |
2442 | rt_ifmsg(ifp); | 2480 | rt_ifmsg(ifp); | |
2443 | DOMAIN_FOREACH(dp) { | 2481 | DOMAIN_FOREACH(dp) { | |
2444 | if (dp->dom_if_down) | 2482 | if (dp->dom_if_down) | |
2445 | dp->dom_if_down(ifp); | 2483 | dp->dom_if_down(ifp); | |
2446 | } | 2484 | } | |
2447 | } | 2485 | } | |
2448 | 2486 | |||
2487 | static void | |||
2488 | if_down_deactivated(struct ifnet *ifp) | |||
2489 | { | |||
2490 | ||||
2491 | KASSERT(if_is_deactivated(ifp)); | |||
2492 | _if_down(ifp); | |||
2493 | } | |||
2494 | ||||
2495 | void | |||
2496 | if_down_locked(struct ifnet *ifp) | |||
2497 | { | |||
2498 | ||||
2499 | KASSERT(IFNET_LOCKED(ifp)); | |||
2500 | _if_down(ifp); | |||
2501 | } | |||
2502 | ||||
2449 | /* | 2503 | /* | |
2450 | * Mark an interface up and notify protocols of | 2504 | * Mark an interface down and notify protocols of | |
2451 | * the transition. | 2505 | * the transition. | |
2452 | * NOTE: must be called at splsoftnet or equivalent. | 2506 | * NOTE: must be called at splsoftnet or equivalent. | |
2453 | */ | 2507 | */ | |
2454 | void | 2508 | void | |
2455 | if_up(struct ifnet *ifp) | 2509 | if_down(struct ifnet *ifp) | |
2510 | { | |||
2511 | ||||
2512 | IFNET_LOCK(ifp); | |||
2513 | if_down_locked(ifp); | |||
2514 | IFNET_UNLOCK(ifp); | |||
2515 | } | |||
2516 | ||||
2517 | /* | |||
2518 | * Must be called with holding if_ioctl_lock. | |||
2519 | */ | |||
2520 | static void | |||
2521 | if_up_locked(struct ifnet *ifp) | |||
2456 | { | 2522 | { | |
2457 | #ifdef notyet | 2523 | #ifdef notyet | |
2458 | struct ifaddr *ifa; | 2524 | struct ifaddr *ifa; | |
2459 | #endif | 2525 | #endif | |
2460 | struct domain *dp; | 2526 | struct domain *dp; | |
2461 | 2527 | |||
2528 | KASSERT(IFNET_LOCKED(ifp)); | |||
2529 | ||||
2530 | KASSERT(!if_is_deactivated(ifp)); | |||
2462 | ifp->if_flags |= IFF_UP; | 2531 | ifp->if_flags |= IFF_UP; | |
2463 | nanotime(&ifp->if_lastchange); | 2532 | nanotime(&ifp->if_lastchange); | |
2464 | #ifdef notyet | 2533 | #ifdef notyet | |
2465 | /* this has no effect on IP, and will kill all ISO connections XXX */ | 2534 | /* this has no effect on IP, and will kill all ISO connections XXX */ | |
2466 | IFADDR_READER_FOREACH(ifa, ifp) | 2535 | IFADDR_READER_FOREACH(ifa, ifp) | |
2467 | pfctlinput(PRC_IFUP, ifa->ifa_addr); | 2536 | pfctlinput(PRC_IFUP, ifa->ifa_addr); | |
2468 | #endif | 2537 | #endif | |
2469 | #if NCARP > 0 | 2538 | #if NCARP > 0 | |
2470 | if (ifp->if_carp) | 2539 | if (ifp->if_carp) | |
2471 | carp_carpdev_state(ifp); | 2540 | carp_carpdev_state(ifp); | |
2472 | #endif | 2541 | #endif | |
2473 | rt_ifmsg(ifp); | 2542 | rt_ifmsg(ifp); | |
2474 | DOMAIN_FOREACH(dp) { | 2543 | DOMAIN_FOREACH(dp) { | |
@@ -2494,60 +2563,89 @@ if_slowtimo(void *arg) | @@ -2494,60 +2563,89 @@ if_slowtimo(void *arg) | |||
2494 | return; | 2563 | return; | |
2495 | 2564 | |||
2496 | s = splnet(); | 2565 | s = splnet(); | |
2497 | if (ifp->if_timer != 0 && --ifp->if_timer == 0) | 2566 | if (ifp->if_timer != 0 && --ifp->if_timer == 0) | |
2498 | (*slowtimo)(ifp); | 2567 | (*slowtimo)(ifp); | |
2499 | 2568 | |||
2500 | splx(s); | 2569 | splx(s); | |
2501 | 2570 | |||
2502 | if (__predict_true(ifp->if_slowtimo != NULL)) | 2571 | if (__predict_true(ifp->if_slowtimo != NULL)) | |
2503 | callout_schedule(ifp->if_slowtimo_ch, hz / IFNET_SLOWHZ); | 2572 | callout_schedule(ifp->if_slowtimo_ch, hz / IFNET_SLOWHZ); | |
2504 | } | 2573 | } | |
2505 | 2574 | |||
2506 | /* | 2575 | /* | |
2576 | * Mark an interface up and notify protocols of | |||
2577 | * the transition. | |||
2578 | * NOTE: must be called at splsoftnet or equivalent. | |||
2579 | */ | |||
2580 | void | |||
2581 | if_up(struct ifnet *ifp) | |||
2582 | { | |||
2583 | ||||
2584 | IFNET_LOCK(ifp); | |||
2585 | if_up_locked(ifp); | |||
2586 | IFNET_UNLOCK(ifp); | |||
2587 | } | |||
2588 | ||||
2589 | /* | |||
2507 | * Set/clear promiscuous mode on interface ifp based on the truth value | 2590 | * Set/clear promiscuous mode on interface ifp based on the truth value | |
2508 | * of pswitch. The calls are reference counted so that only the first | 2591 | * of pswitch. The calls are reference counted so that only the first | |
2509 | * "on" request actually has an effect, as does the final "off" request. | 2592 | * "on" request actually has an effect, as does the final "off" request. | |
2510 | * Results are undefined if the "off" and "on" requests are not matched. | 2593 | * Results are undefined if the "off" and "on" requests are not matched. | |
2511 | */ | 2594 | */ | |
2512 | int | 2595 | int | |
2513 | ifpromisc(struct ifnet *ifp, int pswitch) | 2596 | ifpromisc_locked(struct ifnet *ifp, int pswitch) | |
2514 | { | 2597 | { | |
2515 | int pcount, ret; | 2598 | int pcount, ret = 0; | |
2516 | short nflags; | 2599 | short nflags; | |
2517 | 2600 | |||
2601 | KASSERT(IFNET_LOCKED(ifp)); | |||
2602 | ||||
2518 | pcount = ifp->if_pcount; | 2603 | pcount = ifp->if_pcount; | |
2519 | if (pswitch) { | 2604 | if (pswitch) { | |
2520 | /* | 2605 | /* | |
2521 | * Allow the device to be "placed" into promiscuous | 2606 | * Allow the device to be "placed" into promiscuous | |
2522 | * mode even if it is not configured up. It will | 2607 | * mode even if it is not configured up. It will | |
2523 | * consult IFF_PROMISC when it is brought up. | 2608 | * consult IFF_PROMISC when it is brought up. | |
2524 | */ | 2609 | */ | |
2525 | if (ifp->if_pcount++ != 0) | 2610 | if (ifp->if_pcount++ != 0) | |
2526 | return 0; | 2611 | goto out; | |
2527 | nflags = ifp->if_flags | IFF_PROMISC; | 2612 | nflags = ifp->if_flags | IFF_PROMISC; | |
2528 | } else { | 2613 | } else { | |
2529 | if (--ifp->if_pcount > 0) | 2614 | if (--ifp->if_pcount > 0) | |
2530 | return 0; | 2615 | goto out; | |
2531 | nflags = ifp->if_flags & ~IFF_PROMISC; | 2616 | nflags = ifp->if_flags & ~IFF_PROMISC; | |
2532 | } | 2617 | } | |
2533 | ret = if_flags_set(ifp, nflags); | 2618 | ret = if_flags_set(ifp, nflags); | |
2534 | /* Restore interface state if not successful. */ | 2619 | /* Restore interface state if not successful. */ | |
2535 | if (ret != 0) { | 2620 | if (ret != 0) { | |
2536 | ifp->if_pcount = pcount; | 2621 | ifp->if_pcount = pcount; | |
2537 | } | 2622 | } | |
2623 | out: | |||
2538 | return ret; | 2624 | return ret; | |
2539 | } | 2625 | } | |
2540 | 2626 | |||
2627 | int | |||
2628 | ifpromisc(struct ifnet *ifp, int pswitch) | |||
2629 | { | |||
2630 | int e; | |||
2631 | ||||
2632 | IFNET_LOCK(ifp); | |||
2633 | e = ifpromisc_locked(ifp, pswitch); | |||
2634 | IFNET_UNLOCK(ifp); | |||
2635 | ||||
2636 | return e; | |||
2637 | } | |||
2638 | ||||
2541 | /* | 2639 | /* | |
2542 | * Map interface name to | 2640 | * Map interface name to | |
2543 | * interface structure pointer. | 2641 | * interface structure pointer. | |
2544 | */ | 2642 | */ | |
2545 | struct ifnet * | 2643 | struct ifnet * | |
2546 | ifunit(const char *name) | 2644 | ifunit(const char *name) | |
2547 | { | 2645 | { | |
2548 | struct ifnet *ifp; | 2646 | struct ifnet *ifp; | |
2549 | const char *cp = name; | 2647 | const char *cp = name; | |
2550 | u_int unit = 0; | 2648 | u_int unit = 0; | |
2551 | u_int i; | 2649 | u_int i; | |
2552 | int s; | 2650 | int s; | |
2553 | 2651 | |||
@@ -2624,32 +2722,47 @@ out: | @@ -2624,32 +2722,47 @@ out: | |||
2624 | * Release a reference of an ifnet object given by if_get, if_get_byindex | 2722 | * Release a reference of an ifnet object given by if_get, if_get_byindex | |
2625 | * or if_get_bylla. | 2723 | * or if_get_bylla. | |
2626 | */ | 2724 | */ | |
2627 | void | 2725 | void | |
2628 | if_put(const struct ifnet *ifp, struct psref *psref) | 2726 | if_put(const struct ifnet *ifp, struct psref *psref) | |
2629 | { | 2727 | { | |
2630 | 2728 | |||
2631 | if (ifp == NULL) | 2729 | if (ifp == NULL) | |
2632 | return; | 2730 | return; | |
2633 | 2731 | |||
2634 | psref_release(psref, &ifp->if_psref, ifnet_psref_class); | 2732 | psref_release(psref, &ifp->if_psref, ifnet_psref_class); | |
2635 | } | 2733 | } | |
2636 | 2734 | |||
2735 | /* | |||
2736 | * Return ifp having idx. Return NULL if not found. Normally if_byindex | |||
2737 | * should be used. | |||
2738 | */ | |||
2739 | ifnet_t * | |||
2740 | _if_byindex(u_int idx) | |||
2741 | { | |||
2742 | ||||
2743 | return (__predict_true(idx < if_indexlim)) ? ifindex2ifnet[idx] : NULL; | |||
2744 | } | |||
2745 | ||||
2746 | /* | |||
2747 | * Return ifp having idx. Return NULL if not found or the found ifp is | |||
2748 | * already deactivated. | |||
2749 | */ | |||
2637 | ifnet_t * | 2750 | ifnet_t * | |
2638 | if_byindex(u_int idx) | 2751 | if_byindex(u_int idx) | |
2639 | { | 2752 | { | |
2640 | ifnet_t *ifp; | 2753 | ifnet_t *ifp; | |
2641 | 2754 | |||
2642 | ifp = (__predict_true(idx < if_indexlim)) ? ifindex2ifnet[idx] : NULL; | 2755 | ifp = _if_byindex(idx); | |
2643 | if (ifp != NULL && if_is_deactivated(ifp)) | 2756 | if (ifp != NULL && if_is_deactivated(ifp)) | |
2644 | ifp = NULL; | 2757 | ifp = NULL; | |
2645 | return ifp; | 2758 | return ifp; | |
2646 | } | 2759 | } | |
2647 | 2760 | |||
2648 | /* | 2761 | /* | |
2649 | * Get a reference of an ifnet object by an interface index. | 2762 | * Get a reference of an ifnet object by an interface index. | |
2650 | * The returned reference is protected by psref(9). The caller | 2763 | * The returned reference is protected by psref(9). The caller | |
2651 | * must release a returned reference by if_put after use. | 2764 | * must release a returned reference by if_put after use. | |
2652 | */ | 2765 | */ | |
2653 | ifnet_t * | 2766 | ifnet_t * | |
2654 | if_get_byindex(u_int idx, struct psref *psref) | 2767 | if_get_byindex(u_int idx, struct psref *psref) | |
2655 | { | 2768 | { | |
@@ -2761,36 +2874,42 @@ ifioctl_common(struct ifnet *ifp, u_long | @@ -2761,36 +2874,42 @@ ifioctl_common(struct ifnet *ifp, u_long | |||
2761 | } | 2874 | } | |
2762 | 2875 | |||
2763 | if (ifp->if_capenable & IFCAP_CSUM_UDPv6_Tx) { | 2876 | if (ifp->if_capenable & IFCAP_CSUM_UDPv6_Tx) { | |
2764 | ifp->if_csum_flags_tx |= M_CSUM_UDPv6; | 2877 | ifp->if_csum_flags_tx |= M_CSUM_UDPv6; | |
2765 | } | 2878 | } | |
2766 | if (ifp->if_capenable & IFCAP_CSUM_UDPv6_Rx) { | 2879 | if (ifp->if_capenable & IFCAP_CSUM_UDPv6_Rx) { | |
2767 | ifp->if_csum_flags_rx |= M_CSUM_UDPv6; | 2880 | ifp->if_csum_flags_rx |= M_CSUM_UDPv6; | |
2768 | } | 2881 | } | |
2769 | if (ifp->if_flags & IFF_UP) | 2882 | if (ifp->if_flags & IFF_UP) | |
2770 | return ENETRESET; | 2883 | return ENETRESET; | |
2771 | return 0; | 2884 | return 0; | |
2772 | case SIOCSIFFLAGS: | 2885 | case SIOCSIFFLAGS: | |
2773 | ifr = data; | 2886 | ifr = data; | |
2887 | /* | |||
2888 | * If if_is_mpsafe(ifp), KERNEL_LOCK isn't held here, but if_up | |||
2889 | * and if_down aren't MP-safe yet, so we must hold the lock. | |||
2890 | */ | |||
2891 | KERNEL_LOCK_IF_IFP_MPSAFE(ifp); | |||
2774 | if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) { | 2892 | if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) { | |
2775 | s = splsoftnet(); | 2893 | s = splsoftnet(); | |
2776 | if_down(ifp); | 2894 | if_down_locked(ifp); | |
2777 | splx(s); | 2895 | splx(s); | |
2778 | } | 2896 | } | |
2779 | if (ifr->ifr_flags & IFF_UP && (ifp->if_flags & IFF_UP) == 0) { | 2897 | if (ifr->ifr_flags & IFF_UP && (ifp->if_flags & IFF_UP) == 0) { | |
2780 | s = splsoftnet(); | 2898 | s = splsoftnet(); | |
2781 | if_up(ifp); | 2899 | if_up_locked(ifp); | |
2782 | splx(s); | 2900 | splx(s); | |
2783 | } | 2901 | } | |
2902 | KERNEL_UNLOCK_IF_IFP_MPSAFE(ifp); | |||
2784 | ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) | | 2903 | ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) | | |
2785 | (ifr->ifr_flags &~ IFF_CANTCHANGE); | 2904 | (ifr->ifr_flags &~ IFF_CANTCHANGE); | |
2786 | break; | 2905 | break; | |
2787 | case SIOCGIFFLAGS: | 2906 | case SIOCGIFFLAGS: | |
2788 | ifr = data; | 2907 | ifr = data; | |
2789 | ifr->ifr_flags = ifp->if_flags; | 2908 | ifr->ifr_flags = ifp->if_flags; | |
2790 | break; | 2909 | break; | |
2791 | 2910 | |||
2792 | case SIOCGIFMETRIC: | 2911 | case SIOCGIFMETRIC: | |
2793 | ifr = data; | 2912 | ifr = data; | |
2794 | ifr->ifr_metric = ifp->if_metric; | 2913 | ifr->ifr_metric = ifp->if_metric; | |
2795 | break; | 2914 | break; | |
2796 | 2915 | |||
@@ -2842,28 +2961,30 @@ ifioctl_common(struct ifnet *ifp, u_long | @@ -2842,28 +2961,30 @@ ifioctl_common(struct ifnet *ifp, u_long | |||
2842 | * And also, update if_lastchnage. | 2961 | * And also, update if_lastchnage. | |
2843 | */ | 2962 | */ | |
2844 | getnanotime(&ifp->if_lastchange); | 2963 | getnanotime(&ifp->if_lastchange); | |
2845 | break; | 2964 | break; | |
2846 | case SIOCSIFMTU: | 2965 | case SIOCSIFMTU: | |
2847 | ifr = data; | 2966 | ifr = data; | |
2848 | if (ifp->if_mtu == ifr->ifr_mtu) | 2967 | if (ifp->if_mtu == ifr->ifr_mtu) | |
2849 | break; | 2968 | break; | |
2850 | ifp->if_mtu = ifr->ifr_mtu; | 2969 | ifp->if_mtu = ifr->ifr_mtu; | |
2851 | /* | 2970 | /* | |
2852 | * If the link MTU changed, do network layer specific procedure. | 2971 | * If the link MTU changed, do network layer specific procedure. | |
2853 | */ | 2972 | */ | |
2854 | #ifdef INET6 | 2973 | #ifdef INET6 | |
2974 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |||
2855 | if (in6_present) | 2975 | if (in6_present) | |
2856 | nd6_setmtu(ifp); | 2976 | nd6_setmtu(ifp); | |
2977 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |||
2857 | #endif | 2978 | #endif | |
2858 | return ENETRESET; | 2979 | return ENETRESET; | |
2859 | default: | 2980 | default: | |
2860 | return ENOTTY; | 2981 | return ENOTTY; | |
2861 | } | 2982 | } | |
2862 | return 0; | 2983 | return 0; | |
2863 | } | 2984 | } | |
2864 | 2985 | |||
2865 | int | 2986 | int | |
2866 | ifaddrpref_ioctl(struct socket *so, u_long cmd, void *data, struct ifnet *ifp) | 2987 | ifaddrpref_ioctl(struct socket *so, u_long cmd, void *data, struct ifnet *ifp) | |
2867 | { | 2988 | { | |
2868 | struct if_addrprefreq *ifap = (struct if_addrprefreq *)data; | 2989 | struct if_addrprefreq *ifap = (struct if_addrprefreq *)data; | |
2869 | struct ifaddr *ifa; | 2990 | struct ifaddr *ifa; | |
@@ -2987,31 +3108,33 @@ doifioctl(struct socket *so, u_long cmd, | @@ -2987,31 +3108,33 @@ doifioctl(struct socket *so, u_long cmd, | |||
2987 | if (l != NULL) { | 3108 | if (l != NULL) { | |
2988 | ifp = if_get(ifr->ifr_name, &psref); | 3109 | ifp = if_get(ifr->ifr_name, &psref); | |
2989 | error = kauth_authorize_network(l->l_cred, | 3110 | error = kauth_authorize_network(l->l_cred, | |
2990 | KAUTH_NETWORK_INTERFACE, | 3111 | KAUTH_NETWORK_INTERFACE, | |
2991 | KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, | 3112 | KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, | |
2992 | (void *)cmd, NULL); | 3113 | (void *)cmd, NULL); | |
2993 | if (ifp != NULL) | 3114 | if (ifp != NULL) | |
2994 | if_put(ifp, &psref); | 3115 | if_put(ifp, &psref); | |
2995 | if (error != 0) { | 3116 | if (error != 0) { | |
2996 | curlwp_bindx(bound); | 3117 | curlwp_bindx(bound); | |
2997 | return error; | 3118 | return error; | |
2998 | } | 3119 | } | |
2999 | } | 3120 | } | |
3121 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |||
3000 | mutex_enter(&if_clone_mtx); | 3122 | mutex_enter(&if_clone_mtx); | |
3001 | r = (cmd == SIOCIFCREATE) ? | 3123 | r = (cmd == SIOCIFCREATE) ? | |
3002 | if_clone_create(ifr->ifr_name) : | 3124 | if_clone_create(ifr->ifr_name) : | |
3003 | if_clone_destroy(ifr->ifr_name); | 3125 | if_clone_destroy(ifr->ifr_name); | |
3004 | mutex_exit(&if_clone_mtx); | 3126 | mutex_exit(&if_clone_mtx); | |
3127 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |||
3005 | curlwp_bindx(bound); | 3128 | curlwp_bindx(bound); | |
3006 | return r; | 3129 | return r; | |
3007 | 3130 | |||
3008 | case SIOCIFGCLONERS: | 3131 | case SIOCIFGCLONERS: | |
3009 | { | 3132 | { | |
3010 | struct if_clonereq *req = (struct if_clonereq *)data; | 3133 | struct if_clonereq *req = (struct if_clonereq *)data; | |
3011 | return if_clone_list(req->ifcr_count, req->ifcr_buffer, | 3134 | return if_clone_list(req->ifcr_count, req->ifcr_buffer, | |
3012 | &req->ifcr_total); | 3135 | &req->ifcr_total); | |
3013 | } | 3136 | } | |
3014 | } | 3137 | } | |
3015 | 3138 | |||
3016 | bound = curlwp_bind(); | 3139 | bound = curlwp_bind(); | |
3017 | ifp = if_get(ifr->ifr_name, &psref); | 3140 | ifp = if_get(ifr->ifr_name, &psref); | |
@@ -3049,56 +3172,60 @@ doifioctl(struct socket *so, u_long cmd, | @@ -3049,56 +3172,60 @@ doifioctl(struct socket *so, u_long cmd, | |||
3049 | case SIOCSLINKSTR: | 3172 | case SIOCSLINKSTR: | |
3050 | if (l != NULL) { | 3173 | if (l != NULL) { | |
3051 | error = kauth_authorize_network(l->l_cred, | 3174 | error = kauth_authorize_network(l->l_cred, | |
3052 | KAUTH_NETWORK_INTERFACE, | 3175 | KAUTH_NETWORK_INTERFACE, | |
3053 | KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, | 3176 | KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp, | |
3054 | (void *)cmd, NULL); | 3177 | (void *)cmd, NULL); | |
3055 | if (error != 0) | 3178 | if (error != 0) | |
3056 | goto out; | 3179 | goto out; | |
3057 | } | 3180 | } | |
3058 | } | 3181 | } | |
3059 | 3182 | |||
3060 | oif_flags = ifp->if_flags; | 3183 | oif_flags = ifp->if_flags; | |
3061 | 3184 | |||
3062 | mutex_enter(ifp->if_ioctl_lock); | 3185 | KERNEL_LOCK_UNLESS_IFP_MPSAFE(ifp); | |
3186 | IFNET_LOCK(ifp); | |||
3063 | 3187 | |||
3064 | error = (*ifp->if_ioctl)(ifp, cmd, data); | 3188 | error = (*ifp->if_ioctl)(ifp, cmd, data); | |
3065 | if (error != ENOTTY) | 3189 | if (error != ENOTTY) | |
3066 | ; | 3190 | ; | |
3067 | else if (so->so_proto == NULL) | 3191 | else if (so->so_proto == NULL) | |
3068 | error = EOPNOTSUPP; | 3192 | error = EOPNOTSUPP; | |
3069 | else { | 3193 | else { | |
3194 | KERNEL_LOCK_IF_IFP_MPSAFE(ifp); | |||
3070 | #ifdef COMPAT_OSOCK | 3195 | #ifdef COMPAT_OSOCK | |
3071 | if (vec_compat_ifioctl != NULL) | 3196 | if (vec_compat_ifioctl != NULL) | |
3072 | error = (*vec_compat_ifioctl)(so, ocmd, cmd, data, l); | 3197 | error = (*vec_compat_ifioctl)(so, ocmd, cmd, data, l); | |
3073 | else | 3198 | else | |
3074 | #endif | 3199 | #endif | |
3075 | error = (*so->so_proto->pr_usrreqs->pr_ioctl)(so, | 3200 | error = (*so->so_proto->pr_usrreqs->pr_ioctl)(so, | |
3076 | cmd, data, ifp); | 3201 | cmd, data, ifp); | |
3202 | KERNEL_UNLOCK_IF_IFP_MPSAFE(ifp); | |||
3077 | } | 3203 | } | |
3078 | 3204 | |||
3079 | if (((oif_flags ^ ifp->if_flags) & IFF_UP) != 0) { | 3205 | if (((oif_flags ^ ifp->if_flags) & IFF_UP) != 0) { | |
3080 | if ((ifp->if_flags & IFF_UP) != 0) { | 3206 | if ((ifp->if_flags & IFF_UP) != 0) { | |
3081 | int s = splsoftnet(); | 3207 | int s = splsoftnet(); | |
3082 | if_up(ifp); | 3208 | if_up_locked(ifp); | |
3083 | splx(s); | 3209 | splx(s); | |
3084 | } | 3210 | } | |
3085 | } | 3211 | } | |
3086 | #ifdef COMPAT_OIFREQ | 3212 | #ifdef COMPAT_OIFREQ | |
3087 | if (cmd != ocmd) | 3213 | if (cmd != ocmd) | |
3088 | ifreqn2o(oifr, ifr); | 3214 | ifreqn2o(oifr, ifr); | |
3089 | #endif | 3215 | #endif | |
3090 | 3216 | |||
3091 | mutex_exit(ifp->if_ioctl_lock); | 3217 | IFNET_UNLOCK(ifp); | |
3218 | KERNEL_UNLOCK_UNLESS_IFP_MPSAFE(ifp); | |||
3092 | out: | 3219 | out: | |
3093 | if_put(ifp, &psref); | 3220 | if_put(ifp, &psref); | |
3094 | curlwp_bindx(bound); | 3221 | curlwp_bindx(bound); | |
3095 | return error; | 3222 | return error; | |
3096 | } | 3223 | } | |
3097 | 3224 | |||
3098 | /* | 3225 | /* | |
3099 | * Return interface configuration | 3226 | * Return interface configuration | |
3100 | * of system. List may be used | 3227 | * of system. List may be used | |
3101 | * in later ioctl's (above) to get | 3228 | * in later ioctl's (above) to get | |
3102 | * other information. | 3229 | * other information. | |
3103 | * | 3230 | * | |
3104 | * Each record is a struct ifreq. Before the addition of | 3231 | * Each record is a struct ifreq. Before the addition of | |
@@ -3335,30 +3462,30 @@ ifq_enqueue2(struct ifnet *ifp, struct i | @@ -3335,30 +3462,30 @@ ifq_enqueue2(struct ifnet *ifp, struct i | |||
3335 | IFQ_ENQUEUE(&ifp->if_snd, m, error); | 3462 | IFQ_ENQUEUE(&ifp->if_snd, m, error); | |
3336 | if (error != 0) { | 3463 | if (error != 0) { | |
3337 | ++ifp->if_oerrors; | 3464 | ++ifp->if_oerrors; | |
3338 | return error; | 3465 | return error; | |
3339 | } | 3466 | } | |
3340 | return 0; | 3467 | return 0; | |
3341 | } | 3468 | } | |
3342 | 3469 | |||
3343 | int | 3470 | int | |
3344 | if_addr_init(ifnet_t *ifp, struct ifaddr *ifa, const bool src) | 3471 | if_addr_init(ifnet_t *ifp, struct ifaddr *ifa, const bool src) | |
3345 | { | 3472 | { | |
3346 | int rc; | 3473 | int rc; | |
3347 | 3474 | |||
3475 | KASSERT(IFNET_LOCKED(ifp)); | |||
3348 | if (ifp->if_initaddr != NULL) | 3476 | if (ifp->if_initaddr != NULL) | |
3349 | rc = (*ifp->if_initaddr)(ifp, ifa, src); | 3477 | rc = (*ifp->if_initaddr)(ifp, ifa, src); | |
3350 | else if (src || | 3478 | else if (src || | |
3351 | /* FIXME: may not hold if_ioctl_lock */ | |||
3352 | (rc = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR, ifa)) == ENOTTY) | 3479 | (rc = (*ifp->if_ioctl)(ifp, SIOCSIFDSTADDR, ifa)) == ENOTTY) | |
3353 | rc = (*ifp->if_ioctl)(ifp, SIOCINITIFADDR, ifa); | 3480 | rc = (*ifp->if_ioctl)(ifp, SIOCINITIFADDR, ifa); | |
3354 | 3481 | |||
3355 | return rc; | 3482 | return rc; | |
3356 | } | 3483 | } | |
3357 | 3484 | |||
3358 | int | 3485 | int | |
3359 | if_do_dad(struct ifnet *ifp) | 3486 | if_do_dad(struct ifnet *ifp) | |
3360 | { | 3487 | { | |
3361 | if ((ifp->if_flags & IFF_LOOPBACK) != 0) | 3488 | if ((ifp->if_flags & IFF_LOOPBACK) != 0) | |
3362 | return 0; | 3489 | return 0; | |
3363 | 3490 | |||
3364 | switch (ifp->if_type) { | 3491 | switch (ifp->if_type) { | |
@@ -3383,64 +3510,69 @@ if_do_dad(struct ifnet *ifp) | @@ -3383,64 +3510,69 @@ if_do_dad(struct ifnet *ifp) | |||
3383 | if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != | 3510 | if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != | |
3384 | (IFF_UP|IFF_RUNNING)) | 3511 | (IFF_UP|IFF_RUNNING)) | |
3385 | return 0; | 3512 | return 0; | |
3386 | 3513 | |||
3387 | return 1; | 3514 | return 1; | |
3388 | } | 3515 | } | |
3389 | } | 3516 | } | |
3390 | 3517 | |||
3391 | int | 3518 | int | |
3392 | if_flags_set(ifnet_t *ifp, const short flags) | 3519 | if_flags_set(ifnet_t *ifp, const short flags) | |
3393 | { | 3520 | { | |
3394 | int rc; | 3521 | int rc; | |
3395 | 3522 | |||
3523 | KASSERT(IFNET_LOCKED(ifp)); | |||
3524 | ||||
3396 | if (ifp->if_setflags != NULL) | 3525 | if (ifp->if_setflags != NULL) | |
3397 | rc = (*ifp->if_setflags)(ifp, flags); | 3526 | rc = (*ifp->if_setflags)(ifp, flags); | |
3398 | else { | 3527 | else { | |
3399 | short cantflags, chgdflags; | 3528 | short cantflags, chgdflags; | |
3400 | struct ifreq ifr; | 3529 | struct ifreq ifr; | |
3401 | 3530 | |||
3402 | chgdflags = ifp->if_flags ^ flags; | 3531 | chgdflags = ifp->if_flags ^ flags; | |
3403 | cantflags = chgdflags & IFF_CANTCHANGE; | 3532 | cantflags = chgdflags & IFF_CANTCHANGE; | |
3404 | 3533 | |||
3405 | if (cantflags != 0) | 3534 | if (cantflags != 0) | |
3406 | ifp->if_flags ^= cantflags; | 3535 | ifp->if_flags ^= cantflags; | |
3407 | 3536 | |||
3408 | /* Traditionally, we do not call if_ioctl after | 3537 | /* Traditionally, we do not call if_ioctl after | |
3409 | * setting/clearing only IFF_PROMISC if the interface | 3538 | * setting/clearing only IFF_PROMISC if the interface | |
3410 | * isn't IFF_UP. Uphold that tradition. | 3539 | * isn't IFF_UP. Uphold that tradition. | |
3411 | */ | 3540 | */ | |
3412 | if (chgdflags == IFF_PROMISC && (ifp->if_flags & IFF_UP) == 0) | 3541 | if (chgdflags == IFF_PROMISC && (ifp->if_flags & IFF_UP) == 0) | |
3413 | return 0; | 3542 | return 0; | |
3414 | 3543 | |||
3415 | memset(&ifr, 0, sizeof(ifr)); | 3544 | memset(&ifr, 0, sizeof(ifr)); | |
3416 | 3545 | |||
3417 | ifr.ifr_flags = flags & ~IFF_CANTCHANGE; | 3546 | ifr.ifr_flags = flags & ~IFF_CANTCHANGE; | |
3418 | /* FIXME: may not hold if_ioctl_lock */ | |||
3419 | rc = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, &ifr); | 3547 | rc = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, &ifr); | |
3420 | 3548 | |||
3421 | if (rc != 0 && cantflags != 0) | 3549 | if (rc != 0 && cantflags != 0) | |
3422 | ifp->if_flags ^= cantflags; | 3550 | ifp->if_flags ^= cantflags; | |
3423 | } | 3551 | } | |
3424 | 3552 | |||
3425 | return rc; | 3553 | return rc; | |
3426 | } | 3554 | } | |
3427 | 3555 | |||
3428 | int | 3556 | int | |
3429 | if_mcast_op(ifnet_t *ifp, const unsigned long cmd, const struct sockaddr *sa) | 3557 | if_mcast_op(ifnet_t *ifp, const unsigned long cmd, const struct sockaddr *sa) | |
3430 | { | 3558 | { | |
3431 | int rc; | 3559 | int rc; | |
3432 | struct ifreq ifr; | 3560 | struct ifreq ifr; | |
3433 | 3561 | |||
3562 | /* CARP still doesn't deal with the lock yet */ | |||
3563 | #if !defined(NCARP) || (NCARP == 0) | |||
3564 | KASSERT(IFNET_LOCKED(ifp)); | |||
3565 | #endif | |||
3434 | if (ifp->if_mcastop != NULL) | 3566 | if (ifp->if_mcastop != NULL) | |
3435 | rc = (*ifp->if_mcastop)(ifp, cmd, sa); | 3567 | rc = (*ifp->if_mcastop)(ifp, cmd, sa); | |
3436 | else { | 3568 | else { | |
3437 | ifreq_setaddr(cmd, &ifr, sa); | 3569 | ifreq_setaddr(cmd, &ifr, sa); | |
3438 | rc = (*ifp->if_ioctl)(ifp, cmd, &ifr); | 3570 | rc = (*ifp->if_ioctl)(ifp, cmd, &ifr); | |
3439 | } | 3571 | } | |
3440 | 3572 | |||
3441 | return rc; | 3573 | return rc; | |
3442 | } | 3574 | } | |
3443 | 3575 | |||
3444 | static void | 3576 | static void | |
3445 | sysctl_sndq_setup(struct sysctllog **clog, const char *ifname, | 3577 | sysctl_sndq_setup(struct sysctllog **clog, const char *ifname, | |
3446 | struct ifaltq *ifq) | 3578 | struct ifaltq *ifq) |
--- src/sys/net/if.h 2017/12/10 10:10:24 1.239.2.2
+++ src/sys/net/if.h 2018/01/02 10:20:33 1.239.2.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if.h,v 1.239.2.2 2017/12/10 10:10:24 snj Exp $ */ | 1 | /* $NetBSD: if.h,v 1.239.2.3 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1999, 2000, 2001 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. | |
@@ -225,138 +225,174 @@ struct ifqueue { | @@ -225,138 +225,174 @@ struct ifqueue { | |||
225 | */ | 225 | */ | |
226 | TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */ | 226 | TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */ | |
227 | 227 | |||
228 | struct bridge_softc; | 228 | struct bridge_softc; | |
229 | struct bridge_iflist; | 229 | struct bridge_iflist; | |
230 | struct callout; | 230 | struct callout; | |
231 | struct krwlock; | 231 | struct krwlock; | |
232 | struct if_percpuq; | 232 | struct if_percpuq; | |
233 | struct if_deferred_start; | 233 | struct if_deferred_start; | |
234 | struct in6_multi; | 234 | struct in6_multi; | |
235 | 235 | |||
236 | typedef unsigned short if_index_t; | 236 | typedef unsigned short if_index_t; | |
237 | 237 | |||
238 | /* | |||
239 | * Interface. Field markings and the corresponding locks: | |||
240 | * | |||
241 | * i: IFNET_LOCK (a.k.a., if_ioctl_lock) | |||
242 | * q: ifq_lock (struct ifaltq) | |||
243 | * a: if_afdata_lock | |||
244 | * 6: in6_multilock (global lock) | |||
245 | * :: unlocked, stable | |||
246 | * ?: unkown, maybe unsafe | |||
247 | * | |||
248 | * Lock order: IFNET_LOCK => in6_multilock => if_afdata_lock => ifq_lock | |||
249 | * Note that currently if_afdata_lock and ifq_lock aren't held | |||
250 | * at the same time, but define the order anyway. | |||
251 | * | |||
252 | * Lock order of IFNET_LOCK with other locks: | |||
253 | * softnet_lock => solock => IFNET_LOCK => ND6_LOCK, in_multilock | |||
254 | */ | |||
238 | typedef struct ifnet { | 255 | typedef struct ifnet { | |
239 | void *if_softc; /* lower-level data for this if */ | 256 | void *if_softc; /* :: lower-level data for this if */ | |
240 | /* DEPRECATED. Keep it to avoid breaking kvm(3) users */ | 257 | /* DEPRECATED. Keep it to avoid breaking kvm(3) users */ | |
241 | TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */ | 258 | TAILQ_ENTRY(ifnet) | |
242 | TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */ | 259 | if_list; /* i: all struct ifnets are chained */ | |
243 | char if_xname[IFNAMSIZ]; /* external name (name + unit) */ | 260 | TAILQ_HEAD(, ifaddr) | |
244 | int if_pcount; /* number of promiscuous listeners */ | 261 | if_addrlist; /* i: linked list of addresses per if */ | |
245 | struct bpf_if *if_bpf; /* packet filter structure */ | 262 | char if_xname[IFNAMSIZ]; | |
246 | if_index_t if_index; /* numeric abbreviation for this if */ | 263 | /* :: external name (name + unit) */ | |
247 | short if_timer; /* time 'til if_slowtimo called */ | 264 | int if_pcount; /* i: number of promiscuous listeners */ | |
248 | unsigned short if_flags; /* up/down, broadcast, etc. */ | 265 | struct bpf_if *if_bpf; /* :: packet filter structure */ | |
249 | short if_extflags; /* if_output MP-safe, etc. */ | 266 | if_index_t if_index; /* :: numeric abbreviation for this if */ | |
250 | struct if_data if_data; /* statistics and other data about if */ | 267 | short if_timer; /* ?: time 'til if_slowtimo called */ | |
268 | unsigned short if_flags; /* i: up/down, broadcast, etc. */ | |||
269 | short if_extflags; /* :: if_output MP-safe, etc. */ | |||
270 | struct if_data if_data; /* ?: statistics and other data about if */ | |||
251 | /* | 271 | /* | |
252 | * Procedure handles. If you add more of these, don't forget the | 272 | * Procedure handles. If you add more of these, don't forget the | |
253 | * corresponding NULL stub in if.c. | 273 | * corresponding NULL stub in if.c. | |
254 | */ | 274 | */ | |
255 | int (*if_output) /* output routine (enqueue) */ | 275 | int (*if_output) /* :: output routine (enqueue) */ | |
256 | (struct ifnet *, struct mbuf *, const struct sockaddr *, | 276 | (struct ifnet *, struct mbuf *, const struct sockaddr *, | |
257 | const struct rtentry *); | 277 | const struct rtentry *); | |
258 | void (*_if_input) /* input routine (from h/w driver) */ | 278 | void (*_if_input) /* :: input routine (from h/w driver) */ | |
259 | (struct ifnet *, struct mbuf *); | 279 | (struct ifnet *, struct mbuf *); | |
260 | void (*if_start) /* initiate output routine */ | 280 | void (*if_start) /* :: initiate output routine */ | |
261 | (struct ifnet *); | 281 | (struct ifnet *); | |
262 | int (*if_transmit) /* output routine, must be MP-safe */ | 282 | int (*if_transmit) /* :: output routine, must be MP-safe */ | |
263 | (struct ifnet *, struct mbuf *); | 283 | (struct ifnet *, struct mbuf *); | |
264 | int (*if_ioctl) /* ioctl routine */ | 284 | int (*if_ioctl) /* :: ioctl routine */ | |
265 | (struct ifnet *, u_long, void *); | 285 | (struct ifnet *, u_long, void *); | |
266 | int (*if_init) /* init routine */ | 286 | int (*if_init) /* :: init routine */ | |
267 | (struct ifnet *); | 287 | (struct ifnet *); | |
268 | void (*if_stop) /* stop routine */ | 288 | void (*if_stop) /* :: stop routine */ | |
269 | (struct ifnet *, int); | 289 | (struct ifnet *, int); | |
270 | void (*if_slowtimo) /* timer routine */ | 290 | void (*if_slowtimo) /* :: timer routine */ | |
271 | (struct ifnet *); | 291 | (struct ifnet *); | |
272 | #define if_watchdog if_slowtimo | 292 | #define if_watchdog if_slowtimo | |
273 | void (*if_drain) /* routine to release resources */ | 293 | void (*if_drain) /* :: routine to release resources */ | |
274 | (struct ifnet *); | 294 | (struct ifnet *); | |
275 | struct ifaltq if_snd; /* output queue (includes altq) */ | 295 | struct ifaltq if_snd; /* q: output queue (includes altq) */ | |
276 | struct ifaddr *if_dl; /* identity of this interface. */ | 296 | struct ifaddr *if_dl; /* i: identity of this interface. */ | |
277 | const struct sockaddr_dl *if_sadl; /* pointer to sockaddr_dl | 297 | const struct sockaddr_dl | |
278 | * of if_dl | 298 | *if_sadl; /* i: pointer to sockaddr_dl of if_dl */ | |
279 | */ | 299 | /* | |
280 | /* if_hwdl: h/w identity | |||
281 | * | |||
282 | * May be NULL. If not NULL, it is the address assigned | 300 | * May be NULL. If not NULL, it is the address assigned | |
283 | * to the interface by the manufacturer, so it very likely | 301 | * to the interface by the manufacturer, so it very likely | |
284 | * to be unique. It MUST NOT be deleted. It is highly | 302 | * to be unique. It MUST NOT be deleted. It is highly | |
285 | * suitable for deriving the EUI64 for the interface. | 303 | * suitable for deriving the EUI64 for the interface. | |
286 | */ | 304 | */ | |
287 | struct ifaddr *if_hwdl; | 305 | struct ifaddr *if_hwdl; /* i: h/w identity */ | |
288 | const uint8_t *if_broadcastaddr;/* linklevel broadcast bytestring */ | 306 | const uint8_t *if_broadcastaddr; | |
289 | struct bridge_softc *if_bridge; /* bridge glue */ | 307 | /* :: linklevel broadcast bytestring */ | |
290 | struct bridge_iflist *if_bridgeif; /* shortcut to interface list entry */ | 308 | struct bridge_softc | |
291 | int if_dlt; /* data link type (<net/dlt.h>) */ | 309 | *if_bridge; /* i: bridge glue */ | |
292 | pfil_head_t * if_pfil; /* filtering point */ | 310 | struct bridge_iflist | |
293 | uint64_t if_capabilities; /* interface capabilities */ | 311 | *if_bridgeif; /* i: shortcut to interface list entry */ | |
294 | uint64_t if_capenable; /* capabilities enabled */ | 312 | int if_dlt; /* :: data link type (<net/dlt.h>) */ | |
313 | pfil_head_t * if_pfil; /* :: filtering point */ | |||
314 | uint64_t if_capabilities; | |||
315 | /* i: interface capabilities */ | |||
316 | uint64_t if_capenable; /* i: capabilities enabled */ | |||
295 | union { | 317 | union { | |
296 | void * carp_s; /* carp structure (used by !carp ifs) */ | 318 | void * carp_s; /* carp structure (used by !carp ifs) */ | |
297 | struct ifnet *carp_d;/* ptr to carpdev (used by carp ifs) */ | 319 | struct ifnet *carp_d;/* ptr to carpdev (used by carp ifs) */ | |
298 | } if_carp_ptr; | 320 | } if_carp_ptr; /* ?: */ | |
299 | #define if_carp if_carp_ptr.carp_s | 321 | #define if_carp if_carp_ptr.carp_s | |
300 | #define if_carpdev if_carp_ptr.carp_d | 322 | #define if_carpdev if_carp_ptr.carp_d | |
301 | /* | 323 | /* | |
302 | * These are pre-computed based on an interfaces enabled | 324 | * These are pre-computed based on an interfaces enabled | |
303 | * capabilities, for speed elsewhere. | 325 | * capabilities, for speed elsewhere. | |
304 | */ | 326 | */ | |
305 | int if_csum_flags_tx; /* M_CSUM_* flags for Tx */ | 327 | int if_csum_flags_tx; | |
306 | int if_csum_flags_rx; /* M_CSUM_* flags for Rx */ | 328 | /* i: M_CSUM_* flags for Tx */ | |
307 | 329 | int if_csum_flags_rx; | ||
308 | void *if_afdata[AF_MAX]; | 330 | /* i: M_CSUM_* flags for Rx */ | |
309 | struct mowner *if_mowner; /* who owns mbufs for this interface */ | 331 | ||
332 | void *if_afdata[AF_MAX]; | |||
333 | /* a: */ | |||
334 | struct mowner *if_mowner; /* ?: who owns mbufs for this interface */ | |||
310 | 335 | |||
311 | void *if_agrprivate; /* used only when #if NAGR > 0 */ | 336 | void *if_agrprivate; /* ?: used only when #if NAGR > 0 */ | |
312 | 337 | |||
313 | /* | 338 | /* | |
314 | * pf specific data, used only when #if NPF > 0. | 339 | * pf specific data, used only when #if NPF > 0. | |
315 | */ | 340 | */ | |
316 | void *if_pf_kif; /* pf interface abstraction */ | 341 | void *if_pf_kif; /* ?: pf interface abstraction */ | |
317 | void *if_pf_groups; /* pf interface groups */ | 342 | void *if_pf_groups; /* ?: pf interface groups */ | |
318 | /* | 343 | /* | |
319 | * During an ifnet's lifetime, it has only one if_index, but | 344 | * During an ifnet's lifetime, it has only one if_index, but | |
320 | * and if_index is not sufficient to identify an ifnet | 345 | * and if_index is not sufficient to identify an ifnet | |
321 | * because during the lifetime of the system, many ifnets may occupy a | 346 | * because during the lifetime of the system, many ifnets may occupy a | |
322 | * given if_index. Let us tell different ifnets at the same | 347 | * given if_index. Let us tell different ifnets at the same | |
323 | * if_index apart by their if_index_gen, a unique number that each ifnet | 348 | * if_index apart by their if_index_gen, a unique number that each ifnet | |
324 | * is assigned when it if_attach()s. Now, the kernel can use the | 349 | * is assigned when it if_attach()s. Now, the kernel can use the | |
325 | * pair (if_index, if_index_gen) as a weak reference to an ifnet. | 350 | * pair (if_index, if_index_gen) as a weak reference to an ifnet. | |
326 | */ | 351 | */ | |
327 | uint64_t if_index_gen; /* generation number for the ifnet | 352 | uint64_t if_index_gen; /* :: generation number for the ifnet | |
328 | * at if_index: if two ifnets' index | 353 | * at if_index: if two ifnets' index | |
329 | * and generation number are both the | 354 | * and generation number are both the | |
330 | * same, they are the same ifnet. | 355 | * same, they are the same ifnet. | |
331 | */ | 356 | */ | |
332 | struct sysctllog *if_sysctl_log; | 357 | struct sysctllog | |
333 | int (*if_initaddr)(struct ifnet *, struct ifaddr *, bool); | 358 | *if_sysctl_log; /* :: */ | |
334 | int (*if_mcastop)(struct ifnet *, const unsigned long, | 359 | int (*if_initaddr) /* :: */ | |
335 | const struct sockaddr *); | 360 | (struct ifnet *, struct ifaddr *, bool); | |
336 | int (*if_setflags)(struct ifnet *, const short); | 361 | int (*if_mcastop) /* :: */ | |
337 | kmutex_t *if_ioctl_lock; | 362 | (struct ifnet *, const unsigned long, | |
363 | const struct sockaddr *); | |||
364 | int (*if_setflags) /* :: */ | |||
365 | (struct ifnet *, const short); | |||
366 | kmutex_t *if_ioctl_lock; /* :: */ | |||
338 | #ifdef _KERNEL /* XXX kvm(3) */ | 367 | #ifdef _KERNEL /* XXX kvm(3) */ | |
339 | struct callout *if_slowtimo_ch; | 368 | struct callout *if_slowtimo_ch;/* :: */ | |
340 | struct krwlock *if_afdata_lock; | 369 | struct krwlock *if_afdata_lock;/* :: */ | |
341 | struct if_percpuq *if_percpuq; /* We should remove it in the future */ | 370 | struct if_percpuq | |
342 | void *if_link_si; /* softint to handle link state changes */ | 371 | *if_percpuq; /* :: we should remove it in the future */ | |
343 | uint16_t if_link_queue; /* masked link state change queue */ | 372 | void *if_link_si; /* :: softint to handle link state changes */ | |
344 | struct pslist_entry if_pslist_entry; | 373 | uint16_t if_link_queue; /* q: masked link state change queue */ | |
345 | struct psref_target if_psref; | 374 | struct pslist_entry | |
346 | struct pslist_head if_addr_pslist; | 375 | if_pslist_entry;/* i: */ | |
347 | struct if_deferred_start *if_deferred_start; | 376 | struct psref_target | |
377 | if_psref; /* :: */ | |||
378 | struct pslist_head | |||
379 | if_addr_pslist; /* i: */ | |||
380 | struct if_deferred_start | |||
381 | *if_deferred_start; | |||
382 | /* :: */ | |||
348 | /* XXX should be protocol independent */ | 383 | /* XXX should be protocol independent */ | |
349 | LIST_HEAD(, in6_multi) if_multiaddrs; | 384 | LIST_HEAD(, in6_multi) | |
385 | if_multiaddrs; /* 6: */ | |||
350 | #endif | 386 | #endif | |
351 | } ifnet_t; | 387 | } ifnet_t; | |
352 | 388 | |||
353 | #define if_mtu if_data.ifi_mtu | 389 | #define if_mtu if_data.ifi_mtu | |
354 | #define if_type if_data.ifi_type | 390 | #define if_type if_data.ifi_type | |
355 | #define if_addrlen if_data.ifi_addrlen | 391 | #define if_addrlen if_data.ifi_addrlen | |
356 | #define if_hdrlen if_data.ifi_hdrlen | 392 | #define if_hdrlen if_data.ifi_hdrlen | |
357 | #define if_metric if_data.ifi_metric | 393 | #define if_metric if_data.ifi_metric | |
358 | #define if_link_state if_data.ifi_link_state | 394 | #define if_link_state if_data.ifi_link_state | |
359 | #define if_baudrate if_data.ifi_baudrate | 395 | #define if_baudrate if_data.ifi_baudrate | |
360 | #define if_ipackets if_data.ifi_ipackets | 396 | #define if_ipackets if_data.ifi_ipackets | |
361 | #define if_ierrors if_data.ifi_ierrors | 397 | #define if_ierrors if_data.ifi_ierrors | |
362 | #define if_opackets if_data.ifi_opackets | 398 | #define if_opackets if_data.ifi_opackets | |
@@ -377,81 +413,163 @@ typedef struct ifnet { | @@ -377,81 +413,163 @@ typedef struct ifnet { | |||
377 | #define IFF_POINTOPOINT 0x0010 /* interface is point-to-point link */ | 413 | #define IFF_POINTOPOINT 0x0010 /* interface is point-to-point link */ | |
378 | #define IFF_NOTRAILERS 0x0020 /* avoid use of trailers */ | 414 | #define IFF_NOTRAILERS 0x0020 /* avoid use of trailers */ | |
379 | #define IFF_RUNNING 0x0040 /* resources allocated */ | 415 | #define IFF_RUNNING 0x0040 /* resources allocated */ | |
380 | #define IFF_NOARP 0x0080 /* no address resolution protocol */ | 416 | #define IFF_NOARP 0x0080 /* no address resolution protocol */ | |
381 | #define IFF_PROMISC 0x0100 /* receive all packets */ | 417 | #define IFF_PROMISC 0x0100 /* receive all packets */ | |
382 | #define IFF_ALLMULTI 0x0200 /* receive all multicast packets */ | 418 | #define IFF_ALLMULTI 0x0200 /* receive all multicast packets */ | |
383 | #define IFF_OACTIVE 0x0400 /* transmission in progress */ | 419 | #define IFF_OACTIVE 0x0400 /* transmission in progress */ | |
384 | #define IFF_SIMPLEX 0x0800 /* can't hear own transmissions */ | 420 | #define IFF_SIMPLEX 0x0800 /* can't hear own transmissions */ | |
385 | #define IFF_LINK0 0x1000 /* per link layer defined bit */ | 421 | #define IFF_LINK0 0x1000 /* per link layer defined bit */ | |
386 | #define IFF_LINK1 0x2000 /* per link layer defined bit */ | 422 | #define IFF_LINK1 0x2000 /* per link layer defined bit */ | |
387 | #define IFF_LINK2 0x4000 /* per link layer defined bit */ | 423 | #define IFF_LINK2 0x4000 /* per link layer defined bit */ | |
388 | #define IFF_MULTICAST 0x8000 /* supports multicast */ | 424 | #define IFF_MULTICAST 0x8000 /* supports multicast */ | |
389 | 425 | |||
390 | #define IFEF_OUTPUT_MPSAFE __BIT(0) /* if_output() can run parallel */ | 426 | #define IFEF_MPSAFE __BIT(0) /* handlers can run in parallel (see below) */ | |
391 | #define IFEF_START_MPSAFE __BIT(1) /* if_start() can run parallel */ | 427 | #define IFEF_NO_LINK_STATE_CHANGE __BIT(1) /* doesn't use link state interrupts */ | |
392 | #define IFEF_NO_LINK_STATE_CHANGE __BIT(2) /* doesn't use link state interrupts */ | 428 | ||
429 | /* | |||
430 | * The guidelines for converting an interface to IFEF_MPSAFE are as follows | |||
431 | * | |||
432 | * Enabling IFEF_MPSAFE on an interface suppresses taking KERNEL_LOCK when | |||
433 | * calling the following handlers: | |||
434 | * - if_start | |||
435 | * - Note that if_transmit is always called without KERNEL_LOCK | |||
436 | * - if_output | |||
437 | * - if_ioctl | |||
438 | * - if_init | |||
439 | * - if_stop | |||
440 | * | |||
441 | * This means that an interface with IFEF_MPSAFE must make the above handlers | |||
442 | * MP-safe or take KERNEL_LOCK by itself inside handlers that aren't MP-safe | |||
443 | * yet. | |||
444 | * | |||
445 | * There are some additional restrictions to access member variables of struct | |||
446 | * ifnet: | |||
447 | * - if_flags | |||
448 | * - Must be updated with holding IFNET_LOCK | |||
449 | * - You cannot use the flag in Tx/Rx paths anymore because there is no | |||
450 | * synchronization on the flag except for IFNET_LOCK | |||
451 | * - Note that IFNET_LOCK can't be taken in softint because it's known | |||
452 | * that it causes a deadlock | |||
453 | * - Some synchronization mechanisms such as pserialize_perform are called | |||
454 | * with IFNET_LOCK and also require context switches on every CPUs | |||
455 | * that mean softints finish so trying to take IFNET_LOCK in softint | |||
456 | * might block on IFNET_LOCK and prevent such synchronization mechanisms | |||
457 | * from being completed | |||
458 | * - Currently the deadlock occurs only if NET_MPSAFE is enabled, however, | |||
459 | * we should deal with the restriction because NET_MPSAFE will be enabled | |||
460 | * by default in the future | |||
461 | * - if_watchdog and if_timer | |||
462 | * - The watchdog framework works only for non-IFEF_MPSAFE interfaces | |||
463 | * that rely on KERNEL_LOCK | |||
464 | * - Interfaces with IFEF_MPSAFE have to provide its own watchdog mechanism | |||
465 | * if needed | |||
466 | * - Keep if_watchdog NULL when calling if_attach | |||
467 | */ | |||
393 | 468 | |||
394 | #ifdef _KERNEL | 469 | #ifdef _KERNEL | |
395 | static inline bool | 470 | static inline bool | |
396 | if_output_is_mpsafe(struct ifnet *ifp) | 471 | if_is_mpsafe(struct ifnet *ifp) | |
397 | { | 472 | { | |
398 | 473 | |||
399 | return ((ifp->if_extflags & IFEF_OUTPUT_MPSAFE) != 0); | 474 | return ((ifp->if_extflags & IFEF_MPSAFE) != 0); | |
400 | } | 475 | } | |
401 | 476 | |||
402 | static inline int | 477 | static inline int | |
403 | if_output_lock(struct ifnet *cifp, struct ifnet *ifp, struct mbuf *m, | 478 | if_output_lock(struct ifnet *cifp, struct ifnet *ifp, struct mbuf *m, | |
404 | const struct sockaddr *dst, const struct rtentry *rt) | 479 | const struct sockaddr *dst, const struct rtentry *rt) | |
405 | { | 480 | { | |
406 | 481 | |||
407 | if (if_output_is_mpsafe(cifp)) { | 482 | if (if_is_mpsafe(cifp)) { | |
408 | return (*cifp->if_output)(ifp, m, dst, rt); | 483 | return (*cifp->if_output)(ifp, m, dst, rt); | |
409 | } else { | 484 | } else { | |
410 | int ret; | 485 | int ret; | |
411 | 486 | |||
412 | KERNEL_LOCK(1, NULL); | 487 | KERNEL_LOCK(1, NULL); | |
413 | ret = (*cifp->if_output)(ifp, m, dst, rt); | 488 | ret = (*cifp->if_output)(ifp, m, dst, rt); | |
414 | KERNEL_UNLOCK_ONE(NULL); | 489 | KERNEL_UNLOCK_ONE(NULL); | |
415 | return ret; | 490 | return ret; | |
416 | } | 491 | } | |
417 | } | 492 | } | |
418 | 493 | |||
419 | static inline bool | |||
420 | if_start_is_mpsafe(struct ifnet *ifp) | |||
421 | { | |||
422 | ||||
423 | return ((ifp->if_extflags & IFEF_START_MPSAFE) != 0); | |||
424 | } | |||
425 | ||||
426 | static inline void | 494 | static inline void | |
427 | if_start_lock(struct ifnet *ifp) | 495 | if_start_lock(struct ifnet *ifp) | |
428 | { | 496 | { | |
429 | 497 | |||
430 | if (if_start_is_mpsafe(ifp)) { | 498 | if (if_is_mpsafe(ifp)) { | |
431 | (*ifp->if_start)(ifp); | 499 | (*ifp->if_start)(ifp); | |
432 | } else { | 500 | } else { | |
433 | KERNEL_LOCK(1, NULL); | 501 | KERNEL_LOCK(1, NULL); | |
434 | (*ifp->if_start)(ifp); | 502 | (*ifp->if_start)(ifp); | |
435 | KERNEL_UNLOCK_ONE(NULL); | 503 | KERNEL_UNLOCK_ONE(NULL); | |
436 | } | 504 | } | |
437 | } | 505 | } | |
438 | 506 | |||
439 | static inline bool | 507 | static inline bool | |
440 | if_is_link_state_changeable(struct ifnet *ifp) | 508 | if_is_link_state_changeable(struct ifnet *ifp) | |
441 | { | 509 | { | |
442 | 510 | |||
443 | return ((ifp->if_extflags & IFEF_NO_LINK_STATE_CHANGE) == 0); | 511 | return ((ifp->if_extflags & IFEF_NO_LINK_STATE_CHANGE) == 0); | |
444 | } | 512 | } | |
513 | ||||
514 | #define KERNEL_LOCK_IF_IFP_MPSAFE(ifp) \ | |||
515 | do { if (if_is_mpsafe(ifp)) { KERNEL_LOCK(1, NULL); } } while (0) | |||
516 | #define KERNEL_UNLOCK_IF_IFP_MPSAFE(ifp) \ | |||
517 | do { if (if_is_mpsafe(ifp)) { KERNEL_UNLOCK_ONE(NULL); } } while (0) | |||
518 | ||||
519 | #define KERNEL_LOCK_UNLESS_IFP_MPSAFE(ifp) \ | |||
520 | do { if (!if_is_mpsafe(ifp)) { KERNEL_LOCK(1, NULL); } } while (0) | |||
521 | #define KERNEL_UNLOCK_UNLESS_IFP_MPSAFE(ifp) \ | |||
522 | do { if (!if_is_mpsafe(ifp)) { KERNEL_UNLOCK_ONE(NULL); } } while (0) | |||
523 | ||||
524 | #ifdef _KERNEL_OPT | |||
525 | #include "opt_net_mpsafe.h" | |||
526 | #endif | |||
527 | ||||
528 | /* XXX explore a better place to define */ | |||
529 | #ifdef NET_MPSAFE | |||
530 | ||||
531 | #define KERNEL_LOCK_UNLESS_NET_MPSAFE() do { } while (0) | |||
532 | #define KERNEL_UNLOCK_UNLESS_NET_MPSAFE() do { } while (0) | |||
533 | ||||
534 | #define SOFTNET_LOCK_UNLESS_NET_MPSAFE() do { } while (0) | |||
535 | #define SOFTNET_UNLOCK_UNLESS_NET_MPSAFE() do { } while (0) | |||
536 | ||||
537 | #else /* NET_MPSAFE */ | |||
538 | ||||
539 | #define KERNEL_LOCK_UNLESS_NET_MPSAFE() \ | |||
540 | do { KERNEL_LOCK(1, NULL); } while (0) | |||
541 | #define KERNEL_UNLOCK_UNLESS_NET_MPSAFE() \ | |||
542 | do { KERNEL_UNLOCK_ONE(NULL); } while (0) | |||
543 | ||||
544 | #define SOFTNET_LOCK_UNLESS_NET_MPSAFE() \ | |||
545 | do { mutex_enter(softnet_lock); } while (0) | |||
546 | #define SOFTNET_UNLOCK_UNLESS_NET_MPSAFE() \ | |||
547 | do { mutex_exit(softnet_lock); } while (0) | |||
548 | ||||
549 | #endif /* NET_MPSAFE */ | |||
550 | ||||
551 | #define SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE() \ | |||
552 | do { \ | |||
553 | SOFTNET_LOCK_UNLESS_NET_MPSAFE(); \ | |||
554 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); \ | |||
555 | } while (0) | |||
556 | ||||
557 | #define SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE() \ | |||
558 | do { \ | |||
559 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); \ | |||
560 | SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); \ | |||
561 | } while (0) | |||
562 | ||||
445 | #endif /* _KERNEL */ | 563 | #endif /* _KERNEL */ | |
446 | 564 | |||
447 | #define IFFBITS \ | 565 | #define IFFBITS \ | |
448 | "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS" \ | 566 | "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS" \ | |
449 | "\7RUNNING\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX" \ | 567 | "\7RUNNING\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX" \ | |
450 | "\15LINK0\16LINK1\17LINK2\20MULTICAST" | 568 | "\15LINK0\16LINK1\17LINK2\20MULTICAST" | |
451 | 569 | |||
452 | /* flags set internally only: */ | 570 | /* flags set internally only: */ | |
453 | #define IFF_CANTCHANGE \ | 571 | #define IFF_CANTCHANGE \ | |
454 | (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ | 572 | (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ | |
455 | IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC) | 573 | IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC) | |
456 | 574 | |||
457 | /* | 575 | /* | |
@@ -946,44 +1064,47 @@ struct ifaddr *if_dl_create(const struct | @@ -946,44 +1064,47 @@ struct ifaddr *if_dl_create(const struct | |||
946 | void if_activate_sadl(struct ifnet *, struct ifaddr *, | 1064 | void if_activate_sadl(struct ifnet *, struct ifaddr *, | |
947 | const struct sockaddr_dl *); | 1065 | const struct sockaddr_dl *); | |
948 | void if_set_sadl(struct ifnet *, const void *, u_char, bool); | 1066 | void if_set_sadl(struct ifnet *, const void *, u_char, bool); | |
949 | void if_alloc_sadl(struct ifnet *); | 1067 | void if_alloc_sadl(struct ifnet *); | |
950 | int if_initialize(struct ifnet *); | 1068 | int if_initialize(struct ifnet *); | |
951 | void if_register(struct ifnet *); | 1069 | void if_register(struct ifnet *); | |
952 | int if_attach(struct ifnet *); /* Deprecated. Use if_initialize and if_register */ | 1070 | int if_attach(struct ifnet *); /* Deprecated. Use if_initialize and if_register */ | |
953 | void if_attachdomain(void); | 1071 | void if_attachdomain(void); | |
954 | void if_deactivate(struct ifnet *); | 1072 | void if_deactivate(struct ifnet *); | |
955 | bool if_is_deactivated(const struct ifnet *); | 1073 | bool if_is_deactivated(const struct ifnet *); | |
956 | void if_purgeaddrs(struct ifnet *, int, void (*)(struct ifaddr *)); | 1074 | void if_purgeaddrs(struct ifnet *, int, void (*)(struct ifaddr *)); | |
957 | void if_detach(struct ifnet *); | 1075 | void if_detach(struct ifnet *); | |
958 | void if_down(struct ifnet *); | 1076 | void if_down(struct ifnet *); | |
1077 | void if_down_locked(struct ifnet *); | |||
959 | void if_link_state_change(struct ifnet *, int); | 1078 | void if_link_state_change(struct ifnet *, int); | |
960 | void if_link_state_change_softint(struct ifnet *, int); | 1079 | void if_link_state_change_softint(struct ifnet *, int); | |
961 | void if_up(struct ifnet *); | 1080 | void if_up(struct ifnet *); | |
962 | void ifinit(void); | 1081 | void ifinit(void); | |
963 | void ifinit1(void); | 1082 | void ifinit1(void); | |
964 | int ifaddrpref_ioctl(struct socket *, u_long, void *, struct ifnet *); | 1083 | int ifaddrpref_ioctl(struct socket *, u_long, void *, struct ifnet *); | |
965 | extern int (*ifioctl)(struct socket *, u_long, void *, struct lwp *); | 1084 | extern int (*ifioctl)(struct socket *, u_long, void *, struct lwp *); | |
966 | int ifioctl_common(struct ifnet *, u_long, void *); | 1085 | int ifioctl_common(struct ifnet *, u_long, void *); | |
967 | int ifpromisc(struct ifnet *, int); | 1086 | int ifpromisc(struct ifnet *, int); | |
1087 | int ifpromisc_locked(struct ifnet *, int); | |||
968 | int if_addr_init(ifnet_t *, struct ifaddr *, bool); | 1088 | int if_addr_init(ifnet_t *, struct ifaddr *, bool); | |
969 | int if_do_dad(struct ifnet *); | 1089 | int if_do_dad(struct ifnet *); | |
970 | int if_mcast_op(ifnet_t *, const unsigned long, const struct sockaddr *); | 1090 | int if_mcast_op(ifnet_t *, const unsigned long, const struct sockaddr *); | |
971 | int if_flags_set(struct ifnet *, const short); | 1091 | int if_flags_set(struct ifnet *, const short); | |
972 | int if_clone_list(int, char *, int *); | 1092 | int if_clone_list(int, char *, int *); | |
973 | 1093 | |||
974 | struct ifnet *ifunit(const char *); | 1094 | struct ifnet *ifunit(const char *); | |
975 | struct ifnet *if_get(const char *, struct psref *); | 1095 | struct ifnet *if_get(const char *, struct psref *); | |
976 | ifnet_t *if_byindex(u_int); | 1096 | ifnet_t *if_byindex(u_int); | |
1097 | ifnet_t *_if_byindex(u_int); | |||
977 | ifnet_t *if_get_byindex(u_int, struct psref *); | 1098 | ifnet_t *if_get_byindex(u_int, struct psref *); | |
978 | ifnet_t *if_get_bylla(const void *, unsigned char, struct psref *); | 1099 | ifnet_t *if_get_bylla(const void *, unsigned char, struct psref *); | |
979 | void if_put(const struct ifnet *, struct psref *); | 1100 | void if_put(const struct ifnet *, struct psref *); | |
980 | void if_acquire(struct ifnet *, struct psref *); | 1101 | void if_acquire(struct ifnet *, struct psref *); | |
981 | #define if_release if_put | 1102 | #define if_release if_put | |
982 | 1103 | |||
983 | static inline if_index_t | 1104 | static inline if_index_t | |
984 | if_get_index(const struct ifnet *ifp) | 1105 | if_get_index(const struct ifnet *ifp) | |
985 | { | 1106 | { | |
986 | 1107 | |||
987 | return ifp != NULL ? ifp->if_index : 0; | 1108 | return ifp != NULL ? ifp->if_index : 0; | |
988 | } | 1109 | } | |
989 | 1110 | |||
@@ -1121,29 +1242,29 @@ __END_DECLS | @@ -1121,29 +1242,29 @@ __END_DECLS | |||
1121 | IFADDR_WRITER_INSERT_HEAD((__ifp), (__new)); \ | 1242 | IFADDR_WRITER_INSERT_HEAD((__ifp), (__new)); \ | |
1122 | } else { \ | 1243 | } else { \ | |
1123 | struct ifaddr *__ifa; \ | 1244 | struct ifaddr *__ifa; \ | |
1124 | IFADDR_WRITER_FOREACH(__ifa, (__ifp)) { \ | 1245 | IFADDR_WRITER_FOREACH(__ifa, (__ifp)) { \ | |
1125 | if (IFADDR_WRITER_NEXT(__ifa) == NULL) {\ | 1246 | if (IFADDR_WRITER_NEXT(__ifa) == NULL) {\ | |
1126 | IFADDR_WRITER_INSERT_AFTER(__ifa,\ | 1247 | IFADDR_WRITER_INSERT_AFTER(__ifa,\ | |
1127 | (__new)); \ | 1248 | (__new)); \ | |
1128 | break; \ | 1249 | break; \ | |
1129 | } \ | 1250 | } \ | |
1130 | } \ | 1251 | } \ | |
1131 | } \ | 1252 | } \ | |
1132 | } while (0) | 1253 | } while (0) | |
1133 | 1254 | |||
1134 | #define IFNET_LOCK() mutex_enter(&ifnet_mtx) | 1255 | #define IFNET_GLOBAL_LOCK() mutex_enter(&ifnet_mtx) | |
1135 | #define IFNET_UNLOCK() mutex_exit(&ifnet_mtx) | 1256 | #define IFNET_GLOBAL_UNLOCK() mutex_exit(&ifnet_mtx) | |
1136 | #define IFNET_LOCKED() mutex_owned(&ifnet_mtx) | 1257 | #define IFNET_GLOBAL_LOCKED() mutex_owned(&ifnet_mtx) | |
1137 | 1258 | |||
1138 | #define IFNET_READER_EMPTY() \ | 1259 | #define IFNET_READER_EMPTY() \ | |
1139 | (PSLIST_READER_FIRST(&ifnet_pslist, struct ifnet, if_pslist_entry) == NULL) | 1260 | (PSLIST_READER_FIRST(&ifnet_pslist, struct ifnet, if_pslist_entry) == NULL) | |
1140 | #define IFNET_READER_FIRST() \ | 1261 | #define IFNET_READER_FIRST() \ | |
1141 | PSLIST_READER_FIRST(&ifnet_pslist, struct ifnet, if_pslist_entry) | 1262 | PSLIST_READER_FIRST(&ifnet_pslist, struct ifnet, if_pslist_entry) | |
1142 | #define IFNET_READER_NEXT(__ifp) \ | 1263 | #define IFNET_READER_NEXT(__ifp) \ | |
1143 | PSLIST_READER_NEXT((__ifp), struct ifnet, if_pslist_entry) | 1264 | PSLIST_READER_NEXT((__ifp), struct ifnet, if_pslist_entry) | |
1144 | #define IFNET_READER_FOREACH(__ifp) \ | 1265 | #define IFNET_READER_FOREACH(__ifp) \ | |
1145 | PSLIST_READER_FOREACH((__ifp), &ifnet_pslist, struct ifnet, \ | 1266 | PSLIST_READER_FOREACH((__ifp), &ifnet_pslist, struct ifnet, \ | |
1146 | if_pslist_entry) | 1267 | if_pslist_entry) | |
1147 | #define IFNET_WRITER_INSERT_HEAD(__ifp) \ | 1268 | #define IFNET_WRITER_INSERT_HEAD(__ifp) \ | |
1148 | PSLIST_WRITER_INSERT_HEAD(&ifnet_pslist, (__ifp), if_pslist_entry) | 1269 | PSLIST_WRITER_INSERT_HEAD(&ifnet_pslist, (__ifp), if_pslist_entry) | |
1149 | #define IFNET_WRITER_REMOVE(__ifp) \ | 1270 | #define IFNET_WRITER_REMOVE(__ifp) \ | |
@@ -1163,26 +1284,30 @@ __END_DECLS | @@ -1163,26 +1284,30 @@ __END_DECLS | |||
1163 | IFNET_WRITER_INSERT_HEAD((__new)); \ | 1284 | IFNET_WRITER_INSERT_HEAD((__new)); \ | |
1164 | } else { \ | 1285 | } else { \ | |
1165 | struct ifnet *__ifp; \ | 1286 | struct ifnet *__ifp; \ | |
1166 | IFNET_WRITER_FOREACH(__ifp) { \ | 1287 | IFNET_WRITER_FOREACH(__ifp) { \ | |
1167 | if (IFNET_WRITER_NEXT(__ifp) == NULL) { \ | 1288 | if (IFNET_WRITER_NEXT(__ifp) == NULL) { \ | |
1168 | IFNET_WRITER_INSERT_AFTER(__ifp,\ | 1289 | IFNET_WRITER_INSERT_AFTER(__ifp,\ | |
1169 | (__new)); \ | 1290 | (__new)); \ | |
1170 | break; \ | 1291 | break; \ | |
1171 | } \ | 1292 | } \ | |
1172 | } \ | 1293 | } \ | |
1173 | } \ | 1294 | } \ | |
1174 | } while (0) | 1295 | } while (0) | |
1175 | 1296 | |||
1297 | #define IFNET_LOCK(ifp) mutex_enter((ifp)->if_ioctl_lock) | |||
1298 | #define IFNET_UNLOCK(ifp) mutex_exit((ifp)->if_ioctl_lock) | |||
1299 | #define IFNET_LOCKED(ifp) mutex_owned((ifp)->if_ioctl_lock) | |||
1300 | ||||
1176 | extern struct pslist_head ifnet_pslist; | 1301 | extern struct pslist_head ifnet_pslist; | |
1177 | extern kmutex_t ifnet_mtx; | 1302 | extern kmutex_t ifnet_mtx; | |
1178 | 1303 | |||
1179 | extern struct ifnet *lo0ifp; | 1304 | extern struct ifnet *lo0ifp; | |
1180 | 1305 | |||
1181 | /* | 1306 | /* | |
1182 | * ifq sysctl support | 1307 | * ifq sysctl support | |
1183 | */ | 1308 | */ | |
1184 | int sysctl_ifq(int *name, u_int namelen, void *oldp, | 1309 | int sysctl_ifq(int *name, u_int namelen, void *oldp, | |
1185 | size_t *oldlenp, void *newp, size_t newlen, | 1310 | size_t *oldlenp, void *newp, size_t newlen, | |
1186 | struct ifqueue *ifq); | 1311 | struct ifqueue *ifq); | |
1187 | /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */ | 1312 | /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */ | |
1188 | #define IFQCTL_LEN 1 | 1313 | #define IFQCTL_LEN 1 |
--- src/sys/net/if_bridge.c 2017/12/10 10:10:24 1.134.6.4
+++ src/sys/net/if_bridge.c 2018/01/02 10:20:33 1.134.6.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_bridge.c,v 1.134.6.4 2017/12/10 10:10:24 snj Exp $ */ | 1 | /* $NetBSD: if_bridge.c,v 1.134.6.5 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright 2001 Wasabi Systems, Inc. | 4 | * Copyright 2001 Wasabi Systems, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. | 7 | * Written by Jason R. Thorpe for Wasabi Systems, Inc. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -70,27 +70,27 @@ | @@ -70,27 +70,27 @@ | |||
70 | 70 | |||
71 | /* | 71 | /* | |
72 | * Network interface bridge support. | 72 | * Network interface bridge support. | |
73 | * | 73 | * | |
74 | * TODO: | 74 | * TODO: | |
75 | * | 75 | * | |
76 | * - Currently only supports Ethernet-like interfaces (Ethernet, | 76 | * - Currently only supports Ethernet-like interfaces (Ethernet, | |
77 | * 802.11, VLANs on Ethernet, etc.) Figure out a nice way | 77 | * 802.11, VLANs on Ethernet, etc.) Figure out a nice way | |
78 | * to bridge other types of interfaces (FDDI-FDDI, and maybe | 78 | * to bridge other types of interfaces (FDDI-FDDI, and maybe | |
79 | * consider heterogenous bridges). | 79 | * consider heterogenous bridges). | |
80 | */ | 80 | */ | |
81 | 81 | |||
82 | #include <sys/cdefs.h> | 82 | #include <sys/cdefs.h> | |
83 | __KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.4 2017/12/10 10:10:24 snj Exp $"); | 83 | __KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.134.6.5 2018/01/02 10:20:33 snj Exp $"); | |
84 | 84 | |||
85 | #ifdef _KERNEL_OPT | 85 | #ifdef _KERNEL_OPT | |
86 | #include "opt_bridge_ipf.h" | 86 | #include "opt_bridge_ipf.h" | |
87 | #include "opt_inet.h" | 87 | #include "opt_inet.h" | |
88 | #include "opt_net_mpsafe.h" | 88 | #include "opt_net_mpsafe.h" | |
89 | #endif /* _KERNEL_OPT */ | 89 | #endif /* _KERNEL_OPT */ | |
90 | 90 | |||
91 | #include <sys/param.h> | 91 | #include <sys/param.h> | |
92 | #include <sys/kernel.h> | 92 | #include <sys/kernel.h> | |
93 | #include <sys/mbuf.h> | 93 | #include <sys/mbuf.h> | |
94 | #include <sys/queue.h> | 94 | #include <sys/queue.h> | |
95 | #include <sys/socket.h> | 95 | #include <sys/socket.h> | |
96 | #include <sys/socketvar.h> /* for softnet_lock */ | 96 | #include <sys/socketvar.h> /* for softnet_lock */ | |
@@ -414,27 +414,30 @@ bridge_clone_create(struct if_clone *ifc | @@ -414,27 +414,30 @@ bridge_clone_create(struct if_clone *ifc | |||
414 | bridge_rtage_work, sc, PRI_SOFTNET, IPL_SOFTNET, WQ_MPSAFE); | 414 | bridge_rtage_work, sc, PRI_SOFTNET, IPL_SOFTNET, WQ_MPSAFE); | |
415 | if (error) | 415 | if (error) | |
416 | panic("%s: workqueue_create %d\n", __func__, error); | 416 | panic("%s: workqueue_create %d\n", __func__, error); | |
417 | 417 | |||
418 | callout_init(&sc->sc_brcallout, CALLOUT_MPSAFE); | 418 | callout_init(&sc->sc_brcallout, CALLOUT_MPSAFE); | |
419 | callout_init(&sc->sc_bstpcallout, CALLOUT_MPSAFE); | 419 | callout_init(&sc->sc_bstpcallout, CALLOUT_MPSAFE); | |
420 | 420 | |||
421 | mutex_init(&sc->sc_iflist_psref.bip_lock, MUTEX_DEFAULT, IPL_NONE); | 421 | mutex_init(&sc->sc_iflist_psref.bip_lock, MUTEX_DEFAULT, IPL_NONE); | |
422 | PSLIST_INIT(&sc->sc_iflist_psref.bip_iflist); | 422 | PSLIST_INIT(&sc->sc_iflist_psref.bip_iflist); | |
423 | sc->sc_iflist_psref.bip_psz = pserialize_create(); | 423 | sc->sc_iflist_psref.bip_psz = pserialize_create(); | |
424 | 424 | |||
425 | if_initname(ifp, ifc->ifc_name, unit); | 425 | if_initname(ifp, ifc->ifc_name, unit); | |
426 | ifp->if_softc = sc; | 426 | ifp->if_softc = sc; | |
427 | ifp->if_extflags = IFEF_OUTPUT_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; | 427 | ifp->if_extflags = IFEF_NO_LINK_STATE_CHANGE; | |
428 | #ifdef NET_MPSAFE | |||
429 | ifp->if_extflags |= IFEF_MPSAFE; | |||
430 | #endif | |||
428 | ifp->if_mtu = ETHERMTU; | 431 | ifp->if_mtu = ETHERMTU; | |
429 | ifp->if_ioctl = bridge_ioctl; | 432 | ifp->if_ioctl = bridge_ioctl; | |
430 | ifp->if_output = bridge_output; | 433 | ifp->if_output = bridge_output; | |
431 | ifp->if_start = bridge_start; | 434 | ifp->if_start = bridge_start; | |
432 | ifp->if_stop = bridge_stop; | 435 | ifp->if_stop = bridge_stop; | |
433 | ifp->if_init = bridge_init; | 436 | ifp->if_init = bridge_init; | |
434 | ifp->if_type = IFT_BRIDGE; | 437 | ifp->if_type = IFT_BRIDGE; | |
435 | ifp->if_addrlen = 0; | 438 | ifp->if_addrlen = 0; | |
436 | ifp->if_dlt = DLT_EN10MB; | 439 | ifp->if_dlt = DLT_EN10MB; | |
437 | ifp->if_hdrlen = ETHER_HDR_LEN; | 440 | ifp->if_hdrlen = ETHER_HDR_LEN; | |
438 | 441 | |||
439 | error = if_initialize(ifp); | 442 | error = if_initialize(ifp); | |
440 | if (error != 0) { | 443 | if (error != 0) { | |
@@ -767,27 +770,30 @@ bridge_ioctl_add(struct bridge_softc *sc | @@ -767,27 +770,30 @@ bridge_ioctl_add(struct bridge_softc *sc | |||
767 | goto out; | 770 | goto out; | |
768 | } | 771 | } | |
769 | 772 | |||
770 | bif = kmem_alloc(sizeof(*bif), KM_SLEEP); | 773 | bif = kmem_alloc(sizeof(*bif), KM_SLEEP); | |
771 | 774 | |||
772 | switch (ifs->if_type) { | 775 | switch (ifs->if_type) { | |
773 | case IFT_ETHER: | 776 | case IFT_ETHER: | |
774 | if (sc->sc_if.if_mtu != ifs->if_mtu) { | 777 | if (sc->sc_if.if_mtu != ifs->if_mtu) { | |
775 | error = EINVAL; | 778 | error = EINVAL; | |
776 | goto out; | 779 | goto out; | |
777 | } | 780 | } | |
778 | /* FALLTHROUGH */ | 781 | /* FALLTHROUGH */ | |
779 | case IFT_L2TP: | 782 | case IFT_L2TP: | |
780 | if ((error = ether_enable_vlan_mtu(ifs)) > 0) | 783 | IFNET_LOCK(ifs); | |
784 | error = ether_enable_vlan_mtu(ifs); | |||
785 | IFNET_UNLOCK(ifs); | |||
786 | if (error > 0) | |||
781 | goto out; | 787 | goto out; | |
782 | /* | 788 | /* | |
783 | * Place the interface into promiscuous mode. | 789 | * Place the interface into promiscuous mode. | |
784 | */ | 790 | */ | |
785 | error = ifpromisc(ifs, 1); | 791 | error = ifpromisc(ifs, 1); | |
786 | if (error) | 792 | if (error) | |
787 | goto out; | 793 | goto out; | |
788 | break; | 794 | break; | |
789 | default: | 795 | default: | |
790 | error = EINVAL; | 796 | error = EINVAL; | |
791 | goto out; | 797 | goto out; | |
792 | } | 798 | } | |
793 | 799 | |||
@@ -848,27 +854,29 @@ bridge_ioctl_del(struct bridge_softc *sc | @@ -848,27 +854,29 @@ bridge_ioctl_del(struct bridge_softc *sc | |||
848 | 854 | |||
849 | bridge_delete_member(sc, bif); | 855 | bridge_delete_member(sc, bif); | |
850 | 856 | |||
851 | BRIDGE_UNLOCK(sc); | 857 | BRIDGE_UNLOCK(sc); | |
852 | 858 | |||
853 | switch (ifs->if_type) { | 859 | switch (ifs->if_type) { | |
854 | case IFT_ETHER: | 860 | case IFT_ETHER: | |
855 | case IFT_L2TP: | 861 | case IFT_L2TP: | |
856 | /* | 862 | /* | |
857 | * Take the interface out of promiscuous mode. | 863 | * Take the interface out of promiscuous mode. | |
858 | * Don't call it with holding a spin lock. | 864 | * Don't call it with holding a spin lock. | |
859 | */ | 865 | */ | |
860 | (void) ifpromisc(ifs, 0); | 866 | (void) ifpromisc(ifs, 0); | |
867 | IFNET_LOCK(ifs); | |||
861 | (void) ether_disable_vlan_mtu(ifs); | 868 | (void) ether_disable_vlan_mtu(ifs); | |
869 | IFNET_UNLOCK(ifs); | |||
862 | break; | 870 | break; | |
863 | default: | 871 | default: | |
864 | #ifdef DIAGNOSTIC | 872 | #ifdef DIAGNOSTIC | |
865 | panic("bridge_delete_member: impossible"); | 873 | panic("bridge_delete_member: impossible"); | |
866 | #endif | 874 | #endif | |
867 | break; | 875 | break; | |
868 | } | 876 | } | |
869 | 877 | |||
870 | bridge_rtdelete(sc, ifs); | 878 | bridge_rtdelete(sc, ifs); | |
871 | 879 | |||
872 | if (sc->sc_if.if_flags & IFF_RUNNING) | 880 | if (sc->sc_if.if_flags & IFF_RUNNING) | |
873 | bstp_initialization(sc); | 881 | bstp_initialization(sc); | |
874 | 882 | |||
@@ -1322,56 +1330,52 @@ bridge_ifdetach(struct ifnet *ifp) | @@ -1322,56 +1330,52 @@ bridge_ifdetach(struct ifnet *ifp) | |||
1322 | (void) bridge_ioctl_del(sc, &breq); | 1330 | (void) bridge_ioctl_del(sc, &breq); | |
1323 | } | 1331 | } | |
1324 | 1332 | |||
1325 | /* | 1333 | /* | |
1326 | * bridge_init: | 1334 | * bridge_init: | |
1327 | * | 1335 | * | |
1328 | * Initialize a bridge interface. | 1336 | * Initialize a bridge interface. | |
1329 | */ | 1337 | */ | |
1330 | static int | 1338 | static int | |
1331 | bridge_init(struct ifnet *ifp) | 1339 | bridge_init(struct ifnet *ifp) | |
1332 | { | 1340 | { | |
1333 | struct bridge_softc *sc = ifp->if_softc; | 1341 | struct bridge_softc *sc = ifp->if_softc; | |
1334 | 1342 | |||
1335 | if (ifp->if_flags & IFF_RUNNING) | 1343 | KASSERT((ifp->if_flags & IFF_RUNNING) == 0); | |
1336 | return 0; | |||
1337 | 1344 | |||
1338 | callout_reset(&sc->sc_brcallout, bridge_rtable_prune_period * hz, | 1345 | callout_reset(&sc->sc_brcallout, bridge_rtable_prune_period * hz, | |
1339 | bridge_timer, sc); | 1346 | bridge_timer, sc); | |
1347 | bstp_initialization(sc); | |||
1340 | 1348 | |||
1341 | ifp->if_flags |= IFF_RUNNING; | 1349 | ifp->if_flags |= IFF_RUNNING; | |
1342 | bstp_initialization(sc); | |||
1343 | return 0; | 1350 | return 0; | |
1344 | } | 1351 | } | |
1345 | 1352 | |||
1346 | /* | 1353 | /* | |
1347 | * bridge_stop: | 1354 | * bridge_stop: | |
1348 | * | 1355 | * | |
1349 | * Stop the bridge interface. | 1356 | * Stop the bridge interface. | |
1350 | */ | 1357 | */ | |
1351 | static void | 1358 | static void | |
1352 | bridge_stop(struct ifnet *ifp, int disable) | 1359 | bridge_stop(struct ifnet *ifp, int disable) | |
1353 | { | 1360 | { | |
1354 | struct bridge_softc *sc = ifp->if_softc; | 1361 | struct bridge_softc *sc = ifp->if_softc; | |
1355 | 1362 | |||
1356 | if ((ifp->if_flags & IFF_RUNNING) == 0) | 1363 | KASSERT((ifp->if_flags & IFF_RUNNING) != 0); | |
1357 | return; | 1364 | ifp->if_flags &= ~IFF_RUNNING; | |
1358 | 1365 | |||
1359 | callout_stop(&sc->sc_brcallout); | 1366 | callout_stop(&sc->sc_brcallout); | |
1360 | bstp_stop(sc); | 1367 | bstp_stop(sc); | |
1361 | ||||
1362 | bridge_rtflush(sc, IFBF_FLUSHDYN); | 1368 | bridge_rtflush(sc, IFBF_FLUSHDYN); | |
1363 | ||||
1364 | ifp->if_flags &= ~IFF_RUNNING; | |||
1365 | } | 1369 | } | |
1366 | 1370 | |||
1367 | /* | 1371 | /* | |
1368 | * bridge_enqueue: | 1372 | * bridge_enqueue: | |
1369 | * | 1373 | * | |
1370 | * Enqueue a packet on a bridge member interface. | 1374 | * Enqueue a packet on a bridge member interface. | |
1371 | */ | 1375 | */ | |
1372 | void | 1376 | void | |
1373 | bridge_enqueue(struct bridge_softc *sc, struct ifnet *dst_ifp, struct mbuf *m, | 1377 | bridge_enqueue(struct bridge_softc *sc, struct ifnet *dst_ifp, struct mbuf *m, | |
1374 | int runfilt) | 1378 | int runfilt) | |
1375 | { | 1379 | { | |
1376 | int len, error; | 1380 | int len, error; | |
1377 | short mflags; | 1381 | short mflags; | |
@@ -1435,27 +1439,27 @@ bridge_enqueue(struct bridge_softc *sc, | @@ -1435,27 +1439,27 @@ bridge_enqueue(struct bridge_softc *sc, | |||
1435 | */ | 1439 | */ | |
1436 | int | 1440 | int | |
1437 | bridge_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa, | 1441 | bridge_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *sa, | |
1438 | const struct rtentry *rt) | 1442 | const struct rtentry *rt) | |
1439 | { | 1443 | { | |
1440 | struct ether_header *eh; | 1444 | struct ether_header *eh; | |
1441 | struct ifnet *dst_if; | 1445 | struct ifnet *dst_if; | |
1442 | struct bridge_softc *sc; | 1446 | struct bridge_softc *sc; | |
1443 | int s; | 1447 | int s; | |
1444 | 1448 | |||
1445 | /* | 1449 | /* | |
1446 | * bridge_output() is called from ether_output(), furthermore | 1450 | * bridge_output() is called from ether_output(), furthermore | |
1447 | * ifp argument doesn't point to bridge(4). So, don't assert | 1451 | * ifp argument doesn't point to bridge(4). So, don't assert | |
1448 | * IFEF_OUTPUT_MPSAFE here. | 1452 | * IFEF_MPSAFE here. | |
1449 | */ | 1453 | */ | |
1450 | 1454 | |||
1451 | if (m->m_len < ETHER_HDR_LEN) { | 1455 | if (m->m_len < ETHER_HDR_LEN) { | |
1452 | m = m_pullup(m, ETHER_HDR_LEN); | 1456 | m = m_pullup(m, ETHER_HDR_LEN); | |
1453 | if (m == NULL) | 1457 | if (m == NULL) | |
1454 | return 0; | 1458 | return 0; | |
1455 | } | 1459 | } | |
1456 | 1460 | |||
1457 | eh = mtod(m, struct ether_header *); | 1461 | eh = mtod(m, struct ether_header *); | |
1458 | sc = ifp->if_bridge; | 1462 | sc = ifp->if_bridge; | |
1459 | 1463 | |||
1460 | if (ETHER_IS_MULTICAST(eh->ether_dhost)) { | 1464 | if (ETHER_IS_MULTICAST(eh->ether_dhost)) { | |
1461 | if (memcmp(etherbroadcastaddr, | 1465 | if (memcmp(etherbroadcastaddr, |
--- src/sys/net/Attic/if_etherip.c 2017/12/10 10:10:25 1.38.10.1
+++ src/sys/net/Attic/if_etherip.c 2018/01/02 10:20:33 1.38.10.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_etherip.c,v 1.38.10.1 2017/12/10 10:10:25 snj Exp $ */ | 1 | /* $NetBSD: if_etherip.c,v 1.38.10.2 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2006, Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> | 4 | * Copyright (c) 2006, Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> | |
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. | |
@@ -76,27 +76,27 @@ | @@ -76,27 +76,27 @@ | |||
76 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 76 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
77 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 77 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
78 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | 78 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |
79 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 79 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
80 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 80 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
81 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 81 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
82 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 82 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
83 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 83 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
84 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 84 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
85 | * SUCH DAMAGE. | 85 | * SUCH DAMAGE. | |
86 | */ | 86 | */ | |
87 | 87 | |||
88 | #include <sys/cdefs.h> | 88 | #include <sys/cdefs.h> | |
89 | __KERNEL_RCSID(0, "$NetBSD: if_etherip.c,v 1.38.10.1 2017/12/10 10:10:25 snj Exp $"); | 89 | __KERNEL_RCSID(0, "$NetBSD: if_etherip.c,v 1.38.10.2 2018/01/02 10:20:33 snj Exp $"); | |
90 | 90 | |||
91 | #ifdef _KERNEL_OPT | 91 | #ifdef _KERNEL_OPT | |
92 | #include "opt_inet.h" | 92 | #include "opt_inet.h" | |
93 | #endif | 93 | #endif | |
94 | 94 | |||
95 | #include <sys/param.h> | 95 | #include <sys/param.h> | |
96 | #include <sys/systm.h> | 96 | #include <sys/systm.h> | |
97 | #include <sys/kernel.h> | 97 | #include <sys/kernel.h> | |
98 | #include <sys/malloc.h> | 98 | #include <sys/malloc.h> | |
99 | #include <sys/conf.h> | 99 | #include <sys/conf.h> | |
100 | #include <sys/device.h> | 100 | #include <sys/device.h> | |
101 | #include <sys/errno.h> | 101 | #include <sys/errno.h> | |
102 | #include <sys/time.h> | 102 | #include <sys/time.h> | |
@@ -539,61 +539,61 @@ etherip_set_tunnel(struct ifnet *ifp, | @@ -539,61 +539,61 @@ etherip_set_tunnel(struct ifnet *ifp, | |||
539 | ifp->if_flags &= ~IFF_RUNNING; | 539 | ifp->if_flags &= ~IFF_RUNNING; | |
540 | 540 | |||
541 | osrc = sc->sc_src; sc->sc_src = NULL; | 541 | osrc = sc->sc_src; sc->sc_src = NULL; | |
542 | odst = sc->sc_dst; sc->sc_dst = NULL; | 542 | odst = sc->sc_dst; sc->sc_dst = NULL; | |
543 | 543 | |||
544 | sc->sc_src = sockaddr_dup(src, M_WAITOK); | 544 | sc->sc_src = sockaddr_dup(src, M_WAITOK); | |
545 | if (osrc) | 545 | if (osrc) | |
546 | sockaddr_free(osrc); | 546 | sockaddr_free(osrc); | |
547 | 547 | |||
548 | sc->sc_dst = sockaddr_dup(dst, M_WAITOK); | 548 | sc->sc_dst = sockaddr_dup(dst, M_WAITOK); | |
549 | if (odst) | 549 | if (odst) | |
550 | sockaddr_free(odst); | 550 | sockaddr_free(odst); | |
551 | 551 | |||
552 | ifp->if_flags |= IFF_RUNNING; | |||
553 | ||||
554 | sc->sc_si = softint_establish(SOFTINT_NET, etheripintr, sc); | 552 | sc->sc_si = softint_establish(SOFTINT_NET, etheripintr, sc); | |
555 | if (sc->sc_si == NULL) | 553 | if (sc->sc_si == NULL) | |
556 | error = ENOMEM; | 554 | error = ENOMEM; | |
557 | 555 | |||
556 | ifp->if_flags |= IFF_RUNNING; | |||
558 | out: | 557 | out: | |
559 | splx(s); | 558 | splx(s); | |
560 | 559 | |||
561 | return(error); | 560 | return(error); | |
562 | } | 561 | } | |
563 | 562 | |||
564 | static void | 563 | static void | |
565 | etherip_delete_tunnel(struct ifnet *ifp) | 564 | etherip_delete_tunnel(struct ifnet *ifp) | |
566 | { | 565 | { | |
567 | struct etherip_softc *sc = ifp->if_softc; | 566 | struct etherip_softc *sc = ifp->if_softc; | |
568 | int s; | 567 | int s; | |
569 | 568 | |||
570 | s = splsoftnet(); | 569 | s = splsoftnet(); | |
571 | 570 | |||
571 | ifp->if_flags &= ~IFF_RUNNING; | |||
572 | ||||
572 | if (sc->sc_si) { | 573 | if (sc->sc_si) { | |
573 | softint_disestablish(sc->sc_si); | 574 | softint_disestablish(sc->sc_si); | |
574 | sc->sc_si = NULL; | 575 | sc->sc_si = NULL; | |
575 | } | 576 | } | |
576 | 577 | |||
577 | if (sc->sc_src) { | 578 | if (sc->sc_src) { | |
578 | sockaddr_free(sc->sc_src); | 579 | sockaddr_free(sc->sc_src); | |
579 | sc->sc_src = NULL; | 580 | sc->sc_src = NULL; | |
580 | } | 581 | } | |
581 | if (sc->sc_dst) { | 582 | if (sc->sc_dst) { | |
582 | sockaddr_free(sc->sc_dst); | 583 | sockaddr_free(sc->sc_dst); | |
583 | sc->sc_dst = NULL; | 584 | sc->sc_dst = NULL; | |
584 | } | 585 | } | |
585 | 586 | |||
586 | ifp->if_flags &= ~IFF_RUNNING; | |||
587 | splx(s); | 587 | splx(s); | |
588 | } | 588 | } | |
589 | 589 | |||
590 | static int | 590 | static int | |
591 | etherip_init(struct ifnet *ifp) | 591 | etherip_init(struct ifnet *ifp) | |
592 | { | 592 | { | |
593 | struct etherip_softc *sc = ifp->if_softc; | 593 | struct etherip_softc *sc = ifp->if_softc; | |
594 | 594 | |||
595 | if (sc->sc_si == NULL) | 595 | if (sc->sc_si == NULL) | |
596 | sc->sc_si = softint_establish(SOFTINT_NET, etheripintr, sc); | 596 | sc->sc_si = softint_establish(SOFTINT_NET, etheripintr, sc); | |
597 | 597 | |||
598 | if (sc->sc_si == NULL) | 598 | if (sc->sc_si == NULL) | |
599 | return(ENOMEM); | 599 | return(ENOMEM); |
--- src/sys/net/if_ethersubr.c 2017/10/24 08:38:59 1.242.6.1
+++ src/sys/net/if_ethersubr.c 2018/01/02 10:20:33 1.242.6.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_ethersubr.c,v 1.242.6.1 2017/10/24 08:38:59 snj Exp $ */ | 1 | /* $NetBSD: if_ethersubr.c,v 1.242.6.2 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
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. | |
@@ -51,27 +51,27 @@ | @@ -51,27 +51,27 @@ | |||
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
58 | * SUCH DAMAGE. | 58 | * SUCH DAMAGE. | |
59 | * | 59 | * | |
60 | * @(#)if_ethersubr.c 8.2 (Berkeley) 4/4/96 | 60 | * @(#)if_ethersubr.c 8.2 (Berkeley) 4/4/96 | |
61 | */ | 61 | */ | |
62 | 62 | |||
63 | #include <sys/cdefs.h> | 63 | #include <sys/cdefs.h> | |
64 | __KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.242.6.1 2017/10/24 08:38:59 snj Exp $"); | 64 | __KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.242.6.2 2018/01/02 10:20:33 snj Exp $"); | |
65 | 65 | |||
66 | #ifdef _KERNEL_OPT | 66 | #ifdef _KERNEL_OPT | |
67 | #include "opt_inet.h" | 67 | #include "opt_inet.h" | |
68 | #include "opt_atalk.h" | 68 | #include "opt_atalk.h" | |
69 | #include "opt_mbuftrace.h" | 69 | #include "opt_mbuftrace.h" | |
70 | #include "opt_mpls.h" | 70 | #include "opt_mpls.h" | |
71 | #include "opt_gateway.h" | 71 | #include "opt_gateway.h" | |
72 | #include "opt_pppoe.h" | 72 | #include "opt_pppoe.h" | |
73 | #include "opt_net_mpsafe.h" | 73 | #include "opt_net_mpsafe.h" | |
74 | #endif | 74 | #endif | |
75 | 75 | |||
76 | #include "vlan.h" | 76 | #include "vlan.h" | |
77 | #include "pppoe.h" | 77 | #include "pppoe.h" | |
@@ -194,33 +194,26 @@ ether_output(struct ifnet * const ifp0, | @@ -194,33 +194,26 @@ ether_output(struct ifnet * const ifp0, | |||
194 | int error = 0, hdrcmplt = 0; | 194 | int error = 0, hdrcmplt = 0; | |
195 | uint8_t esrc[6], edst[6]; | 195 | uint8_t esrc[6], edst[6]; | |
196 | struct mbuf *m = m0; | 196 | struct mbuf *m = m0; | |
197 | struct mbuf *mcopy = NULL; | 197 | struct mbuf *mcopy = NULL; | |
198 | struct ether_header *eh; | 198 | struct ether_header *eh; | |
199 | struct ifnet *ifp = ifp0; | 199 | struct ifnet *ifp = ifp0; | |
200 | #ifdef INET | 200 | #ifdef INET | |
201 | struct arphdr *ah; | 201 | struct arphdr *ah; | |
202 | #endif /* INET */ | 202 | #endif /* INET */ | |
203 | #ifdef NETATALK | 203 | #ifdef NETATALK | |
204 | struct at_ifaddr *aa; | 204 | struct at_ifaddr *aa; | |
205 | #endif /* NETATALK */ | 205 | #endif /* NETATALK */ | |
206 | 206 | |||
207 | /* | |||
208 | * some paths such as carp_output() call ethr_output() with "ifp" | |||
209 | * argument as other than ether ifnet. | |||
210 | */ | |||
211 | KASSERT(ifp->if_output != ether_output | |||
212 | || ifp->if_extflags & IFEF_OUTPUT_MPSAFE); | |||
213 | ||||
214 | #ifdef MBUFTRACE | 207 | #ifdef MBUFTRACE | |
215 | m_claimm(m, ifp->if_mowner); | 208 | m_claimm(m, ifp->if_mowner); | |
216 | #endif | 209 | #endif | |
217 | 210 | |||
218 | #if NCARP > 0 | 211 | #if NCARP > 0 | |
219 | if (ifp->if_type == IFT_CARP) { | 212 | if (ifp->if_type == IFT_CARP) { | |
220 | struct ifaddr *ifa; | 213 | struct ifaddr *ifa; | |
221 | int s = pserialize_read_enter(); | 214 | int s = pserialize_read_enter(); | |
222 | 215 | |||
223 | /* loop back if this is going to the carp interface */ | 216 | /* loop back if this is going to the carp interface */ | |
224 | if (dst != NULL && ifp0->if_link_state == LINK_STATE_UP && | 217 | if (dst != NULL && ifp0->if_link_state == LINK_STATE_UP && | |
225 | (ifa = ifa_ifwithaddr(dst)) != NULL) { | 218 | (ifa = ifa_ifwithaddr(dst)) != NULL) { | |
226 | if (ifa->ifa_ifp == ifp0) { | 219 | if (ifa->ifa_ifp == ifp0) { | |
@@ -941,27 +934,26 @@ ether_snprintf(char *buf, size_t len, co | @@ -941,27 +934,26 @@ ether_snprintf(char *buf, size_t len, co | |||
941 | } | 934 | } | |
942 | *--cp = '\0'; | 935 | *--cp = '\0'; | |
943 | return buf; | 936 | return buf; | |
944 | } | 937 | } | |
945 | 938 | |||
946 | /* | 939 | /* | |
947 | * Perform common duties while attaching to interface list | 940 | * Perform common duties while attaching to interface list | |
948 | */ | 941 | */ | |
949 | void | 942 | void | |
950 | ether_ifattach(struct ifnet *ifp, const uint8_t *lla) | 943 | ether_ifattach(struct ifnet *ifp, const uint8_t *lla) | |
951 | { | 944 | { | |
952 | struct ethercom *ec = (struct ethercom *)ifp; | 945 | struct ethercom *ec = (struct ethercom *)ifp; | |
953 | 946 | |||
954 | ifp->if_extflags |= IFEF_OUTPUT_MPSAFE; | |||
955 | ifp->if_type = IFT_ETHER; | 947 | ifp->if_type = IFT_ETHER; | |
956 | ifp->if_hdrlen = ETHER_HDR_LEN; | 948 | ifp->if_hdrlen = ETHER_HDR_LEN; | |
957 | ifp->if_dlt = DLT_EN10MB; | 949 | ifp->if_dlt = DLT_EN10MB; | |
958 | ifp->if_mtu = ETHERMTU; | 950 | ifp->if_mtu = ETHERMTU; | |
959 | ifp->if_output = ether_output; | 951 | ifp->if_output = ether_output; | |
960 | ifp->_if_input = ether_input; | 952 | ifp->_if_input = ether_input; | |
961 | if (ifp->if_baudrate == 0) | 953 | if (ifp->if_baudrate == 0) | |
962 | ifp->if_baudrate = IF_Mbps(10); /* just a default */ | 954 | ifp->if_baudrate = IF_Mbps(10); /* just a default */ | |
963 | 955 | |||
964 | if (lla != NULL) | 956 | if (lla != NULL) | |
965 | if_set_sadl(ifp, lla, ETHER_ADDR_LEN, !ETHER_IS_LOCAL(lla)); | 957 | if_set_sadl(ifp, lla, ETHER_ADDR_LEN, !ETHER_IS_LOCAL(lla)); | |
966 | 958 | |||
967 | LIST_INIT(&ec->ec_multiaddrs); | 959 | LIST_INIT(&ec->ec_multiaddrs); | |
@@ -1003,27 +995,27 @@ ether_ifdetach(struct ifnet *ifp) | @@ -1003,27 +995,27 @@ ether_ifdetach(struct ifnet *ifp) | |||
1003 | bridge_ifdetach(ifp); | 995 | bridge_ifdetach(ifp); | |
1004 | #endif | 996 | #endif | |
1005 | 997 | |||
1006 | bpf_detach(ifp); | 998 | bpf_detach(ifp); | |
1007 | 999 | |||
1008 | #if NVLAN > 0 | 1000 | #if NVLAN > 0 | |
1009 | if (ec->ec_nvlans) | 1001 | if (ec->ec_nvlans) | |
1010 | vlan_ifdetach(ifp); | 1002 | vlan_ifdetach(ifp); | |
1011 | #endif | 1003 | #endif | |
1012 | 1004 | |||
1013 | mutex_enter(ec->ec_lock); | 1005 | mutex_enter(ec->ec_lock); | |
1014 | while ((enm = LIST_FIRST(&ec->ec_multiaddrs)) != NULL) { | 1006 | while ((enm = LIST_FIRST(&ec->ec_multiaddrs)) != NULL) { | |
1015 | LIST_REMOVE(enm, enm_list); | 1007 | LIST_REMOVE(enm, enm_list); | |
1016 | kmem_free(enm, sizeof(*enm)); | 1008 | kmem_intr_free(enm, sizeof(*enm)); | |
1017 | ec->ec_multicnt--; | 1009 | ec->ec_multicnt--; | |
1018 | } | 1010 | } | |
1019 | mutex_exit(ec->ec_lock); | 1011 | mutex_exit(ec->ec_lock); | |
1020 | 1012 | |||
1021 | mutex_destroy(ec->ec_lock); | 1013 | mutex_destroy(ec->ec_lock); | |
1022 | 1014 | |||
1023 | ifp->if_mowner = NULL; | 1015 | ifp->if_mowner = NULL; | |
1024 | MOWNER_DETACH(&ec->ec_rx_mowner); | 1016 | MOWNER_DETACH(&ec->ec_rx_mowner); | |
1025 | MOWNER_DETACH(&ec->ec_tx_mowner); | 1017 | MOWNER_DETACH(&ec->ec_tx_mowner); | |
1026 | } | 1018 | } | |
1027 | 1019 | |||
1028 | #if 0 | 1020 | #if 0 | |
1029 | /* | 1021 | /* | |
@@ -1267,27 +1259,27 @@ ether_addmulti(const struct sockaddr *sa | @@ -1267,27 +1259,27 @@ ether_addmulti(const struct sockaddr *sa | |||
1267 | memcpy(enm->enm_addrhi, addrhi, 6); | 1259 | memcpy(enm->enm_addrhi, addrhi, 6); | |
1268 | enm->enm_refcount = 1; | 1260 | enm->enm_refcount = 1; | |
1269 | LIST_INSERT_HEAD(&ec->ec_multiaddrs, enm, enm_list); | 1261 | LIST_INSERT_HEAD(&ec->ec_multiaddrs, enm, enm_list); | |
1270 | ec->ec_multicnt++; | 1262 | ec->ec_multicnt++; | |
1271 | /* | 1263 | /* | |
1272 | * Return ENETRESET to inform the driver that the list has changed | 1264 | * Return ENETRESET to inform the driver that the list has changed | |
1273 | * and its reception filter should be adjusted accordingly. | 1265 | * and its reception filter should be adjusted accordingly. | |
1274 | */ | 1266 | */ | |
1275 | error = ENETRESET; | 1267 | error = ENETRESET; | |
1276 | enm = NULL; | 1268 | enm = NULL; | |
1277 | out: | 1269 | out: | |
1278 | mutex_exit(ec->ec_lock); | 1270 | mutex_exit(ec->ec_lock); | |
1279 | if (enm != NULL) | 1271 | if (enm != NULL) | |
1280 | kmem_free(enm, sizeof(*enm)); | 1272 | kmem_intr_free(enm, sizeof(*enm)); | |
1281 | return error; | 1273 | return error; | |
1282 | } | 1274 | } | |
1283 | 1275 | |||
1284 | /* | 1276 | /* | |
1285 | * Delete a multicast address record. | 1277 | * Delete a multicast address record. | |
1286 | */ | 1278 | */ | |
1287 | int | 1279 | int | |
1288 | ether_delmulti(const struct sockaddr *sa, struct ethercom *ec) | 1280 | ether_delmulti(const struct sockaddr *sa, struct ethercom *ec) | |
1289 | { | 1281 | { | |
1290 | struct ether_multi *enm; | 1282 | struct ether_multi *enm; | |
1291 | u_char addrlo[ETHER_ADDR_LEN]; | 1283 | u_char addrlo[ETHER_ADDR_LEN]; | |
1292 | u_char addrhi[ETHER_ADDR_LEN]; | 1284 | u_char addrhi[ETHER_ADDR_LEN]; | |
1293 | int error; | 1285 | int error; | |
@@ -1309,27 +1301,27 @@ ether_delmulti(const struct sockaddr *sa | @@ -1309,27 +1301,27 @@ ether_delmulti(const struct sockaddr *sa | |||
1309 | /* | 1301 | /* | |
1310 | * Still some claims to this record. | 1302 | * Still some claims to this record. | |
1311 | */ | 1303 | */ | |
1312 | error = 0; | 1304 | error = 0; | |
1313 | goto error; | 1305 | goto error; | |
1314 | } | 1306 | } | |
1315 | /* | 1307 | /* | |
1316 | * No remaining claims to this record; unlink and free it. | 1308 | * No remaining claims to this record; unlink and free it. | |
1317 | */ | 1309 | */ | |
1318 | LIST_REMOVE(enm, enm_list); | 1310 | LIST_REMOVE(enm, enm_list); | |
1319 | ec->ec_multicnt--; | 1311 | ec->ec_multicnt--; | |
1320 | mutex_exit(ec->ec_lock); | 1312 | mutex_exit(ec->ec_lock); | |
1321 | 1313 | |||
1322 | kmem_free(enm, sizeof(*enm)); | 1314 | kmem_intr_free(enm, sizeof(*enm)); | |
1323 | /* | 1315 | /* | |
1324 | * Return ENETRESET to inform the driver that the list has changed | 1316 | * Return ENETRESET to inform the driver that the list has changed | |
1325 | * and its reception filter should be adjusted accordingly. | 1317 | * and its reception filter should be adjusted accordingly. | |
1326 | */ | 1318 | */ | |
1327 | return ENETRESET; | 1319 | return ENETRESET; | |
1328 | error: | 1320 | error: | |
1329 | mutex_exit(ec->ec_lock); | 1321 | mutex_exit(ec->ec_lock); | |
1330 | return error; | 1322 | return error; | |
1331 | } | 1323 | } | |
1332 | 1324 | |||
1333 | void | 1325 | void | |
1334 | ether_set_ifflags_cb(struct ethercom *ec, ether_cb_t cb) | 1326 | ether_set_ifflags_cb(struct ethercom *ec, ether_cb_t cb) | |
1335 | { | 1327 | { |
--- src/sys/net/if_faith.c 2017/12/10 10:10:25 1.55.8.1
+++ src/sys/net/if_faith.c 2018/01/02 10:20:33 1.55.8.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_faith.c,v 1.55.8.1 2017/12/10 10:10:25 snj Exp $ */ | 1 | /* $NetBSD: if_faith.c,v 1.55.8.2 2018/01/02 10:20:33 snj Exp $ */ | |
2 | /* $KAME: if_faith.c,v 1.21 2001/02/20 07:59:26 itojun Exp $ */ | 2 | /* $KAME: if_faith.c,v 1.21 2001/02/20 07:59:26 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 1982, 1986, 1993 | 5 | * Copyright (c) 1982, 1986, 1993 | |
6 | * The Regents of the University of California. All rights reserved. | 6 | * The Regents of the University of California. All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -30,27 +30,27 @@ | @@ -30,27 +30,27 @@ | |||
30 | * SUCH DAMAGE. | 30 | * SUCH DAMAGE. | |
31 | */ | 31 | */ | |
32 | /* | 32 | /* | |
33 | * derived from | 33 | * derived from | |
34 | * @(#)if_loop.c 8.1 (Berkeley) 6/10/93 | 34 | * @(#)if_loop.c 8.1 (Berkeley) 6/10/93 | |
35 | * Id: if_loop.c,v 1.22 1996/06/19 16:24:10 wollman Exp | 35 | * Id: if_loop.c,v 1.22 1996/06/19 16:24:10 wollman Exp | |
36 | */ | 36 | */ | |
37 | 37 | |||
38 | /* | 38 | /* | |
39 | * IPv6-to-IPv4 TCP relay capturing interface | 39 | * IPv6-to-IPv4 TCP relay capturing interface | |
40 | */ | 40 | */ | |
41 | 41 | |||
42 | #include <sys/cdefs.h> | 42 | #include <sys/cdefs.h> | |
43 | __KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.55.8.1 2017/12/10 10:10:25 snj Exp $"); | 43 | __KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.55.8.2 2018/01/02 10:20:33 snj Exp $"); | |
44 | 44 | |||
45 | #ifdef _KERNEL_OPT | 45 | #ifdef _KERNEL_OPT | |
46 | #include "opt_inet.h" | 46 | #include "opt_inet.h" | |
47 | #endif | 47 | #endif | |
48 | 48 | |||
49 | #include <sys/param.h> | 49 | #include <sys/param.h> | |
50 | #include <sys/systm.h> | 50 | #include <sys/systm.h> | |
51 | #include <sys/kernel.h> | 51 | #include <sys/kernel.h> | |
52 | #include <sys/mbuf.h> | 52 | #include <sys/mbuf.h> | |
53 | #include <sys/socket.h> | 53 | #include <sys/socket.h> | |
54 | #include <sys/errno.h> | 54 | #include <sys/errno.h> | |
55 | #include <sys/ioctl.h> | 55 | #include <sys/ioctl.h> | |
56 | #include <sys/time.h> | 56 | #include <sys/time.h> | |
@@ -253,29 +253,29 @@ faithrtrequest(int cmd, struct rtentry * | @@ -253,29 +253,29 @@ faithrtrequest(int cmd, struct rtentry * | |||
253 | * Process an ioctl request. | 253 | * Process an ioctl request. | |
254 | */ | 254 | */ | |
255 | /* ARGSUSED */ | 255 | /* ARGSUSED */ | |
256 | static int | 256 | static int | |
257 | faithioctl(struct ifnet *ifp, u_long cmd, void *data) | 257 | faithioctl(struct ifnet *ifp, u_long cmd, void *data) | |
258 | { | 258 | { | |
259 | struct ifaddr *ifa; | 259 | struct ifaddr *ifa; | |
260 | struct ifreq *ifr = (struct ifreq *)data; | 260 | struct ifreq *ifr = (struct ifreq *)data; | |
261 | int error = 0; | 261 | int error = 0; | |
262 | 262 | |||
263 | switch (cmd) { | 263 | switch (cmd) { | |
264 | 264 | |||
265 | case SIOCINITIFADDR: | 265 | case SIOCINITIFADDR: | |
266 | ifp->if_flags |= IFF_UP | IFF_RUNNING; | |||
267 | ifa = (struct ifaddr *)data; | 266 | ifa = (struct ifaddr *)data; | |
268 | ifa->ifa_rtrequest = faithrtrequest; | 267 | ifa->ifa_rtrequest = faithrtrequest; | |
268 | ifp->if_flags |= IFF_UP | IFF_RUNNING; | |||
269 | /* | 269 | /* | |
270 | * Everything else is done at a higher level. | 270 | * Everything else is done at a higher level. | |
271 | */ | 271 | */ | |
272 | break; | 272 | break; | |
273 | 273 | |||
274 | case SIOCADDMULTI: | 274 | case SIOCADDMULTI: | |
275 | case SIOCDELMULTI: | 275 | case SIOCDELMULTI: | |
276 | if (ifr == 0) { | 276 | if (ifr == 0) { | |
277 | error = EAFNOSUPPORT; /* XXX */ | 277 | error = EAFNOSUPPORT; /* XXX */ | |
278 | break; | 278 | break; | |
279 | } | 279 | } | |
280 | switch (ifr->ifr_addr.sa_family) { | 280 | switch (ifr->ifr_addr.sa_family) { | |
281 | #ifdef INET | 281 | #ifdef INET |
--- src/sys/net/if_gif.c 2017/12/21 19:14:41 1.126.2.5
+++ src/sys/net/if_gif.c 2018/01/02 10:20:33 1.126.2.6
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_gif.c,v 1.126.2.5 2017/12/21 19:14:41 snj Exp $ */ | 1 | /* $NetBSD: if_gif.c,v 1.126.2.6 2018/01/02 10:20:33 snj Exp $ */ | |
2 | /* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */ | 2 | /* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -21,27 +21,27 @@ | @@ -21,27 +21,27 @@ | |||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | * SUCH DAMAGE. | 30 | * SUCH DAMAGE. | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | #include <sys/cdefs.h> | 33 | #include <sys/cdefs.h> | |
34 | __KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.5 2017/12/21 19:14:41 snj Exp $"); | 34 | __KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.126.2.6 2018/01/02 10:20:33 snj Exp $"); | |
35 | 35 | |||
36 | #ifdef _KERNEL_OPT | 36 | #ifdef _KERNEL_OPT | |
37 | #include "opt_inet.h" | 37 | #include "opt_inet.h" | |
38 | #include "opt_net_mpsafe.h" | 38 | #include "opt_net_mpsafe.h" | |
39 | #endif | 39 | #endif | |
40 | 40 | |||
41 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
42 | #include <sys/systm.h> | 42 | #include <sys/systm.h> | |
43 | #include <sys/kernel.h> | 43 | #include <sys/kernel.h> | |
44 | #include <sys/mbuf.h> | 44 | #include <sys/mbuf.h> | |
45 | #include <sys/socket.h> | 45 | #include <sys/socket.h> | |
46 | #include <sys/sockio.h> | 46 | #include <sys/sockio.h> | |
47 | #include <sys/errno.h> | 47 | #include <sys/errno.h> | |
@@ -265,27 +265,27 @@ gif_clone_create(struct if_clone *ifc, i | @@ -265,27 +265,27 @@ gif_clone_create(struct if_clone *ifc, i | |||
265 | 265 | |||
266 | static int | 266 | static int | |
267 | gifattach0(struct gif_softc *sc) | 267 | gifattach0(struct gif_softc *sc) | |
268 | { | 268 | { | |
269 | int rv; | 269 | int rv; | |
270 | 270 | |||
271 | sc->encap_cookie4 = sc->encap_cookie6 = NULL; | 271 | sc->encap_cookie4 = sc->encap_cookie6 = NULL; | |
272 | 272 | |||
273 | sc->gif_if.if_addrlen = 0; | 273 | sc->gif_if.if_addrlen = 0; | |
274 | sc->gif_if.if_mtu = GIF_MTU; | 274 | sc->gif_if.if_mtu = GIF_MTU; | |
275 | sc->gif_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; | 275 | sc->gif_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST; | |
276 | sc->gif_if.if_extflags = IFEF_NO_LINK_STATE_CHANGE; | 276 | sc->gif_if.if_extflags = IFEF_NO_LINK_STATE_CHANGE; | |
277 | #ifdef GIF_MPSAFE | 277 | #ifdef GIF_MPSAFE | |
278 | sc->gif_if.if_extflags |= IFEF_OUTPUT_MPSAFE; | 278 | sc->gif_if.if_extflags |= IFEF_MPSAFE; | |
279 | #endif | 279 | #endif | |
280 | sc->gif_if.if_ioctl = gif_ioctl; | 280 | sc->gif_if.if_ioctl = gif_ioctl; | |
281 | sc->gif_if.if_output = gif_output; | 281 | sc->gif_if.if_output = gif_output; | |
282 | sc->gif_if.if_start = gif_start; | 282 | sc->gif_if.if_start = gif_start; | |
283 | sc->gif_if.if_transmit = gif_transmit; | 283 | sc->gif_if.if_transmit = gif_transmit; | |
284 | sc->gif_if.if_type = IFT_GIF; | 284 | sc->gif_if.if_type = IFT_GIF; | |
285 | sc->gif_if.if_dlt = DLT_NULL; | 285 | sc->gif_if.if_dlt = DLT_NULL; | |
286 | sc->gif_if.if_softc = sc; | 286 | sc->gif_if.if_softc = sc; | |
287 | IFQ_SET_READY(&sc->gif_if.if_snd); | 287 | IFQ_SET_READY(&sc->gif_if.if_snd); | |
288 | rv = if_initialize(&sc->gif_if); | 288 | rv = if_initialize(&sc->gif_if); | |
289 | if (rv != 0) | 289 | if (rv != 0) | |
290 | return rv; | 290 | return rv; | |
291 | 291 |
--- src/sys/net/if_l2tp.c 2017/11/08 22:20:59 1.11.2.2
+++ src/sys/net/if_l2tp.c 2018/01/02 10:20:33 1.11.2.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_l2tp.c,v 1.11.2.2 2017/11/08 22:20:59 snj Exp $ */ | 1 | /* $NetBSD: if_l2tp.c,v 1.11.2.3 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2017 Internet Initiative Japan Inc. | 4 | * Copyright (c) 2017 Internet Initiative Japan Inc. | |
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. | |
@@ -21,30 +21,31 @@ | @@ -21,30 +21,31 @@ | |||
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
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 | * L2TPv3 kernel interface | 30 | * L2TPv3 kernel interface | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | #include <sys/cdefs.h> | 33 | #include <sys/cdefs.h> | |
34 | __KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.2 2017/11/08 22:20:59 snj Exp $"); | 34 | __KERNEL_RCSID(0, "$NetBSD: if_l2tp.c,v 1.11.2.3 2018/01/02 10:20:33 snj Exp $"); | |
35 | 35 | |||
36 | #ifdef _KERNEL_OPT | 36 | #ifdef _KERNEL_OPT | |
37 | #include "opt_inet.h" | 37 | #include "opt_inet.h" | |
38 | #include "opt_net_mpsafe.h" | |||
38 | #endif | 39 | #endif | |
39 | 40 | |||
40 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
41 | #include <sys/systm.h> | 42 | #include <sys/systm.h> | |
42 | #include <sys/kernel.h> | 43 | #include <sys/kernel.h> | |
43 | #include <sys/mbuf.h> | 44 | #include <sys/mbuf.h> | |
44 | #include <sys/socket.h> | 45 | #include <sys/socket.h> | |
45 | #include <sys/sockio.h> | 46 | #include <sys/sockio.h> | |
46 | #include <sys/errno.h> | 47 | #include <sys/errno.h> | |
47 | #include <sys/ioctl.h> | 48 | #include <sys/ioctl.h> | |
48 | #include <sys/time.h> | 49 | #include <sys/time.h> | |
49 | #include <sys/syslog.h> | 50 | #include <sys/syslog.h> | |
50 | #include <sys/proc.h> | 51 | #include <sys/proc.h> | |
@@ -251,28 +252,30 @@ l2tp_clone_create(struct if_clone *ifc, | @@ -251,28 +252,30 @@ l2tp_clone_create(struct if_clone *ifc, | |||
251 | LIST_INSERT_HEAD(&l2tp_softcs.list, sc, l2tp_list); | 252 | LIST_INSERT_HEAD(&l2tp_softcs.list, sc, l2tp_list); | |
252 | mutex_exit(&l2tp_softcs.lock); | 253 | mutex_exit(&l2tp_softcs.lock); | |
253 | 254 | |||
254 | return (0); | 255 | return (0); | |
255 | } | 256 | } | |
256 | 257 | |||
257 | void | 258 | void | |
258 | l2tpattach0(struct l2tp_softc *sc) | 259 | l2tpattach0(struct l2tp_softc *sc) | |
259 | { | 260 | { | |
260 | 261 | |||
261 | sc->l2tp_ec.ec_if.if_addrlen = 0; | 262 | sc->l2tp_ec.ec_if.if_addrlen = 0; | |
262 | sc->l2tp_ec.ec_if.if_mtu = L2TP_MTU; | 263 | sc->l2tp_ec.ec_if.if_mtu = L2TP_MTU; | |
263 | sc->l2tp_ec.ec_if.if_flags = IFF_POINTOPOINT|IFF_MULTICAST|IFF_SIMPLEX; | 264 | sc->l2tp_ec.ec_if.if_flags = IFF_POINTOPOINT|IFF_MULTICAST|IFF_SIMPLEX; | |
264 | sc->l2tp_ec.ec_if.if_extflags = IFEF_OUTPUT_MPSAFE | | 265 | sc->l2tp_ec.ec_if.if_extflags = IFEF_NO_LINK_STATE_CHANGE; | |
265 | IFEF_START_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; | 266 | #ifdef NET_MPSAFE | |
267 | sc->l2tp_ec.ec_if.if_extflags |= IFEF_MPSAFE; | |||
268 | #endif | |||
266 | sc->l2tp_ec.ec_if.if_ioctl = l2tp_ioctl; | 269 | sc->l2tp_ec.ec_if.if_ioctl = l2tp_ioctl; | |
267 | sc->l2tp_ec.ec_if.if_output = l2tp_output; | 270 | sc->l2tp_ec.ec_if.if_output = l2tp_output; | |
268 | sc->l2tp_ec.ec_if.if_type = IFT_L2TP; | 271 | sc->l2tp_ec.ec_if.if_type = IFT_L2TP; | |
269 | sc->l2tp_ec.ec_if.if_dlt = DLT_NULL; | 272 | sc->l2tp_ec.ec_if.if_dlt = DLT_NULL; | |
270 | sc->l2tp_ec.ec_if.if_start = l2tp_start; | 273 | sc->l2tp_ec.ec_if.if_start = l2tp_start; | |
271 | sc->l2tp_ec.ec_if.if_transmit = l2tp_transmit; | 274 | sc->l2tp_ec.ec_if.if_transmit = l2tp_transmit; | |
272 | sc->l2tp_ec.ec_if._if_input = ether_input; | 275 | sc->l2tp_ec.ec_if._if_input = ether_input; | |
273 | IFQ_SET_READY(&sc->l2tp_ec.ec_if.if_snd); | 276 | IFQ_SET_READY(&sc->l2tp_ec.ec_if.if_snd); | |
274 | if_attach(&sc->l2tp_ec.ec_if); | 277 | if_attach(&sc->l2tp_ec.ec_if); | |
275 | if_alloc_sadl(&sc->l2tp_ec.ec_if); | 278 | if_alloc_sadl(&sc->l2tp_ec.ec_if); | |
276 | bpf_attach(&sc->l2tp_ec.ec_if, DLT_EN10MB, sizeof(struct ether_header)); | 279 | bpf_attach(&sc->l2tp_ec.ec_if, DLT_EN10MB, sizeof(struct ether_header)); | |
277 | } | 280 | } | |
278 | 281 |
--- src/sys/net/if_loop.c 2017/12/10 10:10:25 1.94.6.3
+++ src/sys/net/if_loop.c 2018/01/02 10:20:33 1.94.6.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_loop.c,v 1.94.6.3 2017/12/10 10:10:25 snj Exp $ */ | 1 | /* $NetBSD: if_loop.c,v 1.94.6.4 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
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. | |
@@ -55,27 +55,27 @@ | @@ -55,27 +55,27 @@ | |||
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
58 | * SUCH DAMAGE. | 58 | * SUCH DAMAGE. | |
59 | * | 59 | * | |
60 | * @(#)if_loop.c 8.2 (Berkeley) 1/9/95 | 60 | * @(#)if_loop.c 8.2 (Berkeley) 1/9/95 | |
61 | */ | 61 | */ | |
62 | 62 | |||
63 | /* | 63 | /* | |
64 | * Loopback interface driver for protocol testing and timing. | 64 | * Loopback interface driver for protocol testing and timing. | |
65 | */ | 65 | */ | |
66 | 66 | |||
67 | #include <sys/cdefs.h> | 67 | #include <sys/cdefs.h> | |
68 | __KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.94.6.3 2017/12/10 10:10:25 snj Exp $"); | 68 | __KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.94.6.4 2018/01/02 10:20:33 snj Exp $"); | |
69 | 69 | |||
70 | #ifdef _KERNEL_OPT | 70 | #ifdef _KERNEL_OPT | |
71 | #include "opt_inet.h" | 71 | #include "opt_inet.h" | |
72 | #include "opt_atalk.h" | 72 | #include "opt_atalk.h" | |
73 | #include "opt_mbuftrace.h" | 73 | #include "opt_mbuftrace.h" | |
74 | #include "opt_mpls.h" | 74 | #include "opt_mpls.h" | |
75 | #include "opt_net_mpsafe.h" | 75 | #include "opt_net_mpsafe.h" | |
76 | #endif | 76 | #endif | |
77 | 77 | |||
78 | #include <sys/param.h> | 78 | #include <sys/param.h> | |
79 | #include <sys/systm.h> | 79 | #include <sys/systm.h> | |
80 | #include <sys/kernel.h> | 80 | #include <sys/kernel.h> | |
81 | #include <sys/mbuf.h> | 81 | #include <sys/mbuf.h> | |
@@ -172,28 +172,30 @@ loopdetach(void) | @@ -172,28 +172,30 @@ loopdetach(void) | |||
172 | } | 172 | } | |
173 | 173 | |||
174 | static int | 174 | static int | |
175 | loop_clone_create(struct if_clone *ifc, int unit) | 175 | loop_clone_create(struct if_clone *ifc, int unit) | |
176 | { | 176 | { | |
177 | struct ifnet *ifp; | 177 | struct ifnet *ifp; | |
178 | int rv; | 178 | int rv; | |
179 | 179 | |||
180 | ifp = if_alloc(IFT_LOOP); | 180 | ifp = if_alloc(IFT_LOOP); | |
181 | 181 | |||
182 | if_initname(ifp, ifc->ifc_name, unit); | 182 | if_initname(ifp, ifc->ifc_name, unit); | |
183 | 183 | |||
184 | ifp->if_mtu = LOMTU; | 184 | ifp->if_mtu = LOMTU; | |
185 | ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST | IFF_RUNNING; | 185 | ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; | |
186 | ifp->if_extflags = IFEF_OUTPUT_MPSAFE; | 186 | #ifdef NET_MPSAFE | |
187 | ifp->if_extflags = IFEF_MPSAFE; | |||
188 | #endif | |||
187 | ifp->if_ioctl = loioctl; | 189 | ifp->if_ioctl = loioctl; | |
188 | ifp->if_output = looutput; | 190 | ifp->if_output = looutput; | |
189 | #ifdef ALTQ | 191 | #ifdef ALTQ | |
190 | ifp->if_start = lostart; | 192 | ifp->if_start = lostart; | |
191 | #endif | 193 | #endif | |
192 | ifp->if_type = IFT_LOOP; | 194 | ifp->if_type = IFT_LOOP; | |
193 | ifp->if_hdrlen = 0; | 195 | ifp->if_hdrlen = 0; | |
194 | ifp->if_addrlen = 0; | 196 | ifp->if_addrlen = 0; | |
195 | ifp->if_dlt = DLT_NULL; | 197 | ifp->if_dlt = DLT_NULL; | |
196 | IFQ_SET_READY(&ifp->if_snd); | 198 | IFQ_SET_READY(&ifp->if_snd); | |
197 | if (unit == 0) | 199 | if (unit == 0) | |
198 | lo0ifp = ifp; | 200 | lo0ifp = ifp; | |
199 | rv = if_attach(ifp); | 201 | rv = if_attach(ifp); | |
@@ -201,65 +203,67 @@ loop_clone_create(struct if_clone *ifc, | @@ -201,65 +203,67 @@ loop_clone_create(struct if_clone *ifc, | |||
201 | if_free(ifp); | 203 | if_free(ifp); | |
202 | return rv; | 204 | return rv; | |
203 | } | 205 | } | |
204 | if_alloc_sadl(ifp); | 206 | if_alloc_sadl(ifp); | |
205 | bpf_attach(ifp, DLT_NULL, sizeof(u_int)); | 207 | bpf_attach(ifp, DLT_NULL, sizeof(u_int)); | |
206 | #ifdef MBUFTRACE | 208 | #ifdef MBUFTRACE | |
207 | ifp->if_mowner = malloc(sizeof(struct mowner), M_DEVBUF, | 209 | ifp->if_mowner = malloc(sizeof(struct mowner), M_DEVBUF, | |
208 | M_WAITOK | M_ZERO); | 210 | M_WAITOK | M_ZERO); | |
209 | strlcpy(ifp->if_mowner->mo_name, ifp->if_xname, | 211 | strlcpy(ifp->if_mowner->mo_name, ifp->if_xname, | |
210 | sizeof(ifp->if_mowner->mo_name)); | 212 | sizeof(ifp->if_mowner->mo_name)); | |
211 | MOWNER_ATTACH(ifp->if_mowner); | 213 | MOWNER_ATTACH(ifp->if_mowner); | |
212 | #endif | 214 | #endif | |
213 | 215 | |||
216 | ifp->if_flags |= IFF_RUNNING; | |||
217 | ||||
214 | return (0); | 218 | return (0); | |
215 | } | 219 | } | |
216 | 220 | |||
217 | static int | 221 | static int | |
218 | loop_clone_destroy(struct ifnet *ifp) | 222 | loop_clone_destroy(struct ifnet *ifp) | |
219 | { | 223 | { | |
220 | 224 | |||
221 | if (ifp == lo0ifp) | 225 | if (ifp == lo0ifp) | |
222 | return (EPERM); | 226 | return (EPERM); | |
223 | 227 | |||
228 | ifp->if_flags &= ~IFF_RUNNING; | |||
229 | ||||
224 | #ifdef MBUFTRACE | 230 | #ifdef MBUFTRACE | |
225 | MOWNER_DETACH(ifp->if_mowner); | 231 | MOWNER_DETACH(ifp->if_mowner); | |
226 | free(ifp->if_mowner, M_DEVBUF); | 232 | free(ifp->if_mowner, M_DEVBUF); | |
227 | #endif | 233 | #endif | |
228 | 234 | |||
229 | bpf_detach(ifp); | 235 | bpf_detach(ifp); | |
230 | if_detach(ifp); | 236 | if_detach(ifp); | |
231 | 237 | |||
232 | if_free(ifp); | 238 | if_free(ifp); | |
233 | 239 | |||
234 | return (0); | 240 | return (0); | |
235 | } | 241 | } | |
236 | 242 | |||
237 | int | 243 | int | |
238 | looutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, | 244 | looutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, | |
239 | const struct rtentry *rt) | 245 | const struct rtentry *rt) | |
240 | { | 246 | { | |
241 | pktqueue_t *pktq = NULL; | 247 | pktqueue_t *pktq = NULL; | |
242 | struct ifqueue *ifq = NULL; | 248 | struct ifqueue *ifq = NULL; | |
243 | int s, isr = -1; | 249 | int s, isr = -1; | |
244 | int csum_flags; | 250 | int csum_flags; | |
245 | int error = 0; | 251 | int error = 0; | |
246 | size_t pktlen; | 252 | size_t pktlen; | |
247 | 253 | |||
248 | MCLAIM(m, ifp->if_mowner); | 254 | MCLAIM(m, ifp->if_mowner); | |
249 | 255 | |||
250 | #ifndef NET_MPSAFE | 256 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
251 | KERNEL_LOCK(1, NULL); | |||
252 | #endif | |||
253 | 257 | |||
254 | if ((m->m_flags & M_PKTHDR) == 0) | 258 | if ((m->m_flags & M_PKTHDR) == 0) | |
255 | panic("looutput: no header mbuf"); | 259 | panic("looutput: no header mbuf"); | |
256 | if (ifp->if_flags & IFF_LOOPBACK) | 260 | if (ifp->if_flags & IFF_LOOPBACK) | |
257 | bpf_mtap_af(ifp, dst->sa_family, m); | 261 | bpf_mtap_af(ifp, dst->sa_family, m); | |
258 | m_set_rcvif(m, ifp); | 262 | m_set_rcvif(m, ifp); | |
259 | 263 | |||
260 | if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) { | 264 | if (rt && rt->rt_flags & (RTF_REJECT|RTF_BLACKHOLE)) { | |
261 | m_freem(m); | 265 | m_freem(m); | |
262 | error = (rt->rt_flags & RTF_BLACKHOLE ? 0 : | 266 | error = (rt->rt_flags & RTF_BLACKHOLE ? 0 : | |
263 | rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH); | 267 | rt->rt_flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH); | |
264 | goto out; | 268 | goto out; | |
265 | } | 269 | } | |
@@ -365,29 +369,27 @@ looutput(struct ifnet *ifp, struct mbuf | @@ -365,29 +369,27 @@ looutput(struct ifnet *ifp, struct mbuf | |||
365 | if (IF_QFULL(ifq)) { | 369 | if (IF_QFULL(ifq)) { | |
366 | IF_DROP(ifq); | 370 | IF_DROP(ifq); | |
367 | m_freem(m); | 371 | m_freem(m); | |
368 | splx(s); | 372 | splx(s); | |
369 | error = ENOBUFS; | 373 | error = ENOBUFS; | |
370 | goto out; | 374 | goto out; | |
371 | } | 375 | } | |
372 | ifp->if_ipackets++; | 376 | ifp->if_ipackets++; | |
373 | ifp->if_ibytes += m->m_pkthdr.len; | 377 | ifp->if_ibytes += m->m_pkthdr.len; | |
374 | IF_ENQUEUE(ifq, m); | 378 | IF_ENQUEUE(ifq, m); | |
375 | schednetisr(isr); | 379 | schednetisr(isr); | |
376 | splx(s); | 380 | splx(s); | |
377 | out: | 381 | out: | |
378 | #ifndef NET_MPSAFE | 382 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
379 | KERNEL_UNLOCK_ONE(NULL); | |||
380 | #endif | |||
381 | return error; | 383 | return error; | |
382 | } | 384 | } | |
383 | 385 | |||
384 | #ifdef ALTQ | 386 | #ifdef ALTQ | |
385 | static void | 387 | static void | |
386 | lostart(struct ifnet *ifp) | 388 | lostart(struct ifnet *ifp) | |
387 | { | 389 | { | |
388 | for (;;) { | 390 | for (;;) { | |
389 | pktqueue_t *pktq = NULL; | 391 | pktqueue_t *pktq = NULL; | |
390 | struct ifqueue *ifq = NULL; | 392 | struct ifqueue *ifq = NULL; | |
391 | struct mbuf *m; | 393 | struct mbuf *m; | |
392 | size_t pktlen; | 394 | size_t pktlen; | |
393 | uint32_t af; | 395 | uint32_t af; |
--- src/sys/net/if_media.c 2017/11/22 14:36:55 1.32.6.1
+++ src/sys/net/if_media.c 2018/01/02 10:20:33 1.32.6.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_media.c,v 1.32.6.1 2017/11/22 14:36:55 martin Exp $ */ | 1 | /* $NetBSD: if_media.c,v 1.32.6.2 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998 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 Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | |
9 | * NASA Ames Research Center. | 9 | * NASA Ames Research Center. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -66,27 +66,27 @@ | @@ -66,27 +66,27 @@ | |||
66 | 66 | |||
67 | /* | 67 | /* | |
68 | * BSD/OS-compatible network interface media selection. | 68 | * BSD/OS-compatible network interface media selection. | |
69 | * | 69 | * | |
70 | * Where it is safe to do so, this code strays slightly from the BSD/OS | 70 | * Where it is safe to do so, this code strays slightly from the BSD/OS | |
71 | * design. Software which uses the API (device drivers, basically) | 71 | * design. Software which uses the API (device drivers, basically) | |
72 | * shouldn't notice any difference. | 72 | * shouldn't notice any difference. | |
73 | * | 73 | * | |
74 | * Many thanks to Matt Thomas for providing the information necessary | 74 | * Many thanks to Matt Thomas for providing the information necessary | |
75 | * to implement this interface. | 75 | * to implement this interface. | |
76 | */ | 76 | */ | |
77 | 77 | |||
78 | #include <sys/cdefs.h> | 78 | #include <sys/cdefs.h> | |
79 | __KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.32.6.1 2017/11/22 14:36:55 martin Exp $"); | 79 | __KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.32.6.2 2018/01/02 10:20:33 snj Exp $"); | |
80 | 80 | |||
81 | #include <sys/param.h> | 81 | #include <sys/param.h> | |
82 | #include <sys/systm.h> | 82 | #include <sys/systm.h> | |
83 | #include <sys/errno.h> | 83 | #include <sys/errno.h> | |
84 | #include <sys/ioctl.h> | 84 | #include <sys/ioctl.h> | |
85 | #include <sys/socket.h> | 85 | #include <sys/socket.h> | |
86 | #include <sys/malloc.h> | 86 | #include <sys/malloc.h> | |
87 | 87 | |||
88 | #include <net/if.h> | 88 | #include <net/if.h> | |
89 | #include <net/if_media.h> | 89 | #include <net/if_media.h> | |
90 | #include <net/netisr.h> | 90 | #include <net/netisr.h> | |
91 | 91 | |||
92 | /* | 92 | /* | |
@@ -215,28 +215,28 @@ ifmedia_set(struct ifmedia *ifm, int tar | @@ -215,28 +215,28 @@ ifmedia_set(struct ifmedia *ifm, int tar | |||
215 | #ifdef IFMEDIA_DEBUG | 215 | #ifdef IFMEDIA_DEBUG | |
216 | if (ifmedia_debug) { | 216 | if (ifmedia_debug) { | |
217 | printf("ifmedia_set: target "); | 217 | printf("ifmedia_set: target "); | |
218 | ifmedia_printword(target); | 218 | ifmedia_printword(target); | |
219 | printf("ifmedia_set: setting to "); | 219 | printf("ifmedia_set: setting to "); | |
220 | ifmedia_printword(ifm->ifm_cur->ifm_media); | 220 | ifmedia_printword(ifm->ifm_cur->ifm_media); | |
221 | } | 221 | } | |
222 | #endif | 222 | #endif | |
223 | } | 223 | } | |
224 | 224 | |||
225 | /* | 225 | /* | |
226 | * Device-independent media ioctl support function. | 226 | * Device-independent media ioctl support function. | |
227 | */ | 227 | */ | |
228 | int | 228 | static int | |
229 | ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr, struct ifmedia *ifm, | 229 | _ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr, struct ifmedia *ifm, | |
230 | u_long cmd) | 230 | u_long cmd) | |
231 | { | 231 | { | |
232 | struct ifmedia_entry *match; | 232 | struct ifmedia_entry *match; | |
233 | struct ifmediareq *ifmr = (struct ifmediareq *) ifr; | 233 | struct ifmediareq *ifmr = (struct ifmediareq *) ifr; | |
234 | int error = 0; | 234 | int error = 0; | |
235 | #ifdef OSIOCSIFMEDIA | 235 | #ifdef OSIOCSIFMEDIA | |
236 | struct oifreq *oifr = (struct oifreq *)ifr; | 236 | struct oifreq *oifr = (struct oifreq *)ifr; | |
237 | #endif | 237 | #endif | |
238 | 238 | |||
239 | if (ifp == NULL || ifr == NULL || ifm == NULL) | 239 | if (ifp == NULL || ifr == NULL || ifm == NULL) | |
240 | return (EINVAL); | 240 | return (EINVAL); | |
241 | 241 | |||
242 | switch (cmd) { | 242 | switch (cmd) { | |
@@ -350,26 +350,42 @@ ifmedia_ioctl(struct ifnet *ifp, struct | @@ -350,26 +350,42 @@ ifmedia_ioctl(struct ifnet *ifp, struct | |||
350 | free(kptr, M_TEMP); | 350 | free(kptr, M_TEMP); | |
351 | } | 351 | } | |
352 | ifmr->ifm_count = nwords; | 352 | ifmr->ifm_count = nwords; | |
353 | break; | 353 | break; | |
354 | } | 354 | } | |
355 | 355 | |||
356 | default: | 356 | default: | |
357 | return EINVAL; | 357 | return EINVAL; | |
358 | } | 358 | } | |
359 | 359 | |||
360 | return error; | 360 | return error; | |
361 | } | 361 | } | |
362 | 362 | |||
363 | int | |||
364 | ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr, struct ifmedia *ifm, | |||
365 | u_long cmd) | |||
366 | { | |||
367 | int e; | |||
368 | ||||
369 | /* | |||
370 | * If if_is_mpsafe(ifp), KERNEL_LOCK isn't held here, but _ifmedia_ioctl | |||
371 | * isn't MP-safe yet, so we must hold the lock. | |||
372 | */ | |||
373 | KERNEL_LOCK_IF_IFP_MPSAFE(ifp); | |||
374 | e = _ifmedia_ioctl(ifp, ifr, ifm, cmd); | |||
375 | KERNEL_UNLOCK_IF_IFP_MPSAFE(ifp); | |||
376 | return e; | |||
377 | } | |||
378 | ||||
363 | /* | 379 | /* | |
364 | * Find media entry matching a given ifm word. | 380 | * Find media entry matching a given ifm word. | |
365 | */ | 381 | */ | |
366 | struct ifmedia_entry * | 382 | struct ifmedia_entry * | |
367 | ifmedia_match(struct ifmedia *ifm, u_int target, u_int mask) | 383 | ifmedia_match(struct ifmedia *ifm, u_int target, u_int mask) | |
368 | { | 384 | { | |
369 | struct ifmedia_entry *match, *next; | 385 | struct ifmedia_entry *match, *next; | |
370 | 386 | |||
371 | match = NULL; | 387 | match = NULL; | |
372 | mask = ~mask; | 388 | mask = ~mask; | |
373 | 389 | |||
374 | for (next = TAILQ_FIRST(&ifm->ifm_list); next != NULL; | 390 | for (next = TAILQ_FIRST(&ifm->ifm_list); next != NULL; | |
375 | next = TAILQ_NEXT(next, ifm_list)) { | 391 | next = TAILQ_NEXT(next, ifm_list)) { |
--- src/sys/net/if_pppoe.c 2017/12/10 10:10:25 1.125.6.4
+++ src/sys/net/if_pppoe.c 2018/01/02 10:20:33 1.125.6.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_pppoe.c,v 1.125.6.4 2017/12/10 10:10:25 snj Exp $ */ | 1 | /* $NetBSD: if_pppoe.c,v 1.125.6.5 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2002, 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 Martin Husemann <martin@NetBSD.org>. | 8 | * by Martin Husemann <martin@NetBSD.org>. | |
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. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.4 2017/12/10 10:10:25 snj Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.125.6.5 2018/01/02 10:20:33 snj Exp $"); | |
34 | 34 | |||
35 | #ifdef _KERNEL_OPT | 35 | #ifdef _KERNEL_OPT | |
36 | #include "pppoe.h" | 36 | #include "pppoe.h" | |
37 | #include "opt_pppoe.h" | 37 | #include "opt_pppoe.h" | |
38 | #include "opt_net_mpsafe.h" | 38 | #include "opt_net_mpsafe.h" | |
39 | #endif | 39 | #endif | |
40 | 40 | |||
41 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
42 | #include <sys/systm.h> | 42 | #include <sys/systm.h> | |
43 | #include <sys/kernel.h> | 43 | #include <sys/kernel.h> | |
44 | #include <sys/callout.h> | 44 | #include <sys/callout.h> | |
45 | #include <sys/malloc.h> | 45 | #include <sys/malloc.h> | |
46 | #include <sys/mbuf.h> | 46 | #include <sys/mbuf.h> | |
@@ -291,27 +291,27 @@ pppoedetach(void) | @@ -291,27 +291,27 @@ pppoedetach(void) | |||
291 | static int | 291 | static int | |
292 | pppoe_clone_create(struct if_clone *ifc, int unit) | 292 | pppoe_clone_create(struct if_clone *ifc, int unit) | |
293 | { | 293 | { | |
294 | struct pppoe_softc *sc; | 294 | struct pppoe_softc *sc; | |
295 | int rv; | 295 | int rv; | |
296 | 296 | |||
297 | sc = malloc(sizeof(struct pppoe_softc), M_DEVBUF, M_WAITOK|M_ZERO); | 297 | sc = malloc(sizeof(struct pppoe_softc), M_DEVBUF, M_WAITOK|M_ZERO); | |
298 | 298 | |||
299 | if_initname(&sc->sc_sppp.pp_if, "pppoe", unit); | 299 | if_initname(&sc->sc_sppp.pp_if, "pppoe", unit); | |
300 | sc->sc_sppp.pp_if.if_softc = sc; | 300 | sc->sc_sppp.pp_if.if_softc = sc; | |
301 | sc->sc_sppp.pp_if.if_mtu = PPPOE_MAXMTU; | 301 | sc->sc_sppp.pp_if.if_mtu = PPPOE_MAXMTU; | |
302 | sc->sc_sppp.pp_if.if_flags = IFF_SIMPLEX|IFF_POINTOPOINT|IFF_MULTICAST; | 302 | sc->sc_sppp.pp_if.if_flags = IFF_SIMPLEX|IFF_POINTOPOINT|IFF_MULTICAST; | |
303 | #ifdef PPPOE_MPSAFE | 303 | #ifdef PPPOE_MPSAFE | |
304 | sc->sc_sppp.pp_if.if_extflags = IFEF_OUTPUT_MPSAFE; | 304 | sc->sc_sppp.pp_if.if_extflags = IFEF_MPSAFE; | |
305 | #endif | 305 | #endif | |
306 | sc->sc_sppp.pp_if.if_type = IFT_PPP; | 306 | sc->sc_sppp.pp_if.if_type = IFT_PPP; | |
307 | sc->sc_sppp.pp_if.if_hdrlen = sizeof(struct ether_header) + PPPOE_HEADERLEN; | 307 | sc->sc_sppp.pp_if.if_hdrlen = sizeof(struct ether_header) + PPPOE_HEADERLEN; | |
308 | sc->sc_sppp.pp_if.if_dlt = DLT_PPP_ETHER; | 308 | sc->sc_sppp.pp_if.if_dlt = DLT_PPP_ETHER; | |
309 | sc->sc_sppp.pp_flags |= PP_KEEPALIVE | /* use LCP keepalive */ | 309 | sc->sc_sppp.pp_flags |= PP_KEEPALIVE | /* use LCP keepalive */ | |
310 | PP_NOFRAMING; /* no serial encapsulation */ | 310 | PP_NOFRAMING; /* no serial encapsulation */ | |
311 | sc->sc_sppp.pp_if.if_ioctl = pppoe_ioctl; | 311 | sc->sc_sppp.pp_if.if_ioctl = pppoe_ioctl; | |
312 | IFQ_SET_MAXLEN(&sc->sc_sppp.pp_if.if_snd, IFQ_MAXLEN); | 312 | IFQ_SET_MAXLEN(&sc->sc_sppp.pp_if.if_snd, IFQ_MAXLEN); | |
313 | IFQ_SET_READY(&sc->sc_sppp.pp_if.if_snd); | 313 | IFQ_SET_READY(&sc->sc_sppp.pp_if.if_snd); | |
314 | 314 | |||
315 | /* changed to real address later */ | 315 | /* changed to real address later */ | |
316 | memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest)); | 316 | memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest)); | |
317 | 317 | |||
@@ -465,54 +465,51 @@ static void | @@ -465,54 +465,51 @@ static void | |||
465 | pppoe_softintr_handler(void *dummy) | 465 | pppoe_softintr_handler(void *dummy) | |
466 | { | 466 | { | |
467 | /* called at splsoftnet() */ | 467 | /* called at splsoftnet() */ | |
468 | pppoeintr(); | 468 | pppoeintr(); | |
469 | } | 469 | } | |
470 | 470 | |||
471 | /* called at appropriate protection level */ | 471 | /* called at appropriate protection level */ | |
472 | static void | 472 | static void | |
473 | pppoeintr(void) | 473 | pppoeintr(void) | |
474 | { | 474 | { | |
475 | struct mbuf *m; | 475 | struct mbuf *m; | |
476 | int disc_done, data_done; | 476 | int disc_done, data_done; | |
477 | 477 | |||
478 | #ifndef PPPOE_MPSAFE | 478 | SOFTNET_LOCK_UNLESS_NET_MPSAFE(); | |
479 | mutex_enter(softnet_lock); | |||
480 | #endif | |||
481 | 479 | |||
482 | do { | 480 | do { | |
483 | disc_done = 0; | 481 | disc_done = 0; | |
484 | data_done = 0; | 482 | data_done = 0; | |
485 | for (;;) { | 483 | for (;;) { | |
486 | IFQ_LOCK(&ppoediscinq); | 484 | IFQ_LOCK(&ppoediscinq); | |
487 | IF_DEQUEUE(&ppoediscinq, m); | 485 | IF_DEQUEUE(&ppoediscinq, m); | |
488 | IFQ_UNLOCK(&ppoediscinq); | 486 | IFQ_UNLOCK(&ppoediscinq); | |
489 | if (m == NULL) break; | 487 | if (m == NULL) break; | |
490 | disc_done = 1; | 488 | disc_done = 1; | |
491 | pppoe_disc_input(m); | 489 | pppoe_disc_input(m); | |
492 | } | 490 | } | |
493 | 491 | |||
494 | for (;;) { | 492 | for (;;) { | |
495 | IFQ_LOCK(&ppoeinq); | 493 | IFQ_LOCK(&ppoeinq); | |
496 | IF_DEQUEUE(&ppoeinq, m); | 494 | IF_DEQUEUE(&ppoeinq, m); | |
497 | IFQ_UNLOCK(&ppoeinq); | 495 | IFQ_UNLOCK(&ppoeinq); | |
498 | if (m == NULL) break; | 496 | if (m == NULL) break; | |
499 | data_done = 1; | 497 | data_done = 1; | |
500 | pppoe_data_input(m); | 498 | pppoe_data_input(m); | |
501 | } | 499 | } | |
502 | } while (disc_done || data_done); | 500 | } while (disc_done || data_done); | |
503 | #ifndef PPPOE_MPSAFE | 501 | ||
504 | mutex_exit(softnet_lock); | 502 | SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); | |
505 | #endif | |||
506 | } | 503 | } | |
507 | 504 | |||
508 | /* analyze and handle a single received packet while not in session state */ | 505 | /* analyze and handle a single received packet while not in session state */ | |
509 | static void | 506 | static void | |
510 | pppoe_dispatch_disc_pkt(struct mbuf *m, int off) | 507 | pppoe_dispatch_disc_pkt(struct mbuf *m, int off) | |
511 | { | 508 | { | |
512 | uint16_t tag, len; | 509 | uint16_t tag, len; | |
513 | uint16_t session, plen; | 510 | uint16_t session, plen; | |
514 | struct pppoe_softc *sc; | 511 | struct pppoe_softc *sc; | |
515 | const char *err_msg; | 512 | const char *err_msg; | |
516 | char devname[IF_NAMESIZE]; | 513 | char devname[IF_NAMESIZE]; | |
517 | char *error; | 514 | char *error; | |
518 | uint8_t *ac_cookie; | 515 | uint8_t *ac_cookie; |
--- src/sys/net/if_spppsubr.c 2017/11/30 15:57:37 1.169.6.2
+++ src/sys/net/if_spppsubr.c 2018/01/02 10:20:33 1.169.6.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_spppsubr.c,v 1.169.6.2 2017/11/30 15:57:37 martin Exp $ */ | 1 | /* $NetBSD: if_spppsubr.c,v 1.169.6.3 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Synchronous PPP/Cisco link level subroutines. | 4 | * Synchronous PPP/Cisco link level subroutines. | |
5 | * Keepalive protocol implemented in both Cisco and PPP modes. | 5 | * Keepalive protocol implemented in both Cisco and PPP modes. | |
6 | * | 6 | * | |
7 | * Copyright (C) 1994-1996 Cronyx Engineering Ltd. | 7 | * Copyright (C) 1994-1996 Cronyx Engineering Ltd. | |
8 | * Author: Serge Vakulenko, <vak@cronyx.ru> | 8 | * Author: Serge Vakulenko, <vak@cronyx.ru> | |
9 | * | 9 | * | |
10 | * Heavily revamped to conform to RFC 1661. | 10 | * Heavily revamped to conform to RFC 1661. | |
11 | * Copyright (C) 1997, Joerg Wunsch. | 11 | * Copyright (C) 1997, Joerg Wunsch. | |
12 | * | 12 | * | |
13 | * RFC2472 IPv6CP support. | 13 | * RFC2472 IPv6CP support. | |
14 | * Copyright (C) 2000, Jun-ichiro itojun Hagino <itojun@iijlab.net>. | 14 | * Copyright (C) 2000, Jun-ichiro itojun Hagino <itojun@iijlab.net>. | |
@@ -31,27 +31,27 @@ | @@ -31,27 +31,27 @@ | |||
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
34 | * POSSIBILITY OF SUCH DAMAGE. | 34 | * POSSIBILITY OF SUCH DAMAGE. | |
35 | * | 35 | * | |
36 | * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997 | 36 | * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997 | |
37 | * | 37 | * | |
38 | * From: if_spppsubr.c,v 1.39 1998/04/04 13:26:03 phk Exp | 38 | * From: if_spppsubr.c,v 1.39 1998/04/04 13:26:03 phk Exp | |
39 | * | 39 | * | |
40 | * From: Id: if_spppsubr.c,v 1.23 1999/02/23 14:47:50 hm Exp | 40 | * From: Id: if_spppsubr.c,v 1.23 1999/02/23 14:47:50 hm Exp | |
41 | */ | 41 | */ | |
42 | 42 | |||
43 | #include <sys/cdefs.h> | 43 | #include <sys/cdefs.h> | |
44 | __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.169.6.2 2017/11/30 15:57:37 martin Exp $"); | 44 | __KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.169.6.3 2018/01/02 10:20:33 snj Exp $"); | |
45 | 45 | |||
46 | #if defined(_KERNEL_OPT) | 46 | #if defined(_KERNEL_OPT) | |
47 | #include "opt_inet.h" | 47 | #include "opt_inet.h" | |
48 | #include "opt_modular.h" | 48 | #include "opt_modular.h" | |
49 | #include "opt_compat_netbsd.h" | 49 | #include "opt_compat_netbsd.h" | |
50 | #include "opt_net_mpsafe.h" | 50 | #include "opt_net_mpsafe.h" | |
51 | #endif | 51 | #endif | |
52 | 52 | |||
53 | 53 | |||
54 | #include <sys/param.h> | 54 | #include <sys/param.h> | |
55 | #include <sys/proc.h> | 55 | #include <sys/proc.h> | |
56 | #include <sys/systm.h> | 56 | #include <sys/systm.h> | |
57 | #include <sys/kernel.h> | 57 | #include <sys/kernel.h> | |
@@ -5261,26 +5261,28 @@ sppp_get_ip_addrs(struct sppp *sp, uint3 | @@ -5261,26 +5261,28 @@ sppp_get_ip_addrs(struct sppp *sp, uint3 | |||
5261 | /* | 5261 | /* | |
5262 | * Set IP addresses. Must be called at splnet. | 5262 | * Set IP addresses. Must be called at splnet. | |
5263 | * If an address is 0, leave it the way it is. | 5263 | * If an address is 0, leave it the way it is. | |
5264 | */ | 5264 | */ | |
5265 | static void | 5265 | static void | |
5266 | sppp_set_ip_addrs_work(struct work *wk, struct sppp *sp) | 5266 | sppp_set_ip_addrs_work(struct work *wk, struct sppp *sp) | |
5267 | { | 5267 | { | |
5268 | STDDCL; | 5268 | STDDCL; | |
5269 | struct ifaddr *ifa; | 5269 | struct ifaddr *ifa; | |
5270 | struct sockaddr_in *si, *dest; | 5270 | struct sockaddr_in *si, *dest; | |
5271 | uint32_t myaddr = 0, hisaddr = 0; | 5271 | uint32_t myaddr = 0, hisaddr = 0; | |
5272 | int s; | 5272 | int s; | |
5273 | 5273 | |||
5274 | IFNET_LOCK(ifp); | |||
5275 | ||||
5274 | /* | 5276 | /* | |
5275 | * Pick the first AF_INET address from the list, | 5277 | * Pick the first AF_INET address from the list, | |
5276 | * aliases don't make any sense on a p2p link anyway. | 5278 | * aliases don't make any sense on a p2p link anyway. | |
5277 | */ | 5279 | */ | |
5278 | si = dest = NULL; | 5280 | si = dest = NULL; | |
5279 | s = pserialize_read_enter(); | 5281 | s = pserialize_read_enter(); | |
5280 | IFADDR_READER_FOREACH(ifa, ifp) { | 5282 | IFADDR_READER_FOREACH(ifa, ifp) { | |
5281 | if (ifa->ifa_addr->sa_family == AF_INET) { | 5283 | if (ifa->ifa_addr->sa_family == AF_INET) { | |
5282 | si = (struct sockaddr_in *)ifa->ifa_addr; | 5284 | si = (struct sockaddr_in *)ifa->ifa_addr; | |
5283 | dest = (struct sockaddr_in *)ifa->ifa_dstaddr; | 5285 | dest = (struct sockaddr_in *)ifa->ifa_dstaddr; | |
5284 | break; | 5286 | break; | |
5285 | } | 5287 | } | |
5286 | } | 5288 | } | |
@@ -5324,26 +5326,28 @@ sppp_set_ip_addrs_work(struct work *wk, | @@ -5324,26 +5326,28 @@ sppp_set_ip_addrs_work(struct work *wk, | |||
5324 | pfil_run_addrhooks(if_pfil, SIOCAIFADDR, ifa); | 5326 | pfil_run_addrhooks(if_pfil, SIOCAIFADDR, ifa); | |
5325 | } | 5327 | } | |
5326 | } | 5328 | } | |
5327 | 5329 | |||
5328 | if (ifp->if_mtu > sp->lcp.their_mru) { | 5330 | if (ifp->if_mtu > sp->lcp.their_mru) { | |
5329 | sp->pp_saved_mtu = ifp->if_mtu; | 5331 | sp->pp_saved_mtu = ifp->if_mtu; | |
5330 | ifp->if_mtu = sp->lcp.their_mru; | 5332 | ifp->if_mtu = sp->lcp.their_mru; | |
5331 | if (debug) | 5333 | if (debug) | |
5332 | log(LOG_DEBUG, | 5334 | log(LOG_DEBUG, | |
5333 | "%s: setting MTU to %" PRIu64 " bytes\n", | 5335 | "%s: setting MTU to %" PRIu64 " bytes\n", | |
5334 | ifp->if_xname, ifp->if_mtu); | 5336 | ifp->if_xname, ifp->if_mtu); | |
5335 | } | 5337 | } | |
5336 | 5338 | |||
5339 | IFNET_UNLOCK(ifp); | |||
5340 | ||||
5337 | sppp_notify_con(sp); | 5341 | sppp_notify_con(sp); | |
5338 | } | 5342 | } | |
5339 | 5343 | |||
5340 | static void | 5344 | static void | |
5341 | sppp_set_ip_addrs(struct sppp *sp) | 5345 | sppp_set_ip_addrs(struct sppp *sp) | |
5342 | { | 5346 | { | |
5343 | struct ifnet *ifp = &sp->pp_if; | 5347 | struct ifnet *ifp = &sp->pp_if; | |
5344 | 5348 | |||
5345 | if (!pcq_put(sp->ipcp.update_addrs_q, (void *)IPCP_SET_ADDRS)) { | 5349 | if (!pcq_put(sp->ipcp.update_addrs_q, (void *)IPCP_SET_ADDRS)) { | |
5346 | log(LOG_WARNING, "%s: cannot enqueued, ignore sppp_clear_ip_addrs\n", | 5350 | log(LOG_WARNING, "%s: cannot enqueued, ignore sppp_clear_ip_addrs\n", | |
5347 | ifp->if_xname); | 5351 | ifp->if_xname); | |
5348 | return; | 5352 | return; | |
5349 | } | 5353 | } | |
@@ -5355,26 +5359,28 @@ sppp_set_ip_addrs(struct sppp *sp) | @@ -5355,26 +5359,28 @@ sppp_set_ip_addrs(struct sppp *sp) | |||
5355 | } | 5359 | } | |
5356 | 5360 | |||
5357 | /* | 5361 | /* | |
5358 | * Clear IP addresses. Must be called at splnet. | 5362 | * Clear IP addresses. Must be called at splnet. | |
5359 | */ | 5363 | */ | |
5360 | static void | 5364 | static void | |
5361 | sppp_clear_ip_addrs_work(struct work *wk, struct sppp *sp) | 5365 | sppp_clear_ip_addrs_work(struct work *wk, struct sppp *sp) | |
5362 | { | 5366 | { | |
5363 | STDDCL; | 5367 | STDDCL; | |
5364 | struct ifaddr *ifa; | 5368 | struct ifaddr *ifa; | |
5365 | struct sockaddr_in *si, *dest; | 5369 | struct sockaddr_in *si, *dest; | |
5366 | int s; | 5370 | int s; | |
5367 | 5371 | |||
5372 | IFNET_LOCK(ifp); | |||
5373 | ||||
5368 | /* | 5374 | /* | |
5369 | * Pick the first AF_INET address from the list, | 5375 | * Pick the first AF_INET address from the list, | |
5370 | * aliases don't make any sense on a p2p link anyway. | 5376 | * aliases don't make any sense on a p2p link anyway. | |
5371 | */ | 5377 | */ | |
5372 | si = dest = NULL; | 5378 | si = dest = NULL; | |
5373 | s = pserialize_read_enter(); | 5379 | s = pserialize_read_enter(); | |
5374 | IFADDR_READER_FOREACH(ifa, ifp) { | 5380 | IFADDR_READER_FOREACH(ifa, ifp) { | |
5375 | if (ifa->ifa_addr->sa_family == AF_INET) { | 5381 | if (ifa->ifa_addr->sa_family == AF_INET) { | |
5376 | si = (struct sockaddr_in *)ifa->ifa_addr; | 5382 | si = (struct sockaddr_in *)ifa->ifa_addr; | |
5377 | dest = (struct sockaddr_in *)ifa->ifa_dstaddr; | 5383 | dest = (struct sockaddr_in *)ifa->ifa_dstaddr; | |
5378 | break; | 5384 | break; | |
5379 | } | 5385 | } | |
5380 | } | 5386 | } | |
@@ -5404,26 +5410,28 @@ sppp_clear_ip_addrs_work(struct work *wk | @@ -5404,26 +5410,28 @@ sppp_clear_ip_addrs_work(struct work *wk | |||
5404 | if (!error) { | 5410 | if (!error) { | |
5405 | pfil_run_addrhooks(if_pfil, SIOCAIFADDR, ifa); | 5411 | pfil_run_addrhooks(if_pfil, SIOCAIFADDR, ifa); | |
5406 | } | 5412 | } | |
5407 | } | 5413 | } | |
5408 | 5414 | |||
5409 | if (sp->pp_saved_mtu > 0) { | 5415 | if (sp->pp_saved_mtu > 0) { | |
5410 | ifp->if_mtu = sp->pp_saved_mtu; | 5416 | ifp->if_mtu = sp->pp_saved_mtu; | |
5411 | sp->pp_saved_mtu = 0; | 5417 | sp->pp_saved_mtu = 0; | |
5412 | if (debug) | 5418 | if (debug) | |
5413 | log(LOG_DEBUG, | 5419 | log(LOG_DEBUG, | |
5414 | "%s: resetting MTU to %" PRIu64 " bytes\n", | 5420 | "%s: resetting MTU to %" PRIu64 " bytes\n", | |
5415 | ifp->if_xname, ifp->if_mtu); | 5421 | ifp->if_xname, ifp->if_mtu); | |
5416 | } | 5422 | } | |
5423 | ||||
5424 | IFNET_UNLOCK(ifp); | |||
5417 | } | 5425 | } | |
5418 | 5426 | |||
5419 | static void | 5427 | static void | |
5420 | sppp_clear_ip_addrs(struct sppp *sp) | 5428 | sppp_clear_ip_addrs(struct sppp *sp) | |
5421 | { | 5429 | { | |
5422 | struct ifnet *ifp = &sp->pp_if; | 5430 | struct ifnet *ifp = &sp->pp_if; | |
5423 | 5431 | |||
5424 | if (!pcq_put(sp->ipcp.update_addrs_q, (void *)IPCP_CLEAR_ADDRS)) { | 5432 | if (!pcq_put(sp->ipcp.update_addrs_q, (void *)IPCP_CLEAR_ADDRS)) { | |
5425 | log(LOG_WARNING, "%s: cannot enqueued, ignore sppp_clear_ip_addrs\n", | 5433 | log(LOG_WARNING, "%s: cannot enqueued, ignore sppp_clear_ip_addrs\n", | |
5426 | ifp->if_xname); | 5434 | ifp->if_xname); | |
5427 | return; | 5435 | return; | |
5428 | } | 5436 | } | |
5429 | 5437 | |||
@@ -5521,26 +5529,28 @@ sppp_gen_ip6_addr(struct sppp *sp, struc | @@ -5521,26 +5529,28 @@ sppp_gen_ip6_addr(struct sppp *sp, struc | |||
5521 | 5529 | |||
5522 | /* | 5530 | /* | |
5523 | * Set my IPv6 address. Must be called at splnet. | 5531 | * Set my IPv6 address. Must be called at splnet. | |
5524 | */ | 5532 | */ | |
5525 | static void | 5533 | static void | |
5526 | sppp_set_ip6_addr(struct sppp *sp, const struct in6_addr *src) | 5534 | sppp_set_ip6_addr(struct sppp *sp, const struct in6_addr *src) | |
5527 | { | 5535 | { | |
5528 | STDDCL; | 5536 | STDDCL; | |
5529 | struct ifaddr *ifa; | 5537 | struct ifaddr *ifa; | |
5530 | struct sockaddr_in6 *sin6; | 5538 | struct sockaddr_in6 *sin6; | |
5531 | int s; | 5539 | int s; | |
5532 | struct psref psref; | 5540 | struct psref psref; | |
5533 | 5541 | |||
5542 | IFNET_LOCK(ifp); | |||
5543 | ||||
5534 | /* | 5544 | /* | |
5535 | * Pick the first link-local AF_INET6 address from the list, | 5545 | * Pick the first link-local AF_INET6 address from the list, | |
5536 | * aliases don't make any sense on a p2p link anyway. | 5546 | * aliases don't make any sense on a p2p link anyway. | |
5537 | */ | 5547 | */ | |
5538 | 5548 | |||
5539 | sin6 = NULL; | 5549 | sin6 = NULL; | |
5540 | s = pserialize_read_enter(); | 5550 | s = pserialize_read_enter(); | |
5541 | IFADDR_READER_FOREACH(ifa, ifp) | 5551 | IFADDR_READER_FOREACH(ifa, ifp) | |
5542 | { | 5552 | { | |
5543 | if (ifa->ifa_addr->sa_family == AF_INET6) | 5553 | if (ifa->ifa_addr->sa_family == AF_INET6) | |
5544 | { | 5554 | { | |
5545 | sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; | 5555 | sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; | |
5546 | if (sin6 && IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { | 5556 | if (sin6 && IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { | |
@@ -5558,26 +5568,28 @@ sppp_set_ip6_addr(struct sppp *sp, const | @@ -5558,26 +5568,28 @@ sppp_set_ip6_addr(struct sppp *sp, const | |||
5558 | 5568 | |||
5559 | memcpy(&new_sin6.sin6_addr, src, sizeof(new_sin6.sin6_addr)); | 5569 | memcpy(&new_sin6.sin6_addr, src, sizeof(new_sin6.sin6_addr)); | |
5560 | error = in6_ifinit(ifp, ifatoia6(ifa), &new_sin6, 1); | 5570 | error = in6_ifinit(ifp, ifatoia6(ifa), &new_sin6, 1); | |
5561 | if (debug && error) | 5571 | if (debug && error) | |
5562 | { | 5572 | { | |
5563 | log(LOG_DEBUG, "%s: %s: in6_ifinit failed, error=%d\n", | 5573 | log(LOG_DEBUG, "%s: %s: in6_ifinit failed, error=%d\n", | |
5564 | ifp->if_xname, __func__, error); | 5574 | ifp->if_xname, __func__, error); | |
5565 | } | 5575 | } | |
5566 | if (!error) { | 5576 | if (!error) { | |
5567 | pfil_run_addrhooks(if_pfil, SIOCAIFADDR_IN6, ifa); | 5577 | pfil_run_addrhooks(if_pfil, SIOCAIFADDR_IN6, ifa); | |
5568 | } | 5578 | } | |
5569 | ifa_release(ifa, &psref); | 5579 | ifa_release(ifa, &psref); | |
5570 | } | 5580 | } | |
5581 | ||||
5582 | IFNET_UNLOCK(ifp); | |||
5571 | } | 5583 | } | |
5572 | #endif | 5584 | #endif | |
5573 | 5585 | |||
5574 | /* | 5586 | /* | |
5575 | * Suggest a candidate address to be used by peer. | 5587 | * Suggest a candidate address to be used by peer. | |
5576 | */ | 5588 | */ | |
5577 | static void | 5589 | static void | |
5578 | sppp_suggest_ip6_addr(struct sppp *sp, struct in6_addr *suggest) | 5590 | sppp_suggest_ip6_addr(struct sppp *sp, struct in6_addr *suggest) | |
5579 | { | 5591 | { | |
5580 | struct in6_addr myaddr; | 5592 | struct in6_addr myaddr; | |
5581 | struct timeval tv; | 5593 | struct timeval tv; | |
5582 | 5594 | |||
5583 | sppp_get_ip6_addrs(sp, &myaddr, 0, 0); | 5595 | sppp_get_ip6_addrs(sp, &myaddr, 0, 0); |
--- src/sys/net/if_tun.c 2017/11/08 22:20:59 1.139.2.1
+++ src/sys/net/if_tun.c 2018/01/02 10:20:33 1.139.2.2
@@ -1,35 +1,35 @@ | @@ -1,35 +1,35 @@ | |||
1 | /* $NetBSD: if_tun.c,v 1.139.2.1 2017/11/08 22:20:59 snj Exp $ */ | 1 | /* $NetBSD: if_tun.c,v 1.139.2.2 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk> | 4 | * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk> | |
5 | * Nottingham University 1987. | 5 | * Nottingham University 1987. | |
6 | * | 6 | * | |
7 | * This source may be freely distributed, however I would be interested | 7 | * This source may be freely distributed, however I would be interested | |
8 | * in any changes that are made. | 8 | * in any changes that are made. | |
9 | * | 9 | * | |
10 | * This driver takes packets off the IP i/f and hands them up to a | 10 | * This driver takes packets off the IP i/f and hands them up to a | |
11 | * user process to have its wicked way with. This driver has its | 11 | * user process to have its wicked way with. This driver has its | |
12 | * roots in a similar driver written by Phil Cockcroft (formerly) at | 12 | * roots in a similar driver written by Phil Cockcroft (formerly) at | |
13 | * UCL. This driver is based much more on read/write/poll mode of | 13 | * UCL. This driver is based much more on read/write/poll mode of | |
14 | * operation though. | 14 | * operation though. | |
15 | */ | 15 | */ | |
16 | 16 | |||
17 | /* | 17 | /* | |
18 | * tun - tunnel software network interface. | 18 | * tun - tunnel software network interface. | |
19 | */ | 19 | */ | |
20 | 20 | |||
21 | #include <sys/cdefs.h> | 21 | #include <sys/cdefs.h> | |
22 | __KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.139.2.1 2017/11/08 22:20:59 snj Exp $"); | 22 | __KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.139.2.2 2018/01/02 10:20:33 snj Exp $"); | |
23 | 23 | |||
24 | #ifdef _KERNEL_OPT | 24 | #ifdef _KERNEL_OPT | |
25 | #include "opt_inet.h" | 25 | #include "opt_inet.h" | |
26 | #endif | 26 | #endif | |
27 | 27 | |||
28 | #include <sys/param.h> | 28 | #include <sys/param.h> | |
29 | 29 | |||
30 | #include <sys/buf.h> | 30 | #include <sys/buf.h> | |
31 | #include <sys/conf.h> | 31 | #include <sys/conf.h> | |
32 | #include <sys/cpu.h> | 32 | #include <sys/cpu.h> | |
33 | #include <sys/device.h> | 33 | #include <sys/device.h> | |
34 | #include <sys/file.h> | 34 | #include <sys/file.h> | |
35 | #include <sys/ioctl.h> | 35 | #include <sys/ioctl.h> | |
@@ -411,28 +411,26 @@ tunclose(dev_t dev, int flag, int mode, | @@ -411,28 +411,26 @@ tunclose(dev_t dev, int flag, int mode, | |||
411 | } | 411 | } | |
412 | out_nolock: | 412 | out_nolock: | |
413 | return 0; | 413 | return 0; | |
414 | } | 414 | } | |
415 | 415 | |||
416 | static void | 416 | static void | |
417 | tun_enable(struct tun_softc *tp, const struct ifaddr *ifa) | 417 | tun_enable(struct tun_softc *tp, const struct ifaddr *ifa) | |
418 | { | 418 | { | |
419 | struct ifnet *ifp = &tp->tun_if; | 419 | struct ifnet *ifp = &tp->tun_if; | |
420 | 420 | |||
421 | TUNDEBUG("%s: %s\n", __func__, ifp->if_xname); | 421 | TUNDEBUG("%s: %s\n", __func__, ifp->if_xname); | |
422 | 422 | |||
423 | mutex_enter(&tp->tun_lock); | 423 | mutex_enter(&tp->tun_lock); | |
424 | ifp->if_flags |= IFF_UP | IFF_RUNNING; | |||
425 | ||||
426 | tp->tun_flags &= ~(TUN_IASET|TUN_DSTADDR); | 424 | tp->tun_flags &= ~(TUN_IASET|TUN_DSTADDR); | |
427 | 425 | |||
428 | switch (ifa->ifa_addr->sa_family) { | 426 | switch (ifa->ifa_addr->sa_family) { | |
429 | #ifdef INET | 427 | #ifdef INET | |
430 | case AF_INET: { | 428 | case AF_INET: { | |
431 | struct sockaddr_in *sin; | 429 | struct sockaddr_in *sin; | |
432 | 430 | |||
433 | sin = satosin(ifa->ifa_addr); | 431 | sin = satosin(ifa->ifa_addr); | |
434 | if (sin && sin->sin_addr.s_addr) | 432 | if (sin && sin->sin_addr.s_addr) | |
435 | tp->tun_flags |= TUN_IASET; | 433 | tp->tun_flags |= TUN_IASET; | |
436 | 434 | |||
437 | if (ifp->if_flags & IFF_POINTOPOINT) { | 435 | if (ifp->if_flags & IFF_POINTOPOINT) { | |
438 | sin = satosin(ifa->ifa_dstaddr); | 436 | sin = satosin(ifa->ifa_dstaddr); | |
@@ -452,26 +450,27 @@ tun_enable(struct tun_softc *tp, const s | @@ -452,26 +450,27 @@ tun_enable(struct tun_softc *tp, const s | |||
452 | 450 | |||
453 | if (ifp->if_flags & IFF_POINTOPOINT) { | 451 | if (ifp->if_flags & IFF_POINTOPOINT) { | |
454 | sin = satosin6(ifa->ifa_dstaddr); | 452 | sin = satosin6(ifa->ifa_dstaddr); | |
455 | if (sin && !IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr)) | 453 | if (sin && !IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr)) | |
456 | tp->tun_flags |= TUN_DSTADDR; | 454 | tp->tun_flags |= TUN_DSTADDR; | |
457 | } else | 455 | } else | |
458 | tp->tun_flags &= ~TUN_DSTADDR; | 456 | tp->tun_flags &= ~TUN_DSTADDR; | |
459 | break; | 457 | break; | |
460 | } | 458 | } | |
461 | #endif /* INET6 */ | 459 | #endif /* INET6 */ | |
462 | default: | 460 | default: | |
463 | break; | 461 | break; | |
464 | } | 462 | } | |
463 | ifp->if_flags |= IFF_UP | IFF_RUNNING; | |||
465 | mutex_exit(&tp->tun_lock); | 464 | mutex_exit(&tp->tun_lock); | |
466 | } | 465 | } | |
467 | 466 | |||
468 | /* | 467 | /* | |
469 | * Process an ioctl request. | 468 | * Process an ioctl request. | |
470 | */ | 469 | */ | |
471 | static int | 470 | static int | |
472 | tun_ioctl(struct ifnet *ifp, u_long cmd, void *data) | 471 | tun_ioctl(struct ifnet *ifp, u_long cmd, void *data) | |
473 | { | 472 | { | |
474 | struct tun_softc *tp = (struct tun_softc *)(ifp->if_softc); | 473 | struct tun_softc *tp = (struct tun_softc *)(ifp->if_softc); | |
475 | struct ifreq *ifr = (struct ifreq *)data; | 474 | struct ifreq *ifr = (struct ifreq *)data; | |
476 | struct ifaddr *ifa = (struct ifaddr *)data; | 475 | struct ifaddr *ifa = (struct ifaddr *)data; | |
477 | int error = 0; | 476 | int error = 0; |
--- src/sys/net/if_vlan.c 2017/12/10 10:10:25 1.97.2.10
+++ src/sys/net/if_vlan.c 2018/01/02 10:20:33 1.97.2.11
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_vlan.c,v 1.97.2.10 2017/12/10 10:10:25 snj Exp $ */ | 1 | /* $NetBSD: if_vlan.c,v 1.97.2.11 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2000, 2001 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 Andrew Doran, and by Jason R. Thorpe of Zembu Labs, Inc. | 8 | * by Andrew Doran, and by Jason R. Thorpe of Zembu Labs, Inc. | |
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. | |
@@ -68,30 +68,31 @@ | @@ -68,30 +68,31 @@ | |||
68 | * enough of an Ethernet implementation to make ARP work. The way we do | 68 | * enough of an Ethernet implementation to make ARP work. The way we do | |
69 | * this is by telling everyone that we are an Ethernet interface, and then | 69 | * this is by telling everyone that we are an Ethernet interface, and then | |
70 | * catch the packets that ether_output() left on our output queue when it | 70 | * catch the packets that ether_output() left on our output queue when it | |
71 | * calls if_start(), rewrite them for use by the real outgoing interface, | 71 | * calls if_start(), rewrite them for use by the real outgoing interface, | |
72 | * and ask it to send them. | 72 | * and ask it to send them. | |
73 | * | 73 | * | |
74 | * TODO: | 74 | * TODO: | |
75 | * | 75 | * | |
76 | * - Need some way to notify vlan interfaces when the parent | 76 | * - Need some way to notify vlan interfaces when the parent | |
77 | * interface changes MTU. | 77 | * interface changes MTU. | |
78 | */ | 78 | */ | |
79 | 79 | |||
80 | #include <sys/cdefs.h> | 80 | #include <sys/cdefs.h> | |
81 | __KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.10 2017/12/10 10:10:25 snj Exp $"); | 81 | __KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.97.2.11 2018/01/02 10:20:33 snj Exp $"); | |
82 | 82 | |||
83 | #ifdef _KERNEL_OPT | 83 | #ifdef _KERNEL_OPT | |
84 | #include "opt_inet.h" | 84 | #include "opt_inet.h" | |
85 | #include "opt_net_mpsafe.h" | |||
85 | #endif | 86 | #endif | |
86 | 87 | |||
87 | #include <sys/param.h> | 88 | #include <sys/param.h> | |
88 | #include <sys/systm.h> | 89 | #include <sys/systm.h> | |
89 | #include <sys/kernel.h> | 90 | #include <sys/kernel.h> | |
90 | #include <sys/mbuf.h> | 91 | #include <sys/mbuf.h> | |
91 | #include <sys/queue.h> | 92 | #include <sys/queue.h> | |
92 | #include <sys/socket.h> | 93 | #include <sys/socket.h> | |
93 | #include <sys/sockio.h> | 94 | #include <sys/sockio.h> | |
94 | #include <sys/systm.h> | 95 | #include <sys/systm.h> | |
95 | #include <sys/proc.h> | 96 | #include <sys/proc.h> | |
96 | #include <sys/kauth.h> | 97 | #include <sys/kauth.h> | |
97 | #include <sys/mutex.h> | 98 | #include <sys/mutex.h> | |
@@ -235,26 +236,46 @@ static struct { | @@ -235,26 +236,46 @@ static struct { | |||
235 | .lists = NULL, | 236 | .lists = NULL, | |
236 | .mask = 0, | 237 | .mask = 0, | |
237 | }; | 238 | }; | |
238 | 239 | |||
239 | pserialize_t vlan_psz __read_mostly; | 240 | pserialize_t vlan_psz __read_mostly; | |
240 | static struct psref_class *ifvm_psref_class __read_mostly; | 241 | static struct psref_class *ifvm_psref_class __read_mostly; | |
241 | 242 | |||
242 | struct if_clone vlan_cloner = | 243 | struct if_clone vlan_cloner = | |
243 | IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy); | 244 | IF_CLONE_INITIALIZER("vlan", vlan_clone_create, vlan_clone_destroy); | |
244 | 245 | |||
245 | /* Used to pad ethernet frames with < ETHER_MIN_LEN bytes */ | 246 | /* Used to pad ethernet frames with < ETHER_MIN_LEN bytes */ | |
246 | static char vlan_zero_pad_buff[ETHER_MIN_LEN]; | 247 | static char vlan_zero_pad_buff[ETHER_MIN_LEN]; | |
247 | 248 | |||
249 | static inline int | |||
250 | vlan_safe_ifpromisc(struct ifnet *ifp, int pswitch) | |||
251 | { | |||
252 | int e; | |||
253 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |||
254 | e = ifpromisc(ifp, pswitch); | |||
255 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |||
256 | return e; | |||
257 | } | |||
258 | ||||
259 | static inline int | |||
260 | vlan_safe_ifpromisc_locked(struct ifnet *ifp, int pswitch) | |||
261 | { | |||
262 | int e; | |||
263 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |||
264 | e = ifpromisc_locked(ifp, pswitch); | |||
265 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |||
266 | return e; | |||
267 | } | |||
268 | ||||
248 | void | 269 | void | |
249 | vlanattach(int n) | 270 | vlanattach(int n) | |
250 | { | 271 | { | |
251 | 272 | |||
252 | /* | 273 | /* | |
253 | * Nothing to do here, initialization is handled by the | 274 | * Nothing to do here, initialization is handled by the | |
254 | * module initialization code in vlaninit() below). | 275 | * module initialization code in vlaninit() below). | |
255 | */ | 276 | */ | |
256 | } | 277 | } | |
257 | 278 | |||
258 | static void | 279 | static void | |
259 | vlaninit(void) | 280 | vlaninit(void) | |
260 | { | 281 | { | |
@@ -328,27 +349,30 @@ vlan_clone_create(struct if_clone *ifc, | @@ -328,27 +349,30 @@ vlan_clone_create(struct if_clone *ifc, | |||
328 | mib->ifvm_p = NULL; | 349 | mib->ifvm_p = NULL; | |
329 | psref_target_init(&mib->ifvm_psref, ifvm_psref_class); | 350 | psref_target_init(&mib->ifvm_psref, ifvm_psref_class); | |
330 | 351 | |||
331 | mutex_init(&ifv->ifv_lock, MUTEX_DEFAULT, IPL_NONE); | 352 | mutex_init(&ifv->ifv_lock, MUTEX_DEFAULT, IPL_NONE); | |
332 | ifv->ifv_mib = mib; | 353 | ifv->ifv_mib = mib; | |
333 | 354 | |||
334 | mutex_enter(&ifv_list.lock); | 355 | mutex_enter(&ifv_list.lock); | |
335 | LIST_INSERT_HEAD(&ifv_list.list, ifv, ifv_list); | 356 | LIST_INSERT_HEAD(&ifv_list.list, ifv, ifv_list); | |
336 | mutex_exit(&ifv_list.lock); | 357 | mutex_exit(&ifv_list.lock); | |
337 | 358 | |||
338 | if_initname(ifp, ifc->ifc_name, unit); | 359 | if_initname(ifp, ifc->ifc_name, unit); | |
339 | ifp->if_softc = ifv; | 360 | ifp->if_softc = ifv; | |
340 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | 361 | ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; | |
341 | ifp->if_extflags = IFEF_START_MPSAFE | IFEF_NO_LINK_STATE_CHANGE; | 362 | ifp->if_extflags = IFEF_NO_LINK_STATE_CHANGE; | |
363 | #ifdef NET_MPSAFE | |||
364 | ifp->if_extflags |= IFEF_MPSAFE; | |||
365 | #endif | |||
342 | ifp->if_start = vlan_start; | 366 | ifp->if_start = vlan_start; | |
343 | ifp->if_transmit = vlan_transmit; | 367 | ifp->if_transmit = vlan_transmit; | |
344 | ifp->if_ioctl = vlan_ioctl; | 368 | ifp->if_ioctl = vlan_ioctl; | |
345 | IFQ_SET_READY(&ifp->if_snd); | 369 | IFQ_SET_READY(&ifp->if_snd); | |
346 | 370 | |||
347 | rv = if_initialize(ifp); | 371 | rv = if_initialize(ifp); | |
348 | if (rv != 0) { | 372 | if (rv != 0) { | |
349 | aprint_error("%s: if_initialize failed(%d)\n", ifp->if_xname, | 373 | aprint_error("%s: if_initialize failed(%d)\n", ifp->if_xname, | |
350 | rv); | 374 | rv); | |
351 | goto fail; | 375 | goto fail; | |
352 | } | 376 | } | |
353 | 377 | |||
354 | vlan_reset_linkname(ifp); | 378 | vlan_reset_linkname(ifp); | |
@@ -367,27 +391,29 @@ fail: | @@ -367,27 +391,29 @@ fail: | |||
367 | 391 | |||
368 | return rv; | 392 | return rv; | |
369 | } | 393 | } | |
370 | 394 | |||
371 | static int | 395 | static int | |
372 | vlan_clone_destroy(struct ifnet *ifp) | 396 | vlan_clone_destroy(struct ifnet *ifp) | |
373 | { | 397 | { | |
374 | struct ifvlan *ifv = ifp->if_softc; | 398 | struct ifvlan *ifv = ifp->if_softc; | |
375 | 399 | |||
376 | mutex_enter(&ifv_list.lock); | 400 | mutex_enter(&ifv_list.lock); | |
377 | LIST_REMOVE(ifv, ifv_list); | 401 | LIST_REMOVE(ifv, ifv_list); | |
378 | mutex_exit(&ifv_list.lock); | 402 | mutex_exit(&ifv_list.lock); | |
379 | 403 | |||
404 | IFNET_LOCK(ifp); | |||
380 | vlan_unconfig(ifp); | 405 | vlan_unconfig(ifp); | |
406 | IFNET_UNLOCK(ifp); | |||
381 | if_detach(ifp); | 407 | if_detach(ifp); | |
382 | 408 | |||
383 | psref_target_destroy(&ifv->ifv_mib->ifvm_psref, ifvm_psref_class); | 409 | psref_target_destroy(&ifv->ifv_mib->ifvm_psref, ifvm_psref_class); | |
384 | kmem_free(ifv->ifv_mib, sizeof(struct ifvlan_linkmib)); | 410 | kmem_free(ifv->ifv_mib, sizeof(struct ifvlan_linkmib)); | |
385 | mutex_destroy(&ifv->ifv_lock); | 411 | mutex_destroy(&ifv->ifv_lock); | |
386 | free(ifv, M_DEVBUF); | 412 | free(ifv, M_DEVBUF); | |
387 | 413 | |||
388 | return (0); | 414 | return (0); | |
389 | } | 415 | } | |
390 | 416 | |||
391 | /* | 417 | /* | |
392 | * Configure a VLAN interface. | 418 | * Configure a VLAN interface. | |
393 | */ | 419 | */ | |
@@ -427,27 +453,30 @@ vlan_config(struct ifvlan *ifv, struct i | @@ -427,27 +453,30 @@ vlan_config(struct ifvlan *ifv, struct i | |||
427 | nmib_psref = &nmib->ifvm_psref; | 453 | nmib_psref = &nmib->ifvm_psref; | |
428 | 454 | |||
429 | psref_target_init(nmib_psref, ifvm_psref_class); | 455 | psref_target_init(nmib_psref, ifvm_psref_class); | |
430 | 456 | |||
431 | switch (p->if_type) { | 457 | switch (p->if_type) { | |
432 | case IFT_ETHER: | 458 | case IFT_ETHER: | |
433 | { | 459 | { | |
434 | struct ethercom *ec = (void *) p; | 460 | struct ethercom *ec = (void *) p; | |
435 | nmib->ifvm_msw = &vlan_ether_multisw; | 461 | nmib->ifvm_msw = &vlan_ether_multisw; | |
436 | nmib->ifvm_encaplen = ETHER_VLAN_ENCAP_LEN; | 462 | nmib->ifvm_encaplen = ETHER_VLAN_ENCAP_LEN; | |
437 | nmib->ifvm_mintu = ETHERMIN; | 463 | nmib->ifvm_mintu = ETHERMIN; | |
438 | 464 | |||
439 | if (ec->ec_nvlans++ == 0) { | 465 | if (ec->ec_nvlans++ == 0) { | |
440 | if ((error = ether_enable_vlan_mtu(p)) >= 0) { | 466 | IFNET_LOCK(p); | |
467 | error = ether_enable_vlan_mtu(p); | |||
468 | IFNET_UNLOCK(p); | |||
469 | if (error >= 0) { | |||
441 | if (error) { | 470 | if (error) { | |
442 | ec->ec_nvlans--; | 471 | ec->ec_nvlans--; | |
443 | goto done; | 472 | goto done; | |
444 | } | 473 | } | |
445 | nmib->ifvm_mtufudge = 0; | 474 | nmib->ifvm_mtufudge = 0; | |
446 | } else { | 475 | } else { | |
447 | /* | 476 | /* | |
448 | * Fudge the MTU by the encapsulation size. This | 477 | * Fudge the MTU by the encapsulation size. This | |
449 | * makes us incompatible with strictly compliant | 478 | * makes us incompatible with strictly compliant | |
450 | * 802.1Q implementations, but allows us to use | 479 | * 802.1Q implementations, but allows us to use | |
451 | * the feature with other NetBSD | 480 | * the feature with other NetBSD | |
452 | * implementations, which might still be useful. | 481 | * implementations, which might still be useful. | |
453 | */ | 482 | */ | |
@@ -524,72 +553,80 @@ done: | @@ -524,72 +553,80 @@ done: | |||
524 | return error; | 553 | return error; | |
525 | } | 554 | } | |
526 | 555 | |||
527 | /* | 556 | /* | |
528 | * Unconfigure a VLAN interface. | 557 | * Unconfigure a VLAN interface. | |
529 | */ | 558 | */ | |
530 | static void | 559 | static void | |
531 | vlan_unconfig(struct ifnet *ifp) | 560 | vlan_unconfig(struct ifnet *ifp) | |
532 | { | 561 | { | |
533 | struct ifvlan *ifv = ifp->if_softc; | 562 | struct ifvlan *ifv = ifp->if_softc; | |
534 | struct ifvlan_linkmib *nmib = NULL; | 563 | struct ifvlan_linkmib *nmib = NULL; | |
535 | int error; | 564 | int error; | |
536 | 565 | |||
566 | KASSERT(IFNET_LOCKED(ifp)); | |||
567 | ||||
537 | nmib = kmem_alloc(sizeof(*nmib), KM_SLEEP); | 568 | nmib = kmem_alloc(sizeof(*nmib), KM_SLEEP); | |
538 | 569 | |||
539 | mutex_enter(&ifv->ifv_lock); | 570 | mutex_enter(&ifv->ifv_lock); | |
540 | error = vlan_unconfig_locked(ifv, nmib); | 571 | error = vlan_unconfig_locked(ifv, nmib); | |
541 | mutex_exit(&ifv->ifv_lock); | 572 | mutex_exit(&ifv->ifv_lock); | |
542 | 573 | |||
543 | if (error) | 574 | if (error) | |
544 | kmem_free(nmib, sizeof(*nmib)); | 575 | kmem_free(nmib, sizeof(*nmib)); | |
545 | } | 576 | } | |
546 | static int | 577 | static int | |
547 | vlan_unconfig_locked(struct ifvlan *ifv, struct ifvlan_linkmib *nmib) | 578 | vlan_unconfig_locked(struct ifvlan *ifv, struct ifvlan_linkmib *nmib) | |
548 | { | 579 | { | |
549 | struct ifnet *p; | 580 | struct ifnet *p; | |
550 | struct ifnet *ifp = &ifv->ifv_if; | 581 | struct ifnet *ifp = &ifv->ifv_if; | |
551 | struct psref_target *nmib_psref = NULL; | 582 | struct psref_target *nmib_psref = NULL; | |
552 | struct ifvlan_linkmib *omib; | 583 | struct ifvlan_linkmib *omib; | |
553 | int error = 0; | 584 | int error = 0; | |
554 | 585 | |||
586 | KASSERT(IFNET_LOCKED(ifp)); | |||
555 | KASSERT(mutex_owned(&ifv->ifv_lock)); | 587 | KASSERT(mutex_owned(&ifv->ifv_lock)); | |
556 | 588 | |||
589 | ifp->if_flags &= ~(IFF_UP|IFF_RUNNING); | |||
590 | ||||
557 | omib = ifv->ifv_mib; | 591 | omib = ifv->ifv_mib; | |
558 | p = omib->ifvm_p; | 592 | p = omib->ifvm_p; | |
559 | 593 | |||
560 | if (p == NULL) { | 594 | if (p == NULL) { | |
561 | error = -1; | 595 | error = -1; | |
562 | goto done; | 596 | goto done; | |
563 | } | 597 | } | |
564 | 598 | |||
565 | *nmib = *omib; | 599 | *nmib = *omib; | |
566 | nmib_psref = &nmib->ifvm_psref; | 600 | nmib_psref = &nmib->ifvm_psref; | |
567 | psref_target_init(nmib_psref, ifvm_psref_class); | 601 | psref_target_init(nmib_psref, ifvm_psref_class); | |
568 | 602 | |||
569 | /* | 603 | /* | |
570 | * Since the interface is being unconfigured, we need to empty the | 604 | * Since the interface is being unconfigured, we need to empty the | |
571 | * list of multicast groups that we may have joined while we were | 605 | * list of multicast groups that we may have joined while we were | |
572 | * alive and remove them from the parent's list also. | 606 | * alive and remove them from the parent's list also. | |
573 | */ | 607 | */ | |
574 | (*nmib->ifvm_msw->vmsw_purgemulti)(ifv); | 608 | (*nmib->ifvm_msw->vmsw_purgemulti)(ifv); | |
575 | 609 | |||
576 | /* Disconnect from parent. */ | 610 | /* Disconnect from parent. */ | |
577 | switch (p->if_type) { | 611 | switch (p->if_type) { | |
578 | case IFT_ETHER: | 612 | case IFT_ETHER: | |
579 | { | 613 | { | |
580 | struct ethercom *ec = (void *)p; | 614 | struct ethercom *ec = (void *)p; | |
581 | if (--ec->ec_nvlans == 0) | 615 | if (--ec->ec_nvlans == 0) { | |
582 | (void)ether_disable_vlan_mtu(p); | 616 | IFNET_LOCK(p); | |
617 | (void) ether_disable_vlan_mtu(p); | |||
618 | IFNET_UNLOCK(p); | |||
619 | } | |||
583 | 620 | |||
584 | ether_ifdetach(ifp); | 621 | ether_ifdetach(ifp); | |
585 | /* Restore vlan_ioctl overwritten by ether_ifdetach */ | 622 | /* Restore vlan_ioctl overwritten by ether_ifdetach */ | |
586 | ifp->if_ioctl = vlan_ioctl; | 623 | ifp->if_ioctl = vlan_ioctl; | |
587 | vlan_reset_linkname(ifp); | 624 | vlan_reset_linkname(ifp); | |
588 | break; | 625 | break; | |
589 | } | 626 | } | |
590 | 627 | |||
591 | #ifdef DIAGNOSTIC | 628 | #ifdef DIAGNOSTIC | |
592 | default: | 629 | default: | |
593 | panic("vlan_unconfig: impossible"); | 630 | panic("vlan_unconfig: impossible"); | |
594 | #endif | 631 | #endif | |
595 | } | 632 | } | |
@@ -602,35 +639,36 @@ vlan_unconfig_locked(struct ifvlan *ifv, | @@ -602,35 +639,36 @@ vlan_unconfig_locked(struct ifvlan *ifv, | |||
602 | PSLIST_WRITER_REMOVE(ifv, ifv_hash); | 639 | PSLIST_WRITER_REMOVE(ifv, ifv_hash); | |
603 | pserialize_perform(vlan_psz); | 640 | pserialize_perform(vlan_psz); | |
604 | mutex_exit(&ifv_hash.lock); | 641 | mutex_exit(&ifv_hash.lock); | |
605 | PSLIST_ENTRY_DESTROY(ifv, ifv_hash); | 642 | PSLIST_ENTRY_DESTROY(ifv, ifv_hash); | |
606 | 643 | |||
607 | vlan_linkmib_update(ifv, nmib); | 644 | vlan_linkmib_update(ifv, nmib); | |
608 | 645 | |||
609 | mutex_exit(&ifv->ifv_lock); | 646 | mutex_exit(&ifv->ifv_lock); | |
610 | 647 | |||
611 | nmib_psref = NULL; | 648 | nmib_psref = NULL; | |
612 | kmem_free(omib, sizeof(*omib)); | 649 | kmem_free(omib, sizeof(*omib)); | |
613 | 650 | |||
614 | #ifdef INET6 | 651 | #ifdef INET6 | |
652 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |||
615 | /* To delete v6 link local addresses */ | 653 | /* To delete v6 link local addresses */ | |
616 | if (in6_present) | 654 | if (in6_present) | |
617 | in6_ifdetach(ifp); | 655 | in6_ifdetach(ifp); | |
656 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |||
618 | #endif | 657 | #endif | |
619 | 658 | |||
620 | if ((ifp->if_flags & IFF_PROMISC) != 0) | 659 | if ((ifp->if_flags & IFF_PROMISC) != 0) | |
621 | ifpromisc(ifp, 0); | 660 | vlan_safe_ifpromisc_locked(ifp, 0); | |
622 | if_down(ifp); | 661 | if_down_locked(ifp); | |
623 | ifp->if_flags &= ~(IFF_UP|IFF_RUNNING); | |||
624 | ifp->if_capabilities = 0; | 662 | ifp->if_capabilities = 0; | |
625 | mutex_enter(&ifv->ifv_lock); | 663 | mutex_enter(&ifv->ifv_lock); | |
626 | done: | 664 | done: | |
627 | 665 | |||
628 | if (nmib_psref) | 666 | if (nmib_psref) | |
629 | psref_target_destroy(nmib_psref, ifvm_psref_class); | 667 | psref_target_destroy(nmib_psref, ifvm_psref_class); | |
630 | 668 | |||
631 | return error; | 669 | return error; | |
632 | } | 670 | } | |
633 | 671 | |||
634 | static void | 672 | static void | |
635 | vlan_hash_init(void) | 673 | vlan_hash_init(void) | |
636 | { | 674 | { | |
@@ -779,38 +817,43 @@ vlan_ifdetach(struct ifnet *p) | @@ -779,38 +817,43 @@ vlan_ifdetach(struct ifnet *p) | |||
779 | * The value of "cnt" does not increase while ifv_list.lock | 817 | * The value of "cnt" does not increase while ifv_list.lock | |
780 | * and ifv->ifv_lock are released here, because the parent | 818 | * and ifv->ifv_lock are released here, because the parent | |
781 | * interface is detaching. | 819 | * interface is detaching. | |
782 | */ | 820 | */ | |
783 | nmibs = kmem_alloc(sizeof(*nmibs) * cnt, KM_SLEEP); | 821 | nmibs = kmem_alloc(sizeof(*nmibs) * cnt, KM_SLEEP); | |
784 | for (i=0; i < cnt; i++) { | 822 | for (i=0; i < cnt; i++) { | |
785 | nmibs[i] = kmem_alloc(sizeof(*nmibs[i]), KM_SLEEP); | 823 | nmibs[i] = kmem_alloc(sizeof(*nmibs[i]), KM_SLEEP); | |
786 | } | 824 | } | |
787 | 825 | |||
788 | mutex_enter(&ifv_list.lock); | 826 | mutex_enter(&ifv_list.lock); | |
789 | 827 | |||
790 | i = 0; | 828 | i = 0; | |
791 | LIST_FOREACH(ifv, &ifv_list.list, ifv_list) { | 829 | LIST_FOREACH(ifv, &ifv_list.list, ifv_list) { | |
830 | struct ifnet *ifp = &ifv->ifv_if; | |||
831 | ||||
832 | /* Need IFNET_LOCK that must be held before ifv_lock. */ | |||
833 | IFNET_LOCK(ifp); | |||
792 | mutex_enter(&ifv->ifv_lock); | 834 | mutex_enter(&ifv->ifv_lock); | |
793 | if (ifv->ifv_mib->ifvm_p == p) { | 835 | if (ifv->ifv_mib->ifvm_p == p) { | |
794 | KASSERTMSG(i < cnt, "no memory for unconfig, parent=%s", | 836 | KASSERTMSG(i < cnt, "no memory for unconfig, parent=%s", | |
795 | p->if_xname); | 837 | p->if_xname); | |
796 | error = vlan_unconfig_locked(ifv, nmibs[i]); | 838 | error = vlan_unconfig_locked(ifv, nmibs[i]); | |
797 | if (!error) { | 839 | if (!error) { | |
798 | nmibs[i] = NULL; | 840 | nmibs[i] = NULL; | |
799 | i++; | 841 | i++; | |
800 | } | 842 | } | |
801 | 843 | |||
802 | } | 844 | } | |
803 | mutex_exit(&ifv->ifv_lock); | 845 | mutex_exit(&ifv->ifv_lock); | |
846 | IFNET_UNLOCK(ifp); | |||
804 | } | 847 | } | |
805 | 848 | |||
806 | mutex_exit(&ifv_list.lock); | 849 | mutex_exit(&ifv_list.lock); | |
807 | curlwp_bindx(bound); | 850 | curlwp_bindx(bound); | |
808 | 851 | |||
809 | for (i=0; i < cnt; i++) { | 852 | for (i=0; i < cnt; i++) { | |
810 | if (nmibs[i]) | 853 | if (nmibs[i]) | |
811 | kmem_free(nmibs[i], sizeof(*nmibs[i])); | 854 | kmem_free(nmibs[i], sizeof(*nmibs[i])); | |
812 | } | 855 | } | |
813 | 856 | |||
814 | kmem_free(nmibs, sizeof(*nmibs) * cnt); | 857 | kmem_free(nmibs, sizeof(*nmibs) * cnt); | |
815 | 858 | |||
816 | return; | 859 | return; | |
@@ -824,33 +867,33 @@ vlan_set_promisc(struct ifnet *ifp) | @@ -824,33 +867,33 @@ vlan_set_promisc(struct ifnet *ifp) | |||
824 | struct psref psref; | 867 | struct psref psref; | |
825 | int error = 0; | 868 | int error = 0; | |
826 | int bound; | 869 | int bound; | |
827 | 870 | |||
828 | bound = curlwp_bind(); | 871 | bound = curlwp_bind(); | |
829 | mib = vlan_getref_linkmib(ifv, &psref); | 872 | mib = vlan_getref_linkmib(ifv, &psref); | |
830 | if (mib == NULL) { | 873 | if (mib == NULL) { | |
831 | curlwp_bindx(bound); | 874 | curlwp_bindx(bound); | |
832 | return EBUSY; | 875 | return EBUSY; | |
833 | } | 876 | } | |
834 | 877 | |||
835 | if ((ifp->if_flags & IFF_PROMISC) != 0) { | 878 | if ((ifp->if_flags & IFF_PROMISC) != 0) { | |
836 | if ((ifv->ifv_flags & IFVF_PROMISC) == 0) { | 879 | if ((ifv->ifv_flags & IFVF_PROMISC) == 0) { | |
837 | error = ifpromisc(mib->ifvm_p, 1); | 880 | error = vlan_safe_ifpromisc(mib->ifvm_p, 1); | |
838 | if (error == 0) | 881 | if (error == 0) | |
839 | ifv->ifv_flags |= IFVF_PROMISC; | 882 | ifv->ifv_flags |= IFVF_PROMISC; | |
840 | } | 883 | } | |
841 | } else { | 884 | } else { | |
842 | if ((ifv->ifv_flags & IFVF_PROMISC) != 0) { | 885 | if ((ifv->ifv_flags & IFVF_PROMISC) != 0) { | |
843 | error = ifpromisc(mib->ifvm_p, 0); | 886 | error = vlan_safe_ifpromisc(mib->ifvm_p, 0); | |
844 | if (error == 0) | 887 | if (error == 0) | |
845 | ifv->ifv_flags &= ~IFVF_PROMISC; | 888 | ifv->ifv_flags &= ~IFVF_PROMISC; | |
846 | } | 889 | } | |
847 | } | 890 | } | |
848 | vlan_putref_linkmib(mib, &psref); | 891 | vlan_putref_linkmib(mib, &psref); | |
849 | curlwp_bindx(bound); | 892 | curlwp_bindx(bound); | |
850 | 893 | |||
851 | return (error); | 894 | return (error); | |
852 | } | 895 | } | |
853 | 896 | |||
854 | static int | 897 | static int | |
855 | vlan_ioctl(struct ifnet *ifp, u_long cmd, void *data) | 898 | vlan_ioctl(struct ifnet *ifp, u_long cmd, void *data) | |
856 | { | 899 | { | |
@@ -907,50 +950,51 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd | @@ -907,50 +950,51 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd | |||
907 | break; | 950 | break; | |
908 | 951 | |||
909 | if (vlr.vlr_parent[0] == '\0') { | 952 | if (vlr.vlr_parent[0] == '\0') { | |
910 | bound = curlwp_bind(); | 953 | bound = curlwp_bind(); | |
911 | mib = vlan_getref_linkmib(ifv, &psref); | 954 | mib = vlan_getref_linkmib(ifv, &psref); | |
912 | if (mib == NULL) { | 955 | if (mib == NULL) { | |
913 | curlwp_bindx(bound); | 956 | curlwp_bindx(bound); | |
914 | error = EBUSY; | 957 | error = EBUSY; | |
915 | break; | 958 | break; | |
916 | } | 959 | } | |
917 | 960 | |||
918 | if (mib->ifvm_p != NULL && | 961 | if (mib->ifvm_p != NULL && | |
919 | (ifp->if_flags & IFF_PROMISC) != 0) | 962 | (ifp->if_flags & IFF_PROMISC) != 0) | |
920 | error = ifpromisc(mib->ifvm_p, 0); | 963 | error = vlan_safe_ifpromisc(mib->ifvm_p, 0); | |
921 | 964 | |||
922 | vlan_putref_linkmib(mib, &psref); | 965 | vlan_putref_linkmib(mib, &psref); | |
923 | curlwp_bindx(bound); | 966 | curlwp_bindx(bound); | |
924 | 967 | |||
925 | vlan_unconfig(ifp); | 968 | vlan_unconfig(ifp); | |
926 | break; | 969 | break; | |
927 | } | 970 | } | |
928 | if (vlr.vlr_tag != EVL_VLANOFTAG(vlr.vlr_tag)) { | 971 | if (vlr.vlr_tag != EVL_VLANOFTAG(vlr.vlr_tag)) { | |
929 | error = EINVAL; /* check for valid tag */ | 972 | error = EINVAL; /* check for valid tag */ | |
930 | break; | 973 | break; | |
931 | } | 974 | } | |
932 | if ((pr = ifunit(vlr.vlr_parent)) == NULL) { | 975 | if ((pr = ifunit(vlr.vlr_parent)) == NULL) { | |
933 | error = ENOENT; | 976 | error = ENOENT; | |
934 | break; | 977 | break; | |
935 | } | 978 | } | |
936 | error = vlan_config(ifv, pr, vlr.vlr_tag); | 979 | error = vlan_config(ifv, pr, vlr.vlr_tag); | |
937 | if (error != 0) { | 980 | if (error != 0) { | |
938 | break; | 981 | break; | |
939 | } | 982 | } | |
940 | ifp->if_flags |= IFF_RUNNING; | |||
941 | 983 | |||
942 | /* Update promiscuous mode, if necessary. */ | 984 | /* Update promiscuous mode, if necessary. */ | |
943 | vlan_set_promisc(ifp); | 985 | vlan_set_promisc(ifp); | |
986 | ||||
987 | ifp->if_flags |= IFF_RUNNING; | |||
944 | break; | 988 | break; | |
945 | 989 | |||
946 | case SIOCGETVLAN: | 990 | case SIOCGETVLAN: | |
947 | memset(&vlr, 0, sizeof(vlr)); | 991 | memset(&vlr, 0, sizeof(vlr)); | |
948 | bound = curlwp_bind(); | 992 | bound = curlwp_bind(); | |
949 | mib = vlan_getref_linkmib(ifv, &psref); | 993 | mib = vlan_getref_linkmib(ifv, &psref); | |
950 | if (mib == NULL) { | 994 | if (mib == NULL) { | |
951 | curlwp_bindx(bound); | 995 | curlwp_bindx(bound); | |
952 | error = EBUSY; | 996 | error = EBUSY; | |
953 | break; | 997 | break; | |
954 | } | 998 | } | |
955 | if (mib->ifvm_p != NULL) { | 999 | if (mib->ifvm_p != NULL) { | |
956 | snprintf(vlr.vlr_parent, sizeof(vlr.vlr_parent), "%s", | 1000 | snprintf(vlr.vlr_parent, sizeof(vlr.vlr_parent), "%s", | |
@@ -1104,27 +1148,32 @@ vlan_ether_addmulti(struct ifvlan *ifv, | @@ -1104,27 +1148,32 @@ vlan_ether_addmulti(struct ifvlan *ifv, | |||
1104 | goto alloc_failed; | 1148 | goto alloc_failed; | |
1105 | } | 1149 | } | |
1106 | 1150 | |||
1107 | /* | 1151 | /* | |
1108 | * As ether_addmulti() returns ENETRESET, following two | 1152 | * As ether_addmulti() returns ENETRESET, following two | |
1109 | * statement shouldn't fail. | 1153 | * statement shouldn't fail. | |
1110 | */ | 1154 | */ | |
1111 | (void)ether_multiaddr(sa, addrlo, addrhi); | 1155 | (void)ether_multiaddr(sa, addrlo, addrhi); | |
1112 | ETHER_LOOKUP_MULTI(addrlo, addrhi, &ifv->ifv_ec, mc->mc_enm); | 1156 | ETHER_LOOKUP_MULTI(addrlo, addrhi, &ifv->ifv_ec, mc->mc_enm); | |
1113 | memcpy(&mc->mc_addr, sa, sa->sa_len); | 1157 | memcpy(&mc->mc_addr, sa, sa->sa_len); | |
1114 | LIST_INSERT_HEAD(&ifv->ifv_mc_listhead, mc, mc_entries); | 1158 | LIST_INSERT_HEAD(&ifv->ifv_mc_listhead, mc, mc_entries); | |
1115 | 1159 | |||
1116 | mib = ifv->ifv_mib; | 1160 | mib = ifv->ifv_mib; | |
1161 | ||||
1162 | KERNEL_LOCK_UNLESS_IFP_MPSAFE(mib->ifvm_p); | |||
1163 | IFNET_LOCK(mib->ifvm_p); | |||
1117 | error = if_mcast_op(mib->ifvm_p, SIOCADDMULTI, sa); | 1164 | error = if_mcast_op(mib->ifvm_p, SIOCADDMULTI, sa); | |
1165 | IFNET_UNLOCK(mib->ifvm_p); | |||
1166 | KERNEL_UNLOCK_UNLESS_IFP_MPSAFE(mib->ifvm_p); | |||
1118 | 1167 | |||
1119 | if (error != 0) | 1168 | if (error != 0) | |
1120 | goto ioctl_failed; | 1169 | goto ioctl_failed; | |
1121 | return (error); | 1170 | return (error); | |
1122 | 1171 | |||
1123 | ioctl_failed: | 1172 | ioctl_failed: | |
1124 | LIST_REMOVE(mc, mc_entries); | 1173 | LIST_REMOVE(mc, mc_entries); | |
1125 | free(mc, M_DEVBUF); | 1174 | free(mc, M_DEVBUF); | |
1126 | alloc_failed: | 1175 | alloc_failed: | |
1127 | (void)ether_delmulti(sa, &ifv->ifv_ec); | 1176 | (void)ether_delmulti(sa, &ifv->ifv_ec); | |
1128 | return (error); | 1177 | return (error); | |
1129 | } | 1178 | } | |
1130 | 1179 | |||
@@ -1144,27 +1193,29 @@ vlan_ether_delmulti(struct ifvlan *ifv, | @@ -1144,27 +1193,29 @@ vlan_ether_delmulti(struct ifvlan *ifv, | |||
1144 | * Find a key to lookup vlan_mc_entry. We have to do this | 1193 | * Find a key to lookup vlan_mc_entry. We have to do this | |
1145 | * before calling ether_delmulti for obvious reason. | 1194 | * before calling ether_delmulti for obvious reason. | |
1146 | */ | 1195 | */ | |
1147 | if ((error = ether_multiaddr(sa, addrlo, addrhi)) != 0) | 1196 | if ((error = ether_multiaddr(sa, addrlo, addrhi)) != 0) | |
1148 | return (error); | 1197 | return (error); | |
1149 | ETHER_LOOKUP_MULTI(addrlo, addrhi, &ifv->ifv_ec, enm); | 1198 | ETHER_LOOKUP_MULTI(addrlo, addrhi, &ifv->ifv_ec, enm); | |
1150 | 1199 | |||
1151 | error = ether_delmulti(sa, &ifv->ifv_ec); | 1200 | error = ether_delmulti(sa, &ifv->ifv_ec); | |
1152 | if (error != ENETRESET) | 1201 | if (error != ENETRESET) | |
1153 | return (error); | 1202 | return (error); | |
1154 | 1203 | |||
1155 | /* We no longer use this multicast address. Tell parent so. */ | 1204 | /* We no longer use this multicast address. Tell parent so. */ | |
1156 | mib = ifv->ifv_mib; | 1205 | mib = ifv->ifv_mib; | |
1206 | IFNET_LOCK(mib->ifvm_p); | |||
1157 | error = if_mcast_op(mib->ifvm_p, SIOCDELMULTI, sa); | 1207 | error = if_mcast_op(mib->ifvm_p, SIOCDELMULTI, sa); | |
1208 | IFNET_UNLOCK(mib->ifvm_p); | |||
1158 | 1209 | |||
1159 | if (error == 0) { | 1210 | if (error == 0) { | |
1160 | /* And forget about this address. */ | 1211 | /* And forget about this address. */ | |
1161 | for (mc = LIST_FIRST(&ifv->ifv_mc_listhead); mc != NULL; | 1212 | for (mc = LIST_FIRST(&ifv->ifv_mc_listhead); mc != NULL; | |
1162 | mc = LIST_NEXT(mc, mc_entries)) { | 1213 | mc = LIST_NEXT(mc, mc_entries)) { | |
1163 | if (mc->mc_enm == enm) { | 1214 | if (mc->mc_enm == enm) { | |
1164 | LIST_REMOVE(mc, mc_entries); | 1215 | LIST_REMOVE(mc, mc_entries); | |
1165 | free(mc, M_DEVBUF); | 1216 | free(mc, M_DEVBUF); | |
1166 | break; | 1217 | break; | |
1167 | } | 1218 | } | |
1168 | } | 1219 | } | |
1169 | KASSERT(mc != NULL); | 1220 | KASSERT(mc != NULL); | |
1170 | } else | 1221 | } else | |
@@ -1179,28 +1230,30 @@ vlan_ether_delmulti(struct ifvlan *ifv, | @@ -1179,28 +1230,30 @@ vlan_ether_delmulti(struct ifvlan *ifv, | |||
1179 | static void | 1230 | static void | |
1180 | vlan_ether_purgemulti(struct ifvlan *ifv) | 1231 | vlan_ether_purgemulti(struct ifvlan *ifv) | |
1181 | { | 1232 | { | |
1182 | struct vlan_mc_entry *mc; | 1233 | struct vlan_mc_entry *mc; | |
1183 | struct ifvlan_linkmib *mib; | 1234 | struct ifvlan_linkmib *mib; | |
1184 | 1235 | |||
1185 | KASSERT(mutex_owned(&ifv->ifv_lock)); | 1236 | KASSERT(mutex_owned(&ifv->ifv_lock)); | |
1186 | mib = ifv->ifv_mib; | 1237 | mib = ifv->ifv_mib; | |
1187 | if (mib == NULL) { | 1238 | if (mib == NULL) { | |
1188 | return; | 1239 | return; | |
1189 | } | 1240 | } | |
1190 | 1241 | |||
1191 | while ((mc = LIST_FIRST(&ifv->ifv_mc_listhead)) != NULL) { | 1242 | while ((mc = LIST_FIRST(&ifv->ifv_mc_listhead)) != NULL) { | |
1243 | IFNET_LOCK(mib->ifvm_p); | |||
1192 | (void)if_mcast_op(mib->ifvm_p, SIOCDELMULTI, | 1244 | (void)if_mcast_op(mib->ifvm_p, SIOCDELMULTI, | |
1193 | (const struct sockaddr *)&mc->mc_addr); | 1245 | (const struct sockaddr *)&mc->mc_addr); | |
1246 | IFNET_UNLOCK(mib->ifvm_p); | |||
1194 | LIST_REMOVE(mc, mc_entries); | 1247 | LIST_REMOVE(mc, mc_entries); | |
1195 | free(mc, M_DEVBUF); | 1248 | free(mc, M_DEVBUF); | |
1196 | } | 1249 | } | |
1197 | } | 1250 | } | |
1198 | 1251 | |||
1199 | static void | 1252 | static void | |
1200 | vlan_start(struct ifnet *ifp) | 1253 | vlan_start(struct ifnet *ifp) | |
1201 | { | 1254 | { | |
1202 | struct ifvlan *ifv = ifp->if_softc; | 1255 | struct ifvlan *ifv = ifp->if_softc; | |
1203 | struct ifnet *p; | 1256 | struct ifnet *p; | |
1204 | struct ethercom *ec; | 1257 | struct ethercom *ec; | |
1205 | struct mbuf *m; | 1258 | struct mbuf *m; | |
1206 | struct ifvlan_linkmib *mib; | 1259 | struct ifvlan_linkmib *mib; |
--- src/sys/net/rtsock.c 2017/10/21 19:43:54 1.213.2.3
+++ src/sys/net/rtsock.c 2018/01/02 10:20:33 1.213.2.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rtsock.c,v 1.213.2.3 2017/10/21 19:43:54 snj Exp $ */ | 1 | /* $NetBSD: rtsock.c,v 1.213.2.4 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
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. | |
@@ -51,27 +51,27 @@ | @@ -51,27 +51,27 @@ | |||
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
58 | * SUCH DAMAGE. | 58 | * SUCH DAMAGE. | |
59 | * | 59 | * | |
60 | * @(#)rtsock.c 8.7 (Berkeley) 10/12/95 | 60 | * @(#)rtsock.c 8.7 (Berkeley) 10/12/95 | |
61 | */ | 61 | */ | |
62 | 62 | |||
63 | #include <sys/cdefs.h> | 63 | #include <sys/cdefs.h> | |
64 | __KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.3 2017/10/21 19:43:54 snj Exp $"); | 64 | __KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213.2.4 2018/01/02 10:20:33 snj Exp $"); | |
65 | 65 | |||
66 | #ifdef _KERNEL_OPT | 66 | #ifdef _KERNEL_OPT | |
67 | #include "opt_inet.h" | 67 | #include "opt_inet.h" | |
68 | #include "opt_mpls.h" | 68 | #include "opt_mpls.h" | |
69 | #include "opt_compat_netbsd.h" | 69 | #include "opt_compat_netbsd.h" | |
70 | #include "opt_sctp.h" | 70 | #include "opt_sctp.h" | |
71 | #include "opt_net_mpsafe.h" | 71 | #include "opt_net_mpsafe.h" | |
72 | #endif | 72 | #endif | |
73 | 73 | |||
74 | #include <sys/param.h> | 74 | #include <sys/param.h> | |
75 | #include <sys/systm.h> | 75 | #include <sys/systm.h> | |
76 | #include <sys/proc.h> | 76 | #include <sys/proc.h> | |
77 | #include <sys/socket.h> | 77 | #include <sys/socket.h> | |
@@ -2028,49 +2028,43 @@ again: | @@ -2028,49 +2028,43 @@ again: | |||
2028 | return error; | 2028 | return error; | |
2029 | } | 2029 | } | |
2030 | 2030 | |||
2031 | /* | 2031 | /* | |
2032 | * Routing message software interrupt routine | 2032 | * Routing message software interrupt routine | |
2033 | */ | 2033 | */ | |
2034 | static void | 2034 | static void | |
2035 | COMPATNAME(route_intr)(void *cookie) | 2035 | COMPATNAME(route_intr)(void *cookie) | |
2036 | { | 2036 | { | |
2037 | struct sockproto proto = { .sp_family = PF_XROUTE, }; | 2037 | struct sockproto proto = { .sp_family = PF_XROUTE, }; | |
2038 | struct route_info * const ri = &COMPATNAME(route_info); | 2038 | struct route_info * const ri = &COMPATNAME(route_info); | |
2039 | struct mbuf *m; | 2039 | struct mbuf *m; | |
2040 | 2040 | |||
2041 | #ifndef NET_MPSAFE | 2041 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
2042 | mutex_enter(softnet_lock); | |||
2043 | KERNEL_LOCK(1, NULL); | |||
2044 | #endif | |||
2045 | for (;;) { | 2042 | for (;;) { | |
2046 | IFQ_LOCK(&ri->ri_intrq); | 2043 | IFQ_LOCK(&ri->ri_intrq); | |
2047 | IF_DEQUEUE(&ri->ri_intrq, m); | 2044 | IF_DEQUEUE(&ri->ri_intrq, m); | |
2048 | IFQ_UNLOCK(&ri->ri_intrq); | 2045 | IFQ_UNLOCK(&ri->ri_intrq); | |
2049 | if (m == NULL) | 2046 | if (m == NULL) | |
2050 | break; | 2047 | break; | |
2051 | proto.sp_protocol = M_GETCTX(m, uintptr_t); | 2048 | proto.sp_protocol = M_GETCTX(m, uintptr_t); | |
2052 | #ifdef NET_MPSAFE | 2049 | #ifdef NET_MPSAFE | |
2053 | mutex_enter(rt_so_mtx); | 2050 | mutex_enter(rt_so_mtx); | |
2054 | #endif | 2051 | #endif | |
2055 | raw_input(m, &proto, &ri->ri_src, &ri->ri_dst, &rt_rawcb); | 2052 | raw_input(m, &proto, &ri->ri_src, &ri->ri_dst, &rt_rawcb); | |
2056 | #ifdef NET_MPSAFE | 2053 | #ifdef NET_MPSAFE | |
2057 | mutex_exit(rt_so_mtx); | 2054 | mutex_exit(rt_so_mtx); | |
2058 | #endif | 2055 | #endif | |
2059 | } | 2056 | } | |
2060 | #ifndef NET_MPSAFE | 2057 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
2061 | KERNEL_UNLOCK_ONE(NULL); | |||
2062 | mutex_exit(softnet_lock); | |||
2063 | #endif | |||
2064 | } | 2058 | } | |
2065 | 2059 | |||
2066 | /* | 2060 | /* | |
2067 | * Enqueue a message to the software interrupt routine. | 2061 | * Enqueue a message to the software interrupt routine. | |
2068 | */ | 2062 | */ | |
2069 | void | 2063 | void | |
2070 | COMPATNAME(route_enqueue)(struct mbuf *m, int family) | 2064 | COMPATNAME(route_enqueue)(struct mbuf *m, int family) | |
2071 | { | 2065 | { | |
2072 | struct route_info * const ri = &COMPATNAME(route_info); | 2066 | struct route_info * const ri = &COMPATNAME(route_info); | |
2073 | int wasempty; | 2067 | int wasempty; | |
2074 | 2068 | |||
2075 | IFQ_LOCK(&ri->ri_intrq); | 2069 | IFQ_LOCK(&ri->ri_intrq); | |
2076 | if (IF_QFULL(&ri->ri_intrq)) { | 2070 | if (IF_QFULL(&ri->ri_intrq)) { |
--- src/sys/net/agr/if_agr.c 2017/01/28 22:56:09 1.41
+++ src/sys/net/agr/if_agr.c 2018/01/02 10:20:33 1.41.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_agr.c,v 1.41 2017/01/28 22:56:09 maya Exp $ */ | 1 | /* $NetBSD: if_agr.c,v 1.41.6.1 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c)2005 YAMAMOTO Takashi, | 4 | * Copyright (c)2005 YAMAMOTO Takashi, | |
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. | |
@@ -17,27 +17,27 @@ | @@ -17,27 +17,27 @@ | |||
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | */ | 27 | */ | |
28 | 28 | |||
29 | #include <sys/cdefs.h> | 29 | #include <sys/cdefs.h> | |
30 | __KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.41 2017/01/28 22:56:09 maya Exp $"); | 30 | __KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.41.6.1 2018/01/02 10:20:33 snj Exp $"); | |
31 | 31 | |||
32 | #ifdef _KERNEL_OPT | 32 | #ifdef _KERNEL_OPT | |
33 | #include "opt_inet.h" | 33 | #include "opt_inet.h" | |
34 | #endif | 34 | #endif | |
35 | 35 | |||
36 | #include <sys/param.h> | 36 | #include <sys/param.h> | |
37 | #include <sys/callout.h> | 37 | #include <sys/callout.h> | |
38 | #include <sys/malloc.h> | 38 | #include <sys/malloc.h> | |
39 | #include <sys/mbuf.h> | 39 | #include <sys/mbuf.h> | |
40 | #include <sys/systm.h> | 40 | #include <sys/systm.h> | |
41 | #include <sys/types.h> | 41 | #include <sys/types.h> | |
42 | #include <sys/queue.h> | 42 | #include <sys/queue.h> | |
43 | #include <sys/sockio.h> | 43 | #include <sys/sockio.h> | |
@@ -693,42 +693,42 @@ agr_addport(struct ifnet *ifp, struct if | @@ -693,42 +693,42 @@ agr_addport(struct ifnet *ifp, struct if | |||
693 | port->port_ioctl = ifp_port->if_ioctl; | 693 | port->port_ioctl = ifp_port->if_ioctl; | |
694 | ifp_port->if_ioctl = agr_ioctl_filter; | 694 | ifp_port->if_ioctl = agr_ioctl_filter; | |
695 | 695 | |||
696 | port->port_flags |= AGRPORT_ATTACHED; | 696 | port->port_flags |= AGRPORT_ATTACHED; | |
697 | 697 | |||
698 | AGR_UNLOCK(sc); | 698 | AGR_UNLOCK(sc); | |
699 | 699 | |||
700 | error = (*sc->sc_iftop->iftop_portinit)(sc, port); | 700 | error = (*sc->sc_iftop->iftop_portinit)(sc, port); | |
701 | if (error) { | 701 | if (error) { | |
702 | printf("%s: portinit error %d\n", __func__, error); | 702 | printf("%s: portinit error %d\n", __func__, error); | |
703 | goto cleanup; | 703 | goto cleanup; | |
704 | } | 704 | } | |
705 | 705 | |||
706 | ifp->if_flags |= IFF_RUNNING; | |||
707 | ||||
708 | agrport_config_promisc(port, (ifp->if_flags & IFF_PROMISC) != 0); | 706 | agrport_config_promisc(port, (ifp->if_flags & IFF_PROMISC) != 0); | |
709 | error = (*sc->sc_iftop->iftop_configmulti_port)(sc, port, true); | 707 | error = (*sc->sc_iftop->iftop_configmulti_port)(sc, port, true); | |
710 | if (error) { | 708 | if (error) { | |
711 | printf("%s: configmulti error %d\n", __func__, error); | 709 | printf("%s: configmulti error %d\n", __func__, error); | |
712 | goto cleanup; | 710 | goto cleanup; | |
713 | } | 711 | } | |
714 | 712 | |||
715 | AGR_LOCK(sc); | 713 | AGR_LOCK(sc); | |
716 | port->port_flags &= ~AGRPORT_LARVAL; | 714 | port->port_flags &= ~AGRPORT_LARVAL; | |
717 | AGR_UNLOCK(sc); | 715 | AGR_UNLOCK(sc); | |
718 | out: | 716 | out: | |
719 | if (error && port) { | 717 | if (error && port) { | |
720 | free(port, M_DEVBUF); | 718 | free(port, M_DEVBUF); | |
721 | } | 719 | } | |
720 | if (error == 0) | |||
721 | ifp->if_flags |= IFF_RUNNING; | |||
722 | return error; | 722 | return error; | |
723 | 723 | |||
724 | cleanup: | 724 | cleanup: | |
725 | if (agrport_cleanup(sc, port)) { | 725 | if (agrport_cleanup(sc, port)) { | |
726 | printf("%s: error on cleanup\n", __func__); | 726 | printf("%s: error on cleanup\n", __func__); | |
727 | 727 | |||
728 | port = NULL; /* XXX */ | 728 | port = NULL; /* XXX */ | |
729 | } | 729 | } | |
730 | 730 | |||
731 | if (sc->sc_nports == 0) { | 731 | if (sc->sc_nports == 0) { | |
732 | KASSERT(TAILQ_EMPTY(&sc->sc_ports)); | 732 | KASSERT(TAILQ_EMPTY(&sc->sc_ports)); | |
733 | agrtimer_stop(sc); | 733 | agrtimer_stop(sc); | |
734 | (*sc->sc_iftop->iftop_dtor)(sc); | 734 | (*sc->sc_iftop->iftop_dtor)(sc); |
--- src/sys/net/npf/npf_ifaddr.c 2017/01/03 00:58:05 1.2
+++ src/sys/net/npf/npf_ifaddr.c 2018/01/02 10:20:33 1.2.12.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: npf_ifaddr.c,v 1.2 2017/01/03 00:58:05 rmind Exp $ */ | 1 | /* $NetBSD: npf_ifaddr.c,v 1.2.12.1 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2014 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 Mindaugas Rasiukevicius. | 8 | * by Mindaugas Rasiukevicius. | |
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. | |
@@ -24,27 +24,27 @@ | @@ -24,27 +24,27 @@ | |||
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | /* | 32 | /* | |
33 | * NPF network interface handling module. | 33 | * NPF network interface handling module. | |
34 | */ | 34 | */ | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | __KERNEL_RCSID(0, "$NetBSD: npf_ifaddr.c,v 1.2 2017/01/03 00:58:05 rmind Exp $"); | 37 | __KERNEL_RCSID(0, "$NetBSD: npf_ifaddr.c,v 1.2.12.1 2018/01/02 10:20:33 snj Exp $"); | |
38 | 38 | |||
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/types.h> | 40 | #include <sys/types.h> | |
41 | #include <sys/kmem.h> | 41 | #include <sys/kmem.h> | |
42 | 42 | |||
43 | #include <net/if.h> | 43 | #include <net/if.h> | |
44 | #include <netinet/in.h> | 44 | #include <netinet/in.h> | |
45 | #include <netinet6/in6_var.h> | 45 | #include <netinet6/in6_var.h> | |
46 | 46 | |||
47 | #include "npf_impl.h" | 47 | #include "npf_impl.h" | |
48 | 48 | |||
49 | static npf_table_t * | 49 | static npf_table_t * | |
50 | lookup_ifnet_table(npf_t *npf, ifnet_t *ifp) | 50 | lookup_ifnet_table(npf_t *npf, ifnet_t *ifp) | |
@@ -160,22 +160,22 @@ npf_ifaddr_flush(npf_t *npf, ifnet_t *if | @@ -160,22 +160,22 @@ npf_ifaddr_flush(npf_t *npf, ifnet_t *if | |||
160 | t = lookup_ifnet_table(npf, ifp); | 160 | t = lookup_ifnet_table(npf, ifp); | |
161 | if (!t) { | 161 | if (!t) { | |
162 | return; | 162 | return; | |
163 | } | 163 | } | |
164 | replace_ifnet_table(npf, t); | 164 | replace_ifnet_table(npf, t); | |
165 | } | 165 | } | |
166 | 166 | |||
167 | void | 167 | void | |
168 | npf_ifaddr_syncall(npf_t *npf) | 168 | npf_ifaddr_syncall(npf_t *npf) | |
169 | { | 169 | { | |
170 | ifnet_t *ifp; | 170 | ifnet_t *ifp; | |
171 | 171 | |||
172 | KERNEL_LOCK(1, NULL); | 172 | KERNEL_LOCK(1, NULL); | |
173 | IFNET_LOCK(); | 173 | IFNET_GLOBAL_LOCK(); | |
174 | IFNET_WRITER_FOREACH(ifp) { | 174 | IFNET_WRITER_FOREACH(ifp) { | |
175 | npf_ifaddr_sync(npf, ifp); | 175 | npf_ifaddr_sync(npf, ifp); | |
176 | } | 176 | } | |
177 | IFNET_UNLOCK(); | 177 | IFNET_GLOBAL_UNLOCK(); | |
178 | KERNEL_UNLOCK_ONE(NULL); | 178 | KERNEL_UNLOCK_ONE(NULL); | |
179 | } | 179 | } | |
180 | 180 | |||
181 | 181 |
--- src/sys/net/npf/npf_os.c 2017/07/25 02:17:16 1.6.8.1
+++ src/sys/net/npf/npf_os.c 2018/01/02 10:20:33 1.6.8.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: npf_os.c,v 1.6.8.1 2017/07/25 02:17:16 snj Exp $ */ | 1 | /* $NetBSD: npf_os.c,v 1.6.8.2 2018/01/02 10:20:33 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2009-2016 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2009-2016 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This material is based upon work partially supported by The | 7 | * This material is based upon work partially supported by The | |
8 | * NetBSD Foundation under a contract with Mindaugas Rasiukevicius. | 8 | * NetBSD Foundation under a contract with Mindaugas Rasiukevicius. | |
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. | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | /* | 32 | /* | |
33 | * NPF main: dynamic load/initialisation and unload routines. | 33 | * NPF main: dynamic load/initialisation and unload routines. | |
34 | */ | 34 | */ | |
35 | 35 | |||
36 | #ifdef _KERNEL | 36 | #ifdef _KERNEL | |
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | __KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.6.8.1 2017/07/25 02:17:16 snj Exp $"); | 38 | __KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.6.8.2 2018/01/02 10:20:33 snj Exp $"); | |
39 | 39 | |||
40 | #ifdef _KERNEL_OPT | 40 | #ifdef _KERNEL_OPT | |
41 | #include "pf.h" | 41 | #include "pf.h" | |
42 | #if NPF > 0 | 42 | #if NPF > 0 | |
43 | #error "NPF and PF are mutually exclusive; please select one" | 43 | #error "NPF and PF are mutually exclusive; please select one" | |
44 | #endif | 44 | #endif | |
45 | #endif | 45 | #endif | |
46 | 46 | |||
47 | #include <sys/param.h> | 47 | #include <sys/param.h> | |
48 | #include <sys/types.h> | 48 | #include <sys/types.h> | |
49 | 49 | |||
50 | #include <sys/conf.h> | 50 | #include <sys/conf.h> | |
51 | #include <sys/kauth.h> | 51 | #include <sys/kauth.h> | |
@@ -303,31 +303,31 @@ npf_ifop_getname(ifnet_t *ifp) | @@ -303,31 +303,31 @@ npf_ifop_getname(ifnet_t *ifp) | |||
303 | 303 | |||
304 | static ifnet_t * | 304 | static ifnet_t * | |
305 | npf_ifop_lookup(const char *name) | 305 | npf_ifop_lookup(const char *name) | |
306 | { | 306 | { | |
307 | return ifunit(name); | 307 | return ifunit(name); | |
308 | } | 308 | } | |
309 | 309 | |||
310 | static void | 310 | static void | |
311 | npf_ifop_flush(void *arg) | 311 | npf_ifop_flush(void *arg) | |
312 | { | 312 | { | |
313 | ifnet_t *ifp; | 313 | ifnet_t *ifp; | |
314 | 314 | |||
315 | KERNEL_LOCK(1, NULL); | 315 | KERNEL_LOCK(1, NULL); | |
316 | IFNET_LOCK(); | 316 | IFNET_GLOBAL_LOCK(); | |
317 | IFNET_WRITER_FOREACH(ifp) { | 317 | IFNET_WRITER_FOREACH(ifp) { | |
318 | ifp->if_pf_kif = arg; | 318 | ifp->if_pf_kif = arg; | |
319 | } | 319 | } | |
320 | IFNET_UNLOCK(); | 320 | IFNET_GLOBAL_UNLOCK(); | |
321 | KERNEL_UNLOCK_ONE(NULL); | 321 | KERNEL_UNLOCK_ONE(NULL); | |
322 | } | 322 | } | |
323 | 323 | |||
324 | static void * | 324 | static void * | |
325 | npf_ifop_getmeta(const ifnet_t *ifp) | 325 | npf_ifop_getmeta(const ifnet_t *ifp) | |
326 | { | 326 | { | |
327 | return ifp->if_pf_kif; | 327 | return ifp->if_pf_kif; | |
328 | } | 328 | } | |
329 | 329 | |||
330 | static void | 330 | static void | |
331 | npf_ifop_setmeta(ifnet_t *ifp, void *arg) | 331 | npf_ifop_setmeta(ifnet_t *ifp, void *arg) | |
332 | { | 332 | { | |
333 | ifp->if_pf_kif = arg; | 333 | ifp->if_pf_kif = arg; | |
@@ -387,30 +387,27 @@ npf_ifaddrhook(void *arg, u_long cmd, vo | @@ -387,30 +387,27 @@ npf_ifaddrhook(void *arg, u_long cmd, vo | |||
387 | } | 387 | } | |
388 | npf_ifaddr_sync(npf, ifa->ifa_ifp); | 388 | npf_ifaddr_sync(npf, ifa->ifa_ifp); | |
389 | } | 389 | } | |
390 | 390 | |||
391 | /* | 391 | /* | |
392 | * npf_pfil_register: register pfil(9) hooks. | 392 | * npf_pfil_register: register pfil(9) hooks. | |
393 | */ | 393 | */ | |
394 | int | 394 | int | |
395 | npf_pfil_register(bool init) | 395 | npf_pfil_register(bool init) | |
396 | { | 396 | { | |
397 | npf_t *npf = npf_getkernctx(); | 397 | npf_t *npf = npf_getkernctx(); | |
398 | int error = 0; | 398 | int error = 0; | |
399 | 399 | |||
400 | #ifndef NET_MPSAFE | 400 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
401 | mutex_enter(softnet_lock); | |||
402 | KERNEL_LOCK(1, NULL); | |||
403 | #endif | |||
404 | 401 | |||
405 | /* Init: interface re-config and attach/detach hook. */ | 402 | /* Init: interface re-config and attach/detach hook. */ | |
406 | if (!npf_ph_if) { | 403 | if (!npf_ph_if) { | |
407 | npf_ph_if = pfil_head_get(PFIL_TYPE_IFNET, 0); | 404 | npf_ph_if = pfil_head_get(PFIL_TYPE_IFNET, 0); | |
408 | if (!npf_ph_if) { | 405 | if (!npf_ph_if) { | |
409 | error = ENOENT; | 406 | error = ENOENT; | |
410 | goto out; | 407 | goto out; | |
411 | } | 408 | } | |
412 | 409 | |||
413 | error = pfil_add_ihook(npf_ifhook, NULL, | 410 | error = pfil_add_ihook(npf_ifhook, NULL, | |
414 | PFIL_IFNET, npf_ph_if); | 411 | PFIL_IFNET, npf_ph_if); | |
415 | KASSERT(error == 0); | 412 | KASSERT(error == 0); | |
416 | 413 | |||
@@ -445,62 +442,53 @@ npf_pfil_register(bool init) | @@ -445,62 +442,53 @@ npf_pfil_register(bool init) | |||
445 | if (npf_ph_inet6) { | 442 | if (npf_ph_inet6) { | |
446 | error = pfil_add_hook(npfkern_packet_handler, npf, | 443 | error = pfil_add_hook(npfkern_packet_handler, npf, | |
447 | PFIL_ALL, npf_ph_inet6); | 444 | PFIL_ALL, npf_ph_inet6); | |
448 | KASSERT(error == 0); | 445 | KASSERT(error == 0); | |
449 | } | 446 | } | |
450 | 447 | |||
451 | /* | 448 | /* | |
452 | * It is necessary to re-sync all/any interface address tables, | 449 | * It is necessary to re-sync all/any interface address tables, | |
453 | * since we did not listen for any changes. | 450 | * since we did not listen for any changes. | |
454 | */ | 451 | */ | |
455 | npf_ifaddr_syncall(npf); | 452 | npf_ifaddr_syncall(npf); | |
456 | pfil_registered = true; | 453 | pfil_registered = true; | |
457 | out: | 454 | out: | |
458 | #ifndef NET_MPSAFE | 455 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
459 | KERNEL_UNLOCK_ONE(NULL); | |||
460 | mutex_exit(softnet_lock); | |||
461 | #endif | |||
462 | 456 | |||
463 | return error; | 457 | return error; | |
464 | } | 458 | } | |
465 | 459 | |||
466 | /* | 460 | /* | |
467 | * npf_pfil_unregister: unregister pfil(9) hooks. | 461 | * npf_pfil_unregister: unregister pfil(9) hooks. | |
468 | */ | 462 | */ | |
469 | void | 463 | void | |
470 | npf_pfil_unregister(bool fini) | 464 | npf_pfil_unregister(bool fini) | |
471 | { | 465 | { | |
472 | npf_t *npf = npf_getkernctx(); | 466 | npf_t *npf = npf_getkernctx(); | |
473 | 467 | |||
474 | #ifndef NET_MPSAFE | 468 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
475 | mutex_enter(softnet_lock); | |||
476 | KERNEL_LOCK(1, NULL); | |||
477 | #endif | |||
478 | 469 | |||
479 | if (fini && npf_ph_if) { | 470 | if (fini && npf_ph_if) { | |
480 | (void)pfil_remove_ihook(npf_ifhook, NULL, | 471 | (void)pfil_remove_ihook(npf_ifhook, NULL, | |
481 | PFIL_IFNET, npf_ph_if); | 472 | PFIL_IFNET, npf_ph_if); | |
482 | (void)pfil_remove_ihook(npf_ifaddrhook, NULL, | 473 | (void)pfil_remove_ihook(npf_ifaddrhook, NULL, | |
483 | PFIL_IFADDR, npf_ph_if); | 474 | PFIL_IFADDR, npf_ph_if); | |
484 | } | 475 | } | |
485 | if (npf_ph_inet) { | 476 | if (npf_ph_inet) { | |
486 | (void)pfil_remove_hook(npfkern_packet_handler, npf, | 477 | (void)pfil_remove_hook(npfkern_packet_handler, npf, | |
487 | PFIL_ALL, npf_ph_inet); | 478 | PFIL_ALL, npf_ph_inet); | |
488 | } | 479 | } | |
489 | if (npf_ph_inet6) { | 480 | if (npf_ph_inet6) { | |
490 | (void)pfil_remove_hook(npfkern_packet_handler, npf, | 481 | (void)pfil_remove_hook(npfkern_packet_handler, npf, | |
491 | PFIL_ALL, npf_ph_inet6); | 482 | PFIL_ALL, npf_ph_inet6); | |
492 | } | 483 | } | |
493 | pfil_registered = false; | 484 | pfil_registered = false; | |
494 | 485 | |||
495 | #ifndef NET_MPSAFE | 486 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
496 | KERNEL_UNLOCK_ONE(NULL); | |||
497 | mutex_exit(softnet_lock); | |||
498 | #endif | |||
499 | } | 487 | } | |
500 | 488 | |||
501 | bool | 489 | bool | |
502 | npf_pfil_registered_p(void) | 490 | npf_pfil_registered_p(void) | |
503 | { | 491 | { | |
504 | return pfil_registered; | 492 | return pfil_registered; | |
505 | } | 493 | } | |
506 | #endif | 494 | #endif |
--- src/sys/netcan/if_canloop.c 2017/05/27 21:02:56 1.2
+++ src/sys/netcan/if_canloop.c 2018/01/02 10:20:34 1.2.2.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_canloop.c,v 1.2 2017/05/27 21:02:56 bouyer Exp $ */ | 1 | /* $NetBSD: if_canloop.c,v 1.2.2.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2017 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2017 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 Manuel Bouyer. | 8 | * by Manuel Bouyer. | |
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. | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | 32 | |||
33 | /* | 33 | /* | |
34 | * Loopback interface driver for the CAN protocol | 34 | * Loopback interface driver for the CAN protocol | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | __KERNEL_RCSID(0, "$NetBSD: if_canloop.c,v 1.2 2017/05/27 21:02:56 bouyer Exp $"); | 38 | __KERNEL_RCSID(0, "$NetBSD: if_canloop.c,v 1.2.2.1 2018/01/02 10:20:34 snj Exp $"); | |
39 | 39 | |||
40 | #ifdef _KERNEL_OPT | 40 | #ifdef _KERNEL_OPT | |
41 | #include "opt_can.h" | 41 | #include "opt_can.h" | |
42 | #include "opt_net_mpsafe.h" | 42 | #include "opt_net_mpsafe.h" | |
43 | #endif | 43 | #endif | |
44 | 44 | |||
45 | #include <sys/param.h> | 45 | #include <sys/param.h> | |
46 | #include <sys/systm.h> | 46 | #include <sys/systm.h> | |
47 | #include <sys/kernel.h> | 47 | #include <sys/kernel.h> | |
48 | #include <sys/mbuf.h> | 48 | #include <sys/mbuf.h> | |
49 | #include <sys/socket.h> | 49 | #include <sys/socket.h> | |
50 | #include <sys/errno.h> | 50 | #include <sys/errno.h> | |
51 | #include <sys/ioctl.h> | 51 | #include <sys/ioctl.h> | |
@@ -101,47 +101,52 @@ canloopdetach(void) | @@ -101,47 +101,52 @@ canloopdetach(void) | |||
101 | if_clone_detach(&canloop_cloner); | 101 | if_clone_detach(&canloop_cloner); | |
102 | return 0; | 102 | return 0; | |
103 | } | 103 | } | |
104 | 104 | |||
105 | static int | 105 | static int | |
106 | canloop_clone_create(struct if_clone *ifc, int unit) | 106 | canloop_clone_create(struct if_clone *ifc, int unit) | |
107 | { | 107 | { | |
108 | struct ifnet *ifp; | 108 | struct ifnet *ifp; | |
109 | 109 | |||
110 | ifp = if_alloc(IFT_OTHER); | 110 | ifp = if_alloc(IFT_OTHER); | |
111 | 111 | |||
112 | if_initname(ifp, ifc->ifc_name, unit); | 112 | if_initname(ifp, ifc->ifc_name, unit); | |
113 | 113 | |||
114 | ifp->if_flags = IFF_LOOPBACK | IFF_RUNNING; | 114 | ifp->if_flags = IFF_LOOPBACK; | |
115 | ifp->if_extflags = IFEF_OUTPUT_MPSAFE; | 115 | #ifdef NET_MPSAFE | |
116 | ifp->if_extflags = IFEF_MPSAFE; | |||
117 | #endif | |||
116 | ifp->if_ioctl = canloop_ioctl; | 118 | ifp->if_ioctl = canloop_ioctl; | |
117 | ifp->if_start = canloop_ifstart; | 119 | ifp->if_start = canloop_ifstart; | |
118 | can_ifattach(ifp); | 120 | can_ifattach(ifp); | |
119 | #ifdef MBUFTRACE | 121 | #ifdef MBUFTRACE | |
120 | ifp->if_mowner = malloc(sizeof(struct mowner), M_DEVBUF, | 122 | ifp->if_mowner = malloc(sizeof(struct mowner), M_DEVBUF, | |
121 | M_WAITOK | M_ZERO); | 123 | M_WAITOK | M_ZERO); | |
122 | strlcpy(ifp->if_mowner->mo_name, ifp->if_xname, | 124 | strlcpy(ifp->if_mowner->mo_name, ifp->if_xname, | |
123 | sizeof(ifp->if_mowner->mo_name)); | 125 | sizeof(ifp->if_mowner->mo_name)); | |
124 | MOWNER_ATTACH(ifp->if_mowner); | 126 | MOWNER_ATTACH(ifp->if_mowner); | |
125 | #endif | 127 | #endif | |
126 | canloop_count++; | 128 | canloop_count++; | |
129 | ifp->if_flags |= IFF_RUNNING; | |||
127 | 130 | |||
128 | return (0); | 131 | return (0); | |
129 | } | 132 | } | |
130 | 133 | |||
131 | static int | 134 | static int | |
132 | canloop_clone_destroy(struct ifnet *ifp) | 135 | canloop_clone_destroy(struct ifnet *ifp) | |
133 | { | 136 | { | |
134 | 137 | |||
138 | ifp->if_flags &= ~IFF_RUNNING; | |||
139 | ||||
135 | #ifdef MBUFTRACE | 140 | #ifdef MBUFTRACE | |
136 | MOWNER_DETACH(ifp->if_mowner); | 141 | MOWNER_DETACH(ifp->if_mowner); | |
137 | free(ifp->if_mowner, M_DEVBUF); | 142 | free(ifp->if_mowner, M_DEVBUF); | |
138 | #endif | 143 | #endif | |
139 | 144 | |||
140 | can_ifdetach(ifp); | 145 | can_ifdetach(ifp); | |
141 | 146 | |||
142 | if_free(ifp); | 147 | if_free(ifp); | |
143 | canloop_count--; | 148 | canloop_count--; | |
144 | KASSERT(canloop_count >= 0); | 149 | KASSERT(canloop_count >= 0); | |
145 | return (0); | 150 | return (0); | |
146 | } | 151 | } | |
147 | 152 |
--- src/sys/netinet/if_arp.c 2017/11/17 20:24:05 1.250.2.3
+++ src/sys/netinet/if_arp.c 2018/01/02 10:20:34 1.250.2.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_arp.c,v 1.250.2.3 2017/11/17 20:24:05 snj Exp $ */ | 1 | /* $NetBSD: if_arp.c,v 1.250.2.4 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998, 2000, 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 Public Access Networks Corporation ("Panix"). It was developed under | 8 | * by Public Access Networks Corporation ("Panix"). It was developed under | |
9 | * contract to Panix by Eric Haszlakiewicz and Thor Lancelot Simon. | 9 | * contract to Panix by Eric Haszlakiewicz and Thor Lancelot Simon. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -58,27 +58,27 @@ | @@ -58,27 +58,27 @@ | |||
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | 59 | * SUCH DAMAGE. | |
60 | * | 60 | * | |
61 | * @(#)if_ether.c 8.2 (Berkeley) 9/26/94 | 61 | * @(#)if_ether.c 8.2 (Berkeley) 9/26/94 | |
62 | */ | 62 | */ | |
63 | 63 | |||
64 | /* | 64 | /* | |
65 | * Ethernet address resolution protocol. | 65 | * Ethernet address resolution protocol. | |
66 | * TODO: | 66 | * TODO: | |
67 | * add "inuse/lock" bit (or ref. count) along with valid bit | 67 | * add "inuse/lock" bit (or ref. count) along with valid bit | |
68 | */ | 68 | */ | |
69 | 69 | |||
70 | #include <sys/cdefs.h> | 70 | #include <sys/cdefs.h> | |
71 | __KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.250.2.3 2017/11/17 20:24:05 snj Exp $"); | 71 | __KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.250.2.4 2018/01/02 10:20:34 snj Exp $"); | |
72 | 72 | |||
73 | #ifdef _KERNEL_OPT | 73 | #ifdef _KERNEL_OPT | |
74 | #include "opt_ddb.h" | 74 | #include "opt_ddb.h" | |
75 | #include "opt_inet.h" | 75 | #include "opt_inet.h" | |
76 | #include "opt_net_mpsafe.h" | 76 | #include "opt_net_mpsafe.h" | |
77 | #endif | 77 | #endif | |
78 | 78 | |||
79 | #ifdef INET | 79 | #ifdef INET | |
80 | 80 | |||
81 | #include "arp.h" | 81 | #include "arp.h" | |
82 | #include "bridge.h" | 82 | #include "bridge.h" | |
83 | 83 | |||
84 | #include <sys/param.h> | 84 | #include <sys/param.h> | |
@@ -910,30 +910,27 @@ bad: | @@ -910,30 +910,27 @@ bad: | |||
910 | 910 | |||
911 | /* | 911 | /* | |
912 | * Common length and type checks are done here, | 912 | * Common length and type checks are done here, | |
913 | * then the protocol-specific routine is called. | 913 | * then the protocol-specific routine is called. | |
914 | */ | 914 | */ | |
915 | void | 915 | void | |
916 | arpintr(void) | 916 | arpintr(void) | |
917 | { | 917 | { | |
918 | struct mbuf *m; | 918 | struct mbuf *m; | |
919 | struct arphdr *ar; | 919 | struct arphdr *ar; | |
920 | int s; | 920 | int s; | |
921 | int arplen; | 921 | int arplen; | |
922 | 922 | |||
923 | #ifndef NET_MPSAFE | 923 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
924 | mutex_enter(softnet_lock); | |||
925 | KERNEL_LOCK(1, NULL); | |||
926 | #endif | |||
927 | for (;;) { | 924 | for (;;) { | |
928 | struct ifnet *rcvif; | 925 | struct ifnet *rcvif; | |
929 | 926 | |||
930 | IFQ_LOCK(&arpintrq); | 927 | IFQ_LOCK(&arpintrq); | |
931 | IF_DEQUEUE(&arpintrq, m); | 928 | IF_DEQUEUE(&arpintrq, m); | |
932 | IFQ_UNLOCK(&arpintrq); | 929 | IFQ_UNLOCK(&arpintrq); | |
933 | if (m == NULL) | 930 | if (m == NULL) | |
934 | goto out; | 931 | goto out; | |
935 | if ((m->m_flags & M_PKTHDR) == 0) | 932 | if ((m->m_flags & M_PKTHDR) == 0) | |
936 | panic("arpintr"); | 933 | panic("arpintr"); | |
937 | 934 | |||
938 | MCLAIM(m, &arpdomain.dom_mowner); | 935 | MCLAIM(m, &arpdomain.dom_mowner); | |
939 | ARP_STATINC(ARP_STAT_RCVTOTAL); | 936 | ARP_STATINC(ARP_STAT_RCVTOTAL); | |
@@ -970,32 +967,28 @@ arpintr(void) | @@ -970,32 +967,28 @@ arpintr(void) | |||
970 | in_arpinput(m); | 967 | in_arpinput(m); | |
971 | continue; | 968 | continue; | |
972 | default: | 969 | default: | |
973 | ARP_STATINC(ARP_STAT_RCVBADPROTO); | 970 | ARP_STATINC(ARP_STAT_RCVBADPROTO); | |
974 | } | 971 | } | |
975 | else { | 972 | else { | |
976 | badlen: | 973 | badlen: | |
977 | ARP_STATINC(ARP_STAT_RCVBADLEN); | 974 | ARP_STATINC(ARP_STAT_RCVBADLEN); | |
978 | } | 975 | } | |
979 | free: | 976 | free: | |
980 | m_freem(m); | 977 | m_freem(m); | |
981 | } | 978 | } | |
982 | out: | 979 | out: | |
983 | #ifndef NET_MPSAFE | 980 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
984 | KERNEL_UNLOCK_ONE(NULL); | |||
985 | mutex_exit(softnet_lock); | |||
986 | #else | |||
987 | return; /* XXX gcc */ | 981 | return; /* XXX gcc */ | |
988 | #endif | |||
989 | } | 982 | } | |
990 | 983 | |||
991 | /* | 984 | /* | |
992 | * ARP for Internet protocols on 10 Mb/s Ethernet. Algorithm is that given in | 985 | * ARP for Internet protocols on 10 Mb/s Ethernet. Algorithm is that given in | |
993 | * RFC 826. In addition, a sanity check is performed on the sender protocol | 986 | * RFC 826. In addition, a sanity check is performed on the sender protocol | |
994 | * address, to catch impersonators. | 987 | * address, to catch impersonators. | |
995 | * | 988 | * | |
996 | * We no longer handle negotiations for use of trailer protocol: formerly, ARP | 989 | * We no longer handle negotiations for use of trailer protocol: formerly, ARP | |
997 | * replied for protocol type ETHERTYPE_TRAIL sent along with IP replies if we | 990 | * replied for protocol type ETHERTYPE_TRAIL sent along with IP replies if we | |
998 | * wanted trailers sent to us, and also sent them in response to IP replies. | 991 | * wanted trailers sent to us, and also sent them in response to IP replies. | |
999 | * This allowed either end to announce the desire to receive trailer packets. | 992 | * This allowed either end to announce the desire to receive trailer packets. | |
1000 | * | 993 | * | |
1001 | * We no longer reply to requests for ETHERTYPE_TRAIL protocol either, but | 994 | * We no longer reply to requests for ETHERTYPE_TRAIL protocol either, but | |
@@ -1679,30 +1672,27 @@ arp_dad_stop(struct ifaddr *ifa) | @@ -1679,30 +1672,27 @@ arp_dad_stop(struct ifaddr *ifa) | |||
1679 | 1672 | |||
1680 | kmem_intr_free(dp, sizeof(*dp)); | 1673 | kmem_intr_free(dp, sizeof(*dp)); | |
1681 | ifafree(ifa); | 1674 | ifafree(ifa); | |
1682 | } | 1675 | } | |
1683 | 1676 | |||
1684 | static void | 1677 | static void | |
1685 | arp_dad_timer(struct ifaddr *ifa) | 1678 | arp_dad_timer(struct ifaddr *ifa) | |
1686 | { | 1679 | { | |
1687 | struct in_ifaddr *ia = (struct in_ifaddr *)ifa; | 1680 | struct in_ifaddr *ia = (struct in_ifaddr *)ifa; | |
1688 | struct dadq *dp; | 1681 | struct dadq *dp; | |
1689 | char ipbuf[INET_ADDRSTRLEN]; | 1682 | char ipbuf[INET_ADDRSTRLEN]; | |
1690 | bool need_free = false; | 1683 | bool need_free = false; | |
1691 | 1684 | |||
1692 | #ifndef NET_MPSAFE | 1685 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
1693 | mutex_enter(softnet_lock); | |||
1694 | KERNEL_LOCK(1, NULL); | |||
1695 | #endif | |||
1696 | mutex_enter(&arp_dad_lock); | 1686 | mutex_enter(&arp_dad_lock); | |
1697 | 1687 | |||
1698 | /* Sanity check */ | 1688 | /* Sanity check */ | |
1699 | if (ia == NULL) { | 1689 | if (ia == NULL) { | |
1700 | log(LOG_ERR, "%s: called with null parameter\n", __func__); | 1690 | log(LOG_ERR, "%s: called with null parameter\n", __func__); | |
1701 | goto done; | 1691 | goto done; | |
1702 | } | 1692 | } | |
1703 | dp = arp_dad_find(ifa); | 1693 | dp = arp_dad_find(ifa); | |
1704 | if (dp == NULL) { | 1694 | if (dp == NULL) { | |
1705 | /* DAD seems to be stopping, so do nothing. */ | 1695 | /* DAD seems to be stopping, so do nothing. */ | |
1706 | goto done; | 1696 | goto done; | |
1707 | } | 1697 | } | |
1708 | if (ia->ia4_flags & IN_IFF_DUPLICATED) { | 1698 | if (ia->ia4_flags & IN_IFF_DUPLICATED) { | |
@@ -1773,30 +1763,27 @@ announce: | @@ -1773,30 +1763,27 @@ announce: | |||
1773 | if_name(ifa->ifa_ifp), ARPLOGADDR(&ia->ia_addr.sin_addr)); | 1763 | if_name(ifa->ifa_ifp), ARPLOGADDR(&ia->ia_addr.sin_addr)); | |
1774 | } | 1764 | } | |
1775 | 1765 | |||
1776 | TAILQ_REMOVE(&dadq, dp, dad_list); | 1766 | TAILQ_REMOVE(&dadq, dp, dad_list); | |
1777 | need_free = true; | 1767 | need_free = true; | |
1778 | done: | 1768 | done: | |
1779 | mutex_exit(&arp_dad_lock); | 1769 | mutex_exit(&arp_dad_lock); | |
1780 | 1770 | |||
1781 | if (need_free) { | 1771 | if (need_free) { | |
1782 | kmem_intr_free(dp, sizeof(*dp)); | 1772 | kmem_intr_free(dp, sizeof(*dp)); | |
1783 | ifafree(ifa); | 1773 | ifafree(ifa); | |
1784 | } | 1774 | } | |
1785 | 1775 | |||
1786 | #ifndef NET_MPSAFE | 1776 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
1787 | KERNEL_UNLOCK_ONE(NULL); | |||
1788 | mutex_exit(softnet_lock); | |||
1789 | #endif | |||
1790 | } | 1777 | } | |
1791 | 1778 | |||
1792 | static void | 1779 | static void | |
1793 | arp_dad_duplicated(struct ifaddr *ifa, const char *sha) | 1780 | arp_dad_duplicated(struct ifaddr *ifa, const char *sha) | |
1794 | { | 1781 | { | |
1795 | struct in_ifaddr *ia = (struct in_ifaddr *)ifa; | 1782 | struct in_ifaddr *ia = (struct in_ifaddr *)ifa; | |
1796 | struct ifnet *ifp = ifa->ifa_ifp; | 1783 | struct ifnet *ifp = ifa->ifa_ifp; | |
1797 | char ipbuf[INET_ADDRSTRLEN]; | 1784 | char ipbuf[INET_ADDRSTRLEN]; | |
1798 | const char *iastr; | 1785 | const char *iastr; | |
1799 | 1786 | |||
1800 | iastr = IN_PRINT(ipbuf, &ia->ia_addr.sin_addr); | 1787 | iastr = IN_PRINT(ipbuf, &ia->ia_addr.sin_addr); | |
1801 | 1788 | |||
1802 | if (ia->ia4_flags & (IN_IFF_TENTATIVE|IN_IFF_DUPLICATED)) { | 1789 | if (ia->ia4_flags & (IN_IFF_TENTATIVE|IN_IFF_DUPLICATED)) { |
--- src/sys/netinet/igmp.c 2017/01/24 07:09:24 1.64
+++ src/sys/netinet/igmp.c 2018/01/02 10:20:34 1.64.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: igmp.c,v 1.64 2017/01/24 07:09:24 ozaki-r Exp $ */ | 1 | /* $NetBSD: igmp.c,v 1.64.6.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
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. | |
@@ -30,27 +30,27 @@ | @@ -30,27 +30,27 @@ | |||
30 | */ | 30 | */ | |
31 | 31 | |||
32 | /* | 32 | /* | |
33 | * Internet Group Management Protocol (IGMP) routines. | 33 | * Internet Group Management Protocol (IGMP) routines. | |
34 | * | 34 | * | |
35 | * Written by Steve Deering, Stanford, May 1988. | 35 | * Written by Steve Deering, Stanford, May 1988. | |
36 | * Modified by Rosen Sharma, Stanford, Aug 1994. | 36 | * Modified by Rosen Sharma, Stanford, Aug 1994. | |
37 | * Modified by Bill Fenner, Xerox PARC, Feb 1995. | 37 | * Modified by Bill Fenner, Xerox PARC, Feb 1995. | |
38 | * | 38 | * | |
39 | * MULTICAST Revision: 1.3 | 39 | * MULTICAST Revision: 1.3 | |
40 | */ | 40 | */ | |
41 | 41 | |||
42 | #include <sys/cdefs.h> | 42 | #include <sys/cdefs.h> | |
43 | __KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.64 2017/01/24 07:09:24 ozaki-r Exp $"); | 43 | __KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.64.6.1 2018/01/02 10:20:34 snj Exp $"); | |
44 | 44 | |||
45 | #ifdef _KERNEL_OPT | 45 | #ifdef _KERNEL_OPT | |
46 | #include "opt_mrouting.h" | 46 | #include "opt_mrouting.h" | |
47 | #include "opt_net_mpsafe.h" | 47 | #include "opt_net_mpsafe.h" | |
48 | #endif | 48 | #endif | |
49 | 49 | |||
50 | #include <sys/param.h> | 50 | #include <sys/param.h> | |
51 | #include <sys/mbuf.h> | 51 | #include <sys/mbuf.h> | |
52 | #include <sys/socket.h> | 52 | #include <sys/socket.h> | |
53 | #include <sys/socketvar.h> | 53 | #include <sys/socketvar.h> | |
54 | #include <sys/systm.h> | 54 | #include <sys/systm.h> | |
55 | #include <sys/cprng.h> | 55 | #include <sys/cprng.h> | |
56 | #include <sys/sysctl.h> | 56 | #include <sys/sysctl.h> | |
@@ -532,56 +532,52 @@ void | @@ -532,56 +532,52 @@ void | |||
532 | igmp_fasttimo(void) | 532 | igmp_fasttimo(void) | |
533 | { | 533 | { | |
534 | struct in_multi *inm; | 534 | struct in_multi *inm; | |
535 | struct in_multistep step; | 535 | struct in_multistep step; | |
536 | 536 | |||
537 | /* | 537 | /* | |
538 | * Quick check to see if any work needs to be done, in order | 538 | * Quick check to see if any work needs to be done, in order | |
539 | * to minimize the overhead of fasttimo processing. | 539 | * to minimize the overhead of fasttimo processing. | |
540 | */ | 540 | */ | |
541 | if (!igmp_timers_on) { | 541 | if (!igmp_timers_on) { | |
542 | return; | 542 | return; | |
543 | } | 543 | } | |
544 | 544 | |||
545 | #ifndef NET_MPSAFE | |||
546 | /* XXX: Needed for ip_output(). */ | 545 | /* XXX: Needed for ip_output(). */ | |
547 | mutex_enter(softnet_lock); | 546 | SOFTNET_LOCK_UNLESS_NET_MPSAFE(); | |
548 | #endif | |||
549 | 547 | |||
550 | in_multi_lock(RW_WRITER); | 548 | in_multi_lock(RW_WRITER); | |
551 | igmp_timers_on = false; | 549 | igmp_timers_on = false; | |
552 | inm = in_first_multi(&step); | 550 | inm = in_first_multi(&step); | |
553 | while (inm != NULL) { | 551 | while (inm != NULL) { | |
554 | if (inm->inm_timer == 0) { | 552 | if (inm->inm_timer == 0) { | |
555 | /* do nothing */ | 553 | /* do nothing */ | |
556 | } else if (--inm->inm_timer == 0) { | 554 | } else if (--inm->inm_timer == 0) { | |
557 | if (inm->inm_state == IGMP_DELAYING_MEMBER) { | 555 | if (inm->inm_state == IGMP_DELAYING_MEMBER) { | |
558 | if (inm->inm_rti->rti_type == IGMP_v1_ROUTER) | 556 | if (inm->inm_rti->rti_type == IGMP_v1_ROUTER) | |
559 | igmp_sendpkt(inm, | 557 | igmp_sendpkt(inm, | |
560 | IGMP_v1_HOST_MEMBERSHIP_REPORT); | 558 | IGMP_v1_HOST_MEMBERSHIP_REPORT); | |
561 | else | 559 | else | |
562 | igmp_sendpkt(inm, | 560 | igmp_sendpkt(inm, | |
563 | IGMP_v2_HOST_MEMBERSHIP_REPORT); | 561 | IGMP_v2_HOST_MEMBERSHIP_REPORT); | |
564 | inm->inm_state = IGMP_IDLE_MEMBER; | 562 | inm->inm_state = IGMP_IDLE_MEMBER; | |
565 | } | 563 | } | |
566 | } else { | 564 | } else { | |
567 | igmp_timers_on = true; | 565 | igmp_timers_on = true; | |
568 | } | 566 | } | |
569 | inm = in_next_multi(&step); | 567 | inm = in_next_multi(&step); | |
570 | } | 568 | } | |
571 | in_multi_unlock(); | 569 | in_multi_unlock(); | |
572 | #ifndef NET_MPSAFE | 570 | SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); | |
573 | mutex_exit(softnet_lock); | |||
574 | #endif | |||
575 | } | 571 | } | |
576 | 572 | |||
577 | void | 573 | void | |
578 | igmp_slowtimo(void) | 574 | igmp_slowtimo(void) | |
579 | { | 575 | { | |
580 | router_info_t *rti; | 576 | router_info_t *rti; | |
581 | 577 | |||
582 | in_multi_lock(RW_WRITER); | 578 | in_multi_lock(RW_WRITER); | |
583 | LIST_FOREACH(rti, &rti_head, rti_link) { | 579 | LIST_FOREACH(rti, &rti_head, rti_link) { | |
584 | if (rti->rti_type == IGMP_v1_ROUTER && | 580 | if (rti->rti_type == IGMP_v1_ROUTER && | |
585 | ++rti->rti_age >= IGMP_AGE_THRESHOLD) { | 581 | ++rti->rti_age >= IGMP_AGE_THRESHOLD) { | |
586 | rti->rti_type = IGMP_v2_ROUTER; | 582 | rti->rti_type = IGMP_v2_ROUTER; | |
587 | } | 583 | } |
--- src/sys/netinet/in.c 2017/12/21 21:08:13 1.203.2.3
+++ src/sys/netinet/in.c 2018/01/02 10:20:34 1.203.2.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: in.c,v 1.203.2.3 2017/12/21 21:08:13 snj Exp $ */ | 1 | /* $NetBSD: in.c,v 1.203.2.4 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
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. | |
@@ -81,27 +81,27 @@ | @@ -81,27 +81,27 @@ | |||
81 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 81 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
82 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 82 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
83 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 83 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
84 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 84 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
85 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 85 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
86 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 86 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
87 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 87 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
88 | * SUCH DAMAGE. | 88 | * SUCH DAMAGE. | |
89 | * | 89 | * | |
90 | * @(#)in.c 8.4 (Berkeley) 1/9/95 | 90 | * @(#)in.c 8.4 (Berkeley) 1/9/95 | |
91 | */ | 91 | */ | |
92 | 92 | |||
93 | #include <sys/cdefs.h> | 93 | #include <sys/cdefs.h> | |
94 | __KERNEL_RCSID(0, "$NetBSD: in.c,v 1.203.2.3 2017/12/21 21:08:13 snj Exp $"); | 94 | __KERNEL_RCSID(0, "$NetBSD: in.c,v 1.203.2.4 2018/01/02 10:20:34 snj Exp $"); | |
95 | 95 | |||
96 | #include "arp.h" | 96 | #include "arp.h" | |
97 | 97 | |||
98 | #ifdef _KERNEL_OPT | 98 | #ifdef _KERNEL_OPT | |
99 | #include "opt_inet.h" | 99 | #include "opt_inet.h" | |
100 | #include "opt_inet_conf.h" | 100 | #include "opt_inet_conf.h" | |
101 | #include "opt_mrouting.h" | 101 | #include "opt_mrouting.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/ioctl.h> | 106 | #include <sys/ioctl.h> | |
107 | #include <sys/errno.h> | 107 | #include <sys/errno.h> | |
@@ -741,33 +741,29 @@ in_control0(struct socket *so, u_long cm | @@ -741,33 +741,29 @@ in_control0(struct socket *so, u_long cm | |||
741 | 741 | |||
742 | out: | 742 | out: | |
743 | if (!newifaddr && ia != NULL) | 743 | if (!newifaddr && ia != NULL) | |
744 | ia4_release(ia, &psref); | 744 | ia4_release(ia, &psref); | |
745 | curlwp_bindx(bound); | 745 | curlwp_bindx(bound); | |
746 | return error; | 746 | return error; | |
747 | } | 747 | } | |
748 | 748 | |||
749 | int | 749 | int | |
750 | in_control(struct socket *so, u_long cmd, void *data, struct ifnet *ifp) | 750 | in_control(struct socket *so, u_long cmd, void *data, struct ifnet *ifp) | |
751 | { | 751 | { | |
752 | int error; | 752 | int error; | |
753 | 753 | |||
754 | #ifndef NET_MPSAFE | 754 | SOFTNET_LOCK_UNLESS_NET_MPSAFE(); | |
755 | mutex_enter(softnet_lock); | |||
756 | #endif | |||
757 | error = in_control0(so, cmd, data, ifp); | 755 | error = in_control0(so, cmd, data, ifp); | |
758 | #ifndef NET_MPSAFE | 756 | SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); | |
759 | mutex_exit(softnet_lock); | |||
760 | #endif | |||
761 | 757 | |||
762 | return error; | 758 | return error; | |
763 | } | 759 | } | |
764 | 760 | |||
765 | /* Add ownaddr as loopback rtentry. */ | 761 | /* Add ownaddr as loopback rtentry. */ | |
766 | static void | 762 | static void | |
767 | in_ifaddlocal(struct ifaddr *ifa) | 763 | in_ifaddlocal(struct ifaddr *ifa) | |
768 | { | 764 | { | |
769 | struct in_ifaddr *ia; | 765 | struct in_ifaddr *ia; | |
770 | 766 | |||
771 | ia = (struct in_ifaddr *)ifa; | 767 | ia = (struct in_ifaddr *)ifa; | |
772 | if (ia->ia_addr.sin_addr.s_addr == INADDR_ANY || | 768 | if (ia->ia_addr.sin_addr.s_addr == INADDR_ANY || | |
773 | (ia->ia_ifp->if_flags & IFF_POINTOPOINT && | 769 | (ia->ia_ifp->if_flags & IFF_POINTOPOINT && | |
@@ -906,31 +902,34 @@ in_addrhash_remove(struct in_ifaddr *ia) | @@ -906,31 +902,34 @@ in_addrhash_remove(struct in_ifaddr *ia) | |||
906 | 902 | |||
907 | mutex_enter(&in_ifaddr_lock); | 903 | mutex_enter(&in_ifaddr_lock); | |
908 | in_addrhash_remove_locked(ia); | 904 | in_addrhash_remove_locked(ia); | |
909 | #ifdef NET_MPSAFE | 905 | #ifdef NET_MPSAFE | |
910 | pserialize_perform(in_ifaddrhash_psz); | 906 | pserialize_perform(in_ifaddrhash_psz); | |
911 | #endif | 907 | #endif | |
912 | mutex_exit(&in_ifaddr_lock); | 908 | mutex_exit(&in_ifaddr_lock); | |
913 | IN_ADDRHASH_ENTRY_DESTROY(ia); | 909 | IN_ADDRHASH_ENTRY_DESTROY(ia); | |
914 | } | 910 | } | |
915 | 911 | |||
916 | void | 912 | void | |
917 | in_purgeif(struct ifnet *ifp) /* MUST be called at splsoftnet() */ | 913 | in_purgeif(struct ifnet *ifp) /* MUST be called at splsoftnet() */ | |
918 | { | 914 | { | |
915 | ||||
916 | IFNET_LOCK(ifp); | |||
919 | if_purgeaddrs(ifp, AF_INET, in_purgeaddr); | 917 | if_purgeaddrs(ifp, AF_INET, in_purgeaddr); | |
920 | igmp_purgeif(ifp); /* manipulates pools */ | 918 | igmp_purgeif(ifp); /* manipulates pools */ | |
921 | #ifdef MROUTING | 919 | #ifdef MROUTING | |
922 | ip_mrouter_detach(ifp); | 920 | ip_mrouter_detach(ifp); | |
923 | #endif | 921 | #endif | |
922 | IFNET_UNLOCK(ifp); | |||
924 | } | 923 | } | |
925 | 924 | |||
926 | /* | 925 | /* | |
927 | * SIOC[GAD]LIFADDR. | 926 | * SIOC[GAD]LIFADDR. | |
928 | * SIOCGLIFADDR: get first address. (???) | 927 | * SIOCGLIFADDR: get first address. (???) | |
929 | * SIOCGLIFADDR with IFLR_PREFIX: | 928 | * SIOCGLIFADDR with IFLR_PREFIX: | |
930 | * get first address that matches the specified prefix. | 929 | * get first address that matches the specified prefix. | |
931 | * SIOCALIFADDR: add the specified address. | 930 | * SIOCALIFADDR: add the specified address. | |
932 | * SIOCALIFADDR with IFLR_PREFIX: | 931 | * SIOCALIFADDR with IFLR_PREFIX: | |
933 | * EINVAL since we can't deduce hostid part of the address. | 932 | * EINVAL since we can't deduce hostid part of the address. | |
934 | * SIOCDLIFADDR: delete the specified address. | 933 | * SIOCDLIFADDR: delete the specified address. | |
935 | * SIOCDLIFADDR with IFLR_PREFIX: | 934 | * SIOCDLIFADDR with IFLR_PREFIX: | |
936 | * delete the first address that matches the specified prefix. | 935 | * delete the first address that matches the specified prefix. |
--- src/sys/netinet/in_pcb.c 2017/12/21 21:08:13 1.178.4.1
+++ src/sys/netinet/in_pcb.c 2018/01/02 10:20:34 1.178.4.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: in_pcb.c,v 1.178.4.1 2017/12/21 21:08:13 snj Exp $ */ | 1 | /* $NetBSD: in_pcb.c,v 1.178.4.2 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
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. | |
@@ -83,27 +83,27 @@ | @@ -83,27 +83,27 @@ | |||
83 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 83 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
84 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 84 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
85 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 85 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
86 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 86 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
87 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 87 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
88 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 88 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
89 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 89 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
90 | * SUCH DAMAGE. | 90 | * SUCH DAMAGE. | |
91 | * | 91 | * | |
92 | * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95 | 92 | * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95 | |
93 | */ | 93 | */ | |
94 | 94 | |||
95 | #include <sys/cdefs.h> | 95 | #include <sys/cdefs.h> | |
96 | __KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.178.4.1 2017/12/21 21:08:13 snj Exp $"); | 96 | __KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.178.4.2 2018/01/02 10:20:34 snj Exp $"); | |
97 | 97 | |||
98 | #ifdef _KERNEL_OPT | 98 | #ifdef _KERNEL_OPT | |
99 | #include "opt_inet.h" | 99 | #include "opt_inet.h" | |
100 | #include "opt_ipsec.h" | 100 | #include "opt_ipsec.h" | |
101 | #endif | 101 | #endif | |
102 | 102 | |||
103 | #include <sys/param.h> | 103 | #include <sys/param.h> | |
104 | #include <sys/systm.h> | 104 | #include <sys/systm.h> | |
105 | #include <sys/mbuf.h> | 105 | #include <sys/mbuf.h> | |
106 | #include <sys/socket.h> | 106 | #include <sys/socket.h> | |
107 | #include <sys/socketvar.h> | 107 | #include <sys/socketvar.h> | |
108 | #include <sys/ioctl.h> | 108 | #include <sys/ioctl.h> | |
109 | #include <sys/errno.h> | 109 | #include <sys/errno.h> | |
@@ -767,27 +767,30 @@ in_pcbpurgeif0(struct inpcbtable *table, | @@ -767,27 +767,30 @@ in_pcbpurgeif0(struct inpcbtable *table, | |||
767 | TAILQ_FOREACH_SAFE(inph, &table->inpt_queue, inph_queue, ninph) { | 767 | TAILQ_FOREACH_SAFE(inph, &table->inpt_queue, inph_queue, ninph) { | |
768 | struct inpcb *inp = (struct inpcb *)inph; | 768 | struct inpcb *inp = (struct inpcb *)inph; | |
769 | bool need_unlock = false; | 769 | bool need_unlock = false; | |
770 | 770 | |||
771 | if (inp->inp_af != AF_INET) | 771 | if (inp->inp_af != AF_INET) | |
772 | continue; | 772 | continue; | |
773 | 773 | |||
774 | /* The caller holds either one of inps' lock */ | 774 | /* The caller holds either one of inps' lock */ | |
775 | if (!inp_locked(inp)) { | 775 | if (!inp_locked(inp)) { | |
776 | inp_lock(inp); | 776 | inp_lock(inp); | |
777 | need_unlock = true; | 777 | need_unlock = true; | |
778 | } | 778 | } | |
779 | 779 | |||
780 | /* IFNET_LOCK must be taken after solock */ | |||
781 | IFNET_LOCK(ifp); | |||
780 | in_purgeifmcast(inp->inp_moptions, ifp); | 782 | in_purgeifmcast(inp->inp_moptions, ifp); | |
783 | IFNET_UNLOCK(ifp); | |||
781 | 784 | |||
782 | if (need_unlock) | 785 | if (need_unlock) | |
783 | inp_unlock(inp); | 786 | inp_unlock(inp); | |
784 | } | 787 | } | |
785 | } | 788 | } | |
786 | 789 | |||
787 | void | 790 | void | |
788 | in_pcbpurgeif(struct inpcbtable *table, struct ifnet *ifp) | 791 | in_pcbpurgeif(struct inpcbtable *table, struct ifnet *ifp) | |
789 | { | 792 | { | |
790 | struct rtentry *rt; | 793 | struct rtentry *rt; | |
791 | struct inpcb_hdr *inph, *ninph; | 794 | struct inpcb_hdr *inph, *ninph; | |
792 | 795 | |||
793 | TAILQ_FOREACH_SAFE(inph, &table->inpt_queue, inph_queue, ninph) { | 796 | TAILQ_FOREACH_SAFE(inph, &table->inpt_queue, inph_queue, ninph) { |
--- src/sys/netinet/ip_carp.c 2017/12/10 10:10:25 1.90.2.2
+++ src/sys/netinet/ip_carp.c 2018/01/02 10:20:34 1.90.2.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ip_carp.c,v 1.90.2.2 2017/12/10 10:10:25 snj Exp $ */ | 1 | /* $NetBSD: ip_carp.c,v 1.90.2.3 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $ */ | 2 | /* $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2002 Michael Shalayeff. All rights reserved. | 5 | * Copyright (c) 2002 Michael Shalayeff. All rights reserved. | |
6 | * Copyright (c) 2003 Ryan McBride. All rights reserved. | 6 | * Copyright (c) 2003 Ryan McBride. All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -23,27 +23,27 @@ | @@ -23,27 +23,27 @@ | |||
23 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 23 | * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
27 | * THE POSSIBILITY OF SUCH DAMAGE. | 27 | * THE POSSIBILITY OF SUCH DAMAGE. | |
28 | */ | 28 | */ | |
29 | 29 | |||
30 | #ifdef _KERNEL_OPT | 30 | #ifdef _KERNEL_OPT | |
31 | #include "opt_inet.h" | 31 | #include "opt_inet.h" | |
32 | #include "opt_mbuftrace.h" | 32 | #include "opt_mbuftrace.h" | |
33 | #endif | 33 | #endif | |
34 | 34 | |||
35 | #include <sys/cdefs.h> | 35 | #include <sys/cdefs.h> | |
36 | __KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.90.2.2 2017/12/10 10:10:25 snj Exp $"); | 36 | __KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.90.2.3 2018/01/02 10:20:34 snj Exp $"); | |
37 | 37 | |||
38 | /* | 38 | /* | |
39 | * TODO: | 39 | * TODO: | |
40 | * - iface reconfigure | 40 | * - iface reconfigure | |
41 | * - support for hardware checksum calculations; | 41 | * - support for hardware checksum calculations; | |
42 | * | 42 | * | |
43 | */ | 43 | */ | |
44 | 44 | |||
45 | #include <sys/param.h> | 45 | #include <sys/param.h> | |
46 | #include <sys/proc.h> | 46 | #include <sys/proc.h> | |
47 | #include <sys/mbuf.h> | 47 | #include <sys/mbuf.h> | |
48 | #include <sys/socket.h> | 48 | #include <sys/socket.h> | |
49 | #include <sys/socketvar.h> | 49 | #include <sys/socketvar.h> | |
@@ -885,27 +885,26 @@ carp_clone_create(struct if_clone *ifc, | @@ -885,27 +885,26 @@ carp_clone_create(struct if_clone *ifc, | |||
885 | if (rv != 0) { | 885 | if (rv != 0) { | |
886 | callout_destroy(&sc->sc_ad_tmo); | 886 | callout_destroy(&sc->sc_ad_tmo); | |
887 | callout_destroy(&sc->sc_md_tmo); | 887 | callout_destroy(&sc->sc_md_tmo); | |
888 | callout_destroy(&sc->sc_md6_tmo); | 888 | callout_destroy(&sc->sc_md6_tmo); | |
889 | free(ifp->if_softc, M_DEVBUF); | 889 | free(ifp->if_softc, M_DEVBUF); | |
890 | 890 | |||
891 | return rv; | 891 | return rv; | |
892 | } | 892 | } | |
893 | ether_ifattach(ifp, NULL); | 893 | ether_ifattach(ifp, NULL); | |
894 | carp_set_enaddr(sc); | 894 | carp_set_enaddr(sc); | |
895 | /* Overwrite ethernet defaults */ | 895 | /* Overwrite ethernet defaults */ | |
896 | ifp->if_type = IFT_CARP; | 896 | ifp->if_type = IFT_CARP; | |
897 | ifp->if_output = carp_output; | 897 | ifp->if_output = carp_output; | |
898 | ifp->if_extflags &= ~IFEF_OUTPUT_MPSAFE; | |||
899 | if_register(ifp); | 898 | if_register(ifp); | |
900 | 899 | |||
901 | return (0); | 900 | return (0); | |
902 | } | 901 | } | |
903 | 902 | |||
904 | static int | 903 | static int | |
905 | carp_clone_destroy(struct ifnet *ifp) | 904 | carp_clone_destroy(struct ifnet *ifp) | |
906 | { | 905 | { | |
907 | struct carp_softc *sc = ifp->if_softc; | 906 | struct carp_softc *sc = ifp->if_softc; | |
908 | 907 | |||
909 | carpdetach(ifp->if_softc); | 908 | carpdetach(ifp->if_softc); | |
910 | ether_ifdetach(ifp); | 909 | ether_ifdetach(ifp); | |
911 | if_detach(ifp); | 910 | if_detach(ifp); | |
@@ -2226,27 +2225,33 @@ carp_set_state(struct carp_softc *sc, in | @@ -2226,27 +2225,33 @@ carp_set_state(struct carp_softc *sc, in | |||
2226 | 2225 | |||
2227 | sc->sc_state = state; | 2226 | sc->sc_state = state; | |
2228 | switch (state) { | 2227 | switch (state) { | |
2229 | case BACKUP: | 2228 | case BACKUP: | |
2230 | link_state = LINK_STATE_DOWN; | 2229 | link_state = LINK_STATE_DOWN; | |
2231 | break; | 2230 | break; | |
2232 | case MASTER: | 2231 | case MASTER: | |
2233 | link_state = LINK_STATE_UP; | 2232 | link_state = LINK_STATE_UP; | |
2234 | break; | 2233 | break; | |
2235 | default: | 2234 | default: | |
2236 | link_state = LINK_STATE_UNKNOWN; | 2235 | link_state = LINK_STATE_UNKNOWN; | |
2237 | break; | 2236 | break; | |
2238 | } | 2237 | } | |
2238 | /* | |||
2239 | * The lock is needed to serialize a call of | |||
2240 | * if_link_state_change_softint from here and a call from softint. | |||
2241 | */ | |||
2242 | KERNEL_LOCK(1, NULL); | |||
2239 | if_link_state_change_softint(&sc->sc_if, link_state); | 2243 | if_link_state_change_softint(&sc->sc_if, link_state); | |
2244 | KERNEL_UNLOCK_ONE(NULL); | |||
2240 | } | 2245 | } | |
2241 | 2246 | |||
2242 | void | 2247 | void | |
2243 | carp_carpdev_state(void *v) | 2248 | carp_carpdev_state(void *v) | |
2244 | { | 2249 | { | |
2245 | struct carp_if *cif; | 2250 | struct carp_if *cif; | |
2246 | struct carp_softc *sc; | 2251 | struct carp_softc *sc; | |
2247 | struct ifnet *ifp = v; | 2252 | struct ifnet *ifp = v; | |
2248 | 2253 | |||
2249 | if (ifp->if_type == IFT_CARP) | 2254 | if (ifp->if_type == IFT_CARP) | |
2250 | return; | 2255 | return; | |
2251 | 2256 | |||
2252 | cif = (struct carp_if *)ifp->if_carp; | 2257 | cif = (struct carp_if *)ifp->if_carp; |
--- src/sys/netinet/ip_flow.c 2017/02/07 02:38:08 1.80
+++ src/sys/netinet/ip_flow.c 2018/01/02 10:20:34 1.80.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ip_flow.c,v 1.80 2017/02/07 02:38:08 ozaki-r Exp $ */ | 1 | /* $NetBSD: ip_flow.c,v 1.80.6.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998 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 the 3am Software Foundry ("3am"). It was developed by Matt Thomas. | 8 | * by the 3am Software Foundry ("3am"). It was developed by Matt Thomas. | |
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. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.80 2017/02/07 02:38:08 ozaki-r Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.80.6.1 2018/01/02 10:20:34 snj Exp $"); | |
34 | 34 | |||
35 | #ifdef _KERNEL_OPT | 35 | #ifdef _KERNEL_OPT | |
36 | #include "opt_net_mpsafe.h" | 36 | #include "opt_net_mpsafe.h" | |
37 | #endif | 37 | #endif | |
38 | 38 | |||
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/systm.h> | 40 | #include <sys/systm.h> | |
41 | #include <sys/malloc.h> | 41 | #include <sys/malloc.h> | |
42 | #include <sys/mbuf.h> | 42 | #include <sys/mbuf.h> | |
43 | #include <sys/socketvar.h> | 43 | #include <sys/socketvar.h> | |
44 | #include <sys/errno.h> | 44 | #include <sys/errno.h> | |
45 | #include <sys/time.h> | 45 | #include <sys/time.h> | |
46 | #include <sys/kernel.h> | 46 | #include <sys/kernel.h> | |
@@ -472,76 +472,68 @@ ipflow_reap(bool just_one) | @@ -472,76 +472,68 @@ ipflow_reap(bool just_one) | |||
472 | 472 | |||
473 | static unsigned int ipflow_work_enqueued = 0; | 473 | static unsigned int ipflow_work_enqueued = 0; | |
474 | 474 | |||
475 | static void | 475 | static void | |
476 | ipflow_slowtimo_work(struct work *wk, void *arg) | 476 | ipflow_slowtimo_work(struct work *wk, void *arg) | |
477 | { | 477 | { | |
478 | struct rtentry *rt; | 478 | struct rtentry *rt; | |
479 | struct ipflow *ipf, *next_ipf; | 479 | struct ipflow *ipf, *next_ipf; | |
480 | uint64_t *ips; | 480 | uint64_t *ips; | |
481 | 481 | |||
482 | /* We can allow enqueuing another work at this point */ | 482 | /* We can allow enqueuing another work at this point */ | |
483 | atomic_swap_uint(&ipflow_work_enqueued, 0); | 483 | atomic_swap_uint(&ipflow_work_enqueued, 0); | |
484 | 484 | |||
485 | #ifndef NET_MPSAFE | 485 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
486 | mutex_enter(softnet_lock); | |||
487 | KERNEL_LOCK(1, NULL); | |||
488 | #endif | |||
489 | mutex_enter(&ipflow_lock); | 486 | mutex_enter(&ipflow_lock); | |
490 | for (ipf = TAILQ_FIRST(&ipflowlist); ipf != NULL; ipf = next_ipf) { | 487 | for (ipf = TAILQ_FIRST(&ipflowlist); ipf != NULL; ipf = next_ipf) { | |
491 | next_ipf = TAILQ_NEXT(ipf, ipf_list); | 488 | next_ipf = TAILQ_NEXT(ipf, ipf_list); | |
492 | if (PRT_SLOW_ISEXPIRED(ipf->ipf_timer) || | 489 | if (PRT_SLOW_ISEXPIRED(ipf->ipf_timer) || | |
493 | (rt = rtcache_validate(&ipf->ipf_ro)) == NULL) { | 490 | (rt = rtcache_validate(&ipf->ipf_ro)) == NULL) { | |
494 | ipflow_free(ipf); | 491 | ipflow_free(ipf); | |
495 | } else { | 492 | } else { | |
496 | ipf->ipf_last_uses = ipf->ipf_uses; | 493 | ipf->ipf_last_uses = ipf->ipf_uses; | |
497 | rt->rt_use += ipf->ipf_uses; | 494 | rt->rt_use += ipf->ipf_uses; | |
498 | rtcache_unref(rt, &ipf->ipf_ro); | 495 | rtcache_unref(rt, &ipf->ipf_ro); | |
499 | ips = IP_STAT_GETREF(); | 496 | ips = IP_STAT_GETREF(); | |
500 | ips[IP_STAT_TOTAL] += ipf->ipf_uses; | 497 | ips[IP_STAT_TOTAL] += ipf->ipf_uses; | |
501 | ips[IP_STAT_FORWARD] += ipf->ipf_uses; | 498 | ips[IP_STAT_FORWARD] += ipf->ipf_uses; | |
502 | ips[IP_STAT_FASTFORWARD] += ipf->ipf_uses; | 499 | ips[IP_STAT_FASTFORWARD] += ipf->ipf_uses; | |
503 | IP_STAT_PUTREF(); | 500 | IP_STAT_PUTREF(); | |
504 | ipf->ipf_uses = 0; | 501 | ipf->ipf_uses = 0; | |
505 | } | 502 | } | |
506 | } | 503 | } | |
507 | mutex_exit(&ipflow_lock); | 504 | mutex_exit(&ipflow_lock); | |
508 | #ifndef NET_MPSAFE | 505 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
509 | KERNEL_UNLOCK_ONE(NULL); | |||
510 | mutex_exit(softnet_lock); | |||
511 | #endif | |||
512 | } | 506 | } | |
513 | 507 | |||
514 | void | 508 | void | |
515 | ipflow_slowtimo(void) | 509 | ipflow_slowtimo(void) | |
516 | { | 510 | { | |
517 | 511 | |||
518 | /* Avoid enqueuing another work when one is already enqueued */ | 512 | /* Avoid enqueuing another work when one is already enqueued */ | |
519 | if (atomic_swap_uint(&ipflow_work_enqueued, 1) == 1) | 513 | if (atomic_swap_uint(&ipflow_work_enqueued, 1) == 1) | |
520 | return; | 514 | return; | |
521 | 515 | |||
522 | workqueue_enqueue(ipflow_slowtimo_wq, &ipflow_slowtimo_wk, NULL); | 516 | workqueue_enqueue(ipflow_slowtimo_wq, &ipflow_slowtimo_wk, NULL); | |
523 | } | 517 | } | |
524 | 518 | |||
525 | void | 519 | void | |
526 | ipflow_create(struct route *ro, struct mbuf *m) | 520 | ipflow_create(struct route *ro, struct mbuf *m) | |
527 | { | 521 | { | |
528 | const struct ip *const ip = mtod(m, const struct ip *); | 522 | const struct ip *const ip = mtod(m, const struct ip *); | |
529 | struct ipflow *ipf; | 523 | struct ipflow *ipf; | |
530 | size_t hash; | 524 | size_t hash; | |
531 | 525 | |||
532 | #ifndef NET_MPSAFE | 526 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
533 | KERNEL_LOCK(1, NULL); | |||
534 | #endif | |||
535 | mutex_enter(&ipflow_lock); | 527 | mutex_enter(&ipflow_lock); | |
536 | 528 | |||
537 | /* | 529 | /* | |
538 | * Don't create cache entries for ICMP messages. | 530 | * Don't create cache entries for ICMP messages. | |
539 | */ | 531 | */ | |
540 | if (ip_maxflows == 0 || ip->ip_p == IPPROTO_ICMP) | 532 | if (ip_maxflows == 0 || ip->ip_p == IPPROTO_ICMP) | |
541 | goto out; | 533 | goto out; | |
542 | 534 | |||
543 | /* | 535 | /* | |
544 | * See if an existing flow struct exists. If so remove it from its | 536 | * See if an existing flow struct exists. If so remove it from its | |
545 | * list and free the old route. If not, try to malloc a new one | 537 | * list and free the old route. If not, try to malloc a new one | |
546 | * (if we aren't at our limit). | 538 | * (if we aren't at our limit). | |
547 | */ | 539 | */ | |
@@ -572,29 +564,27 @@ ipflow_create(struct route *ro, struct m | @@ -572,29 +564,27 @@ ipflow_create(struct route *ro, struct m | |||
572 | ipf->ipf_dst = ip->ip_dst; | 564 | ipf->ipf_dst = ip->ip_dst; | |
573 | ipf->ipf_src = ip->ip_src; | 565 | ipf->ipf_src = ip->ip_src; | |
574 | ipf->ipf_tos = ip->ip_tos; | 566 | ipf->ipf_tos = ip->ip_tos; | |
575 | PRT_SLOW_ARM(ipf->ipf_timer, IPFLOW_TIMER); | 567 | PRT_SLOW_ARM(ipf->ipf_timer, IPFLOW_TIMER); | |
576 | 568 | |||
577 | /* | 569 | /* | |
578 | * Insert into the approriate bucket of the flow table. | 570 | * Insert into the approriate bucket of the flow table. | |
579 | */ | 571 | */ | |
580 | hash = ipflow_hash(ip); | 572 | hash = ipflow_hash(ip); | |
581 | IPFLOW_INSERT(hash, ipf); | 573 | IPFLOW_INSERT(hash, ipf); | |
582 | 574 | |||
583 | out: | 575 | out: | |
584 | mutex_exit(&ipflow_lock); | 576 | mutex_exit(&ipflow_lock); | |
585 | #ifndef NET_MPSAFE | 577 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
586 | KERNEL_UNLOCK_ONE(NULL); | |||
587 | #endif | |||
588 | } | 578 | } | |
589 | 579 | |||
590 | int | 580 | int | |
591 | ipflow_invalidate_all(int new_size) | 581 | ipflow_invalidate_all(int new_size) | |
592 | { | 582 | { | |
593 | struct ipflow *ipf, *next_ipf; | 583 | struct ipflow *ipf, *next_ipf; | |
594 | int error; | 584 | int error; | |
595 | 585 | |||
596 | error = 0; | 586 | error = 0; | |
597 | 587 | |||
598 | mutex_enter(&ipflow_lock); | 588 | mutex_enter(&ipflow_lock); | |
599 | 589 | |||
600 | for (ipf = TAILQ_FIRST(&ipflowlist); ipf != NULL; ipf = next_ipf) { | 590 | for (ipf = TAILQ_FIRST(&ipflowlist); ipf != NULL; ipf = next_ipf) { | |
@@ -612,69 +602,57 @@ ipflow_invalidate_all(int new_size) | @@ -612,69 +602,57 @@ ipflow_invalidate_all(int new_size) | |||
612 | 602 | |||
613 | /* | 603 | /* | |
614 | * sysctl helper routine for net.inet.ip.maxflows. | 604 | * sysctl helper routine for net.inet.ip.maxflows. | |
615 | */ | 605 | */ | |
616 | static int | 606 | static int | |
617 | sysctl_net_inet_ip_maxflows(SYSCTLFN_ARGS) | 607 | sysctl_net_inet_ip_maxflows(SYSCTLFN_ARGS) | |
618 | { | 608 | { | |
619 | int error; | 609 | int error; | |
620 | 610 | |||
621 | error = sysctl_lookup(SYSCTLFN_CALL(rnode)); | 611 | error = sysctl_lookup(SYSCTLFN_CALL(rnode)); | |
622 | if (error || newp == NULL) | 612 | if (error || newp == NULL) | |
623 | return (error); | 613 | return (error); | |
624 | 614 | |||
625 | #ifndef NET_MPSAFE | 615 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
626 | mutex_enter(softnet_lock); | |||
627 | KERNEL_LOCK(1, NULL); | |||
628 | #endif | |||
629 | mutex_enter(&ipflow_lock); | 616 | mutex_enter(&ipflow_lock); | |
630 | 617 | |||
631 | ipflow_reap(false); | 618 | ipflow_reap(false); | |
632 | 619 | |||
633 | mutex_exit(&ipflow_lock); | 620 | mutex_exit(&ipflow_lock); | |
634 | #ifndef NET_MPSAFE | 621 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
635 | KERNEL_UNLOCK_ONE(NULL); | |||
636 | mutex_exit(softnet_lock); | |||
637 | #endif | |||
638 | 622 | |||
639 | return (0); | 623 | return (0); | |
640 | } | 624 | } | |
641 | 625 | |||
642 | static int | 626 | static int | |
643 | sysctl_net_inet_ip_hashsize(SYSCTLFN_ARGS) | 627 | sysctl_net_inet_ip_hashsize(SYSCTLFN_ARGS) | |
644 | { | 628 | { | |
645 | int error, tmp; | 629 | int error, tmp; | |
646 | struct sysctlnode node; | 630 | struct sysctlnode node; | |
647 | 631 | |||
648 | node = *rnode; | 632 | node = *rnode; | |
649 | tmp = ip_hashsize; | 633 | tmp = ip_hashsize; | |
650 | node.sysctl_data = &tmp; | 634 | node.sysctl_data = &tmp; | |
651 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); | 635 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); | |
652 | if (error || newp == NULL) | 636 | if (error || newp == NULL) | |
653 | return (error); | 637 | return (error); | |
654 | 638 | |||
655 | if ((tmp & (tmp - 1)) == 0 && tmp != 0) { | 639 | if ((tmp & (tmp - 1)) == 0 && tmp != 0) { | |
656 | /* | 640 | /* | |
657 | * Can only fail due to malloc() | 641 | * Can only fail due to malloc() | |
658 | */ | 642 | */ | |
659 | #ifndef NET_MPSAFE | 643 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
660 | mutex_enter(softnet_lock); | |||
661 | KERNEL_LOCK(1, NULL); | |||
662 | #endif | |||
663 | error = ipflow_invalidate_all(tmp); | 644 | error = ipflow_invalidate_all(tmp); | |
664 | #ifndef NET_MPSAFE | 645 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
665 | KERNEL_UNLOCK_ONE(NULL); | |||
666 | mutex_exit(softnet_lock); | |||
667 | #endif | |||
668 | } else { | 646 | } else { | |
669 | /* | 647 | /* | |
670 | * EINVAL if not a power of 2 | 648 | * EINVAL if not a power of 2 | |
671 | */ | 649 | */ | |
672 | error = EINVAL; | 650 | error = EINVAL; | |
673 | } | 651 | } | |
674 | 652 | |||
675 | return error; | 653 | return error; | |
676 | } | 654 | } | |
677 | 655 | |||
678 | static void | 656 | static void | |
679 | ipflow_sysctl_init(struct sysctllog **clog) | 657 | ipflow_sysctl_init(struct sysctllog **clog) | |
680 | { | 658 | { |
--- src/sys/netinet/ip_input.c 2017/12/10 09:24:30 1.355.2.2
+++ src/sys/netinet/ip_input.c 2018/01/02 10:20:34 1.355.2.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ip_input.c,v 1.355.2.2 2017/12/10 09:24:30 snj Exp $ */ | 1 | /* $NetBSD: ip_input.c,v 1.355.2.3 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
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. | |
@@ -81,27 +81,27 @@ | @@ -81,27 +81,27 @@ | |||
81 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 81 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
82 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 82 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
83 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 83 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
84 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 84 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
85 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 85 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
86 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 86 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
87 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 87 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
88 | * SUCH DAMAGE. | 88 | * SUCH DAMAGE. | |
89 | * | 89 | * | |
90 | * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 | 90 | * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 | |
91 | */ | 91 | */ | |
92 | 92 | |||
93 | #include <sys/cdefs.h> | 93 | #include <sys/cdefs.h> | |
94 | __KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.355.2.2 2017/12/10 09:24:30 snj Exp $"); | 94 | __KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.355.2.3 2018/01/02 10:20:34 snj Exp $"); | |
95 | 95 | |||
96 | #ifdef _KERNEL_OPT | 96 | #ifdef _KERNEL_OPT | |
97 | #include "opt_inet.h" | 97 | #include "opt_inet.h" | |
98 | #include "opt_compat_netbsd.h" | 98 | #include "opt_compat_netbsd.h" | |
99 | #include "opt_gateway.h" | 99 | #include "opt_gateway.h" | |
100 | #include "opt_ipsec.h" | 100 | #include "opt_ipsec.h" | |
101 | #include "opt_mrouting.h" | 101 | #include "opt_mrouting.h" | |
102 | #include "opt_mbuftrace.h" | 102 | #include "opt_mbuftrace.h" | |
103 | #include "opt_inet_csum.h" | 103 | #include "opt_inet_csum.h" | |
104 | #include "opt_net_mpsafe.h" | 104 | #include "opt_net_mpsafe.h" | |
105 | #endif | 105 | #endif | |
106 | 106 | |||
107 | #include "arp.h" | 107 | #include "arp.h" | |
@@ -428,35 +428,31 @@ matched: | @@ -428,35 +428,31 @@ matched: | |||
428 | return ia; | 428 | return ia; | |
429 | } | 429 | } | |
430 | 430 | |||
431 | /* | 431 | /* | |
432 | * IP software interrupt routine. | 432 | * IP software interrupt routine. | |
433 | */ | 433 | */ | |
434 | static void | 434 | static void | |
435 | ipintr(void *arg __unused) | 435 | ipintr(void *arg __unused) | |
436 | { | 436 | { | |
437 | struct mbuf *m; | 437 | struct mbuf *m; | |
438 | 438 | |||
439 | KASSERT(cpu_softintr_p()); | 439 | KASSERT(cpu_softintr_p()); | |
440 | 440 | |||
441 | #ifndef NET_MPSAFE | 441 | SOFTNET_LOCK_UNLESS_NET_MPSAFE(); | |
442 | mutex_enter(softnet_lock); | |||
443 | #endif | |||
444 | while ((m = pktq_dequeue(ip_pktq)) != NULL) { | 442 | while ((m = pktq_dequeue(ip_pktq)) != NULL) { | |
445 | ip_input(m); | 443 | ip_input(m); | |
446 | } | 444 | } | |
447 | #ifndef NET_MPSAFE | 445 | SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); | |
448 | mutex_exit(softnet_lock); | |||
449 | #endif | |||
450 | } | 446 | } | |
451 | 447 | |||
452 | /* | 448 | /* | |
453 | * IP input routine. Checksum and byte swap header. If fragmented | 449 | * IP input routine. Checksum and byte swap header. If fragmented | |
454 | * try to reassemble. Process options. Pass to next level. | 450 | * try to reassemble. Process options. Pass to next level. | |
455 | */ | 451 | */ | |
456 | static void | 452 | static void | |
457 | ip_input(struct mbuf *m) | 453 | ip_input(struct mbuf *m) | |
458 | { | 454 | { | |
459 | struct ip *ip = NULL; | 455 | struct ip *ip = NULL; | |
460 | struct in_ifaddr *ia = NULL; | 456 | struct in_ifaddr *ia = NULL; | |
461 | int hlen = 0, len; | 457 | int hlen = 0, len; | |
462 | int downmatch; | 458 | int downmatch; | |
@@ -844,37 +840,31 @@ ours: | @@ -844,37 +840,31 @@ ours: | |||
844 | out: | 840 | out: | |
845 | m_put_rcvif_psref(ifp, &psref); | 841 | m_put_rcvif_psref(ifp, &psref); | |
846 | if (m != NULL) | 842 | if (m != NULL) | |
847 | m_freem(m); | 843 | m_freem(m); | |
848 | } | 844 | } | |
849 | 845 | |||
850 | /* | 846 | /* | |
851 | * IP timer processing. | 847 | * IP timer processing. | |
852 | */ | 848 | */ | |
853 | void | 849 | void | |
854 | ip_slowtimo(void) | 850 | ip_slowtimo(void) | |
855 | { | 851 | { | |
856 | 852 | |||
857 | #ifndef NET_MPSAFE | 853 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
858 | mutex_enter(softnet_lock); | |||
859 | KERNEL_LOCK(1, NULL); | |||
860 | #endif | |||
861 | 854 | |||
862 | ip_reass_slowtimo(); | 855 | ip_reass_slowtimo(); | |
863 | 856 | |||
864 | #ifndef NET_MPSAFE | 857 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
865 | KERNEL_UNLOCK_ONE(NULL); | |||
866 | mutex_exit(softnet_lock); | |||
867 | #endif | |||
868 | } | 858 | } | |
869 | 859 | |||
870 | /* | 860 | /* | |
871 | * IP drain processing. | 861 | * IP drain processing. | |
872 | */ | 862 | */ | |
873 | void | 863 | void | |
874 | ip_drain(void) | 864 | ip_drain(void) | |
875 | { | 865 | { | |
876 | 866 | |||
877 | KERNEL_LOCK(1, NULL); | 867 | KERNEL_LOCK(1, NULL); | |
878 | ip_reass_drain(); | 868 | ip_reass_drain(); | |
879 | KERNEL_UNLOCK_ONE(NULL); | 869 | KERNEL_UNLOCK_ONE(NULL); | |
880 | } | 870 | } |
--- src/sys/netinet/ip_mroute.c 2017/12/10 09:41:31 1.146.6.1
+++ src/sys/netinet/ip_mroute.c 2018/01/02 10:20:34 1.146.6.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ip_mroute.c,v 1.146.6.1 2017/12/10 09:41:31 snj Exp $ */ | 1 | /* $NetBSD: ip_mroute.c,v 1.146.6.2 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993 | |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * Stephen Deering of Stanford University. | 8 | * Stephen Deering of Stanford University. | |
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. | |
@@ -83,27 +83,27 @@ | @@ -83,27 +83,27 @@ | |||
83 | * Modified by Charles M. Hannum, NetBSD, May 1995. | 83 | * Modified by Charles M. Hannum, NetBSD, May 1995. | |
84 | * Modified by Ahmed Helmy, SGI, June 1996 | 84 | * Modified by Ahmed Helmy, SGI, June 1996 | |
85 | * Modified by George Edmond Eddy (Rusty), ISI, February 1998 | 85 | * Modified by George Edmond Eddy (Rusty), ISI, February 1998 | |
86 | * Modified by Pavlin Radoslavov, USC/ISI, May 1998, August 1999, October 2000 | 86 | * Modified by Pavlin Radoslavov, USC/ISI, May 1998, August 1999, October 2000 | |
87 | * Modified by Hitoshi Asaeda, WIDE, August 2000 | 87 | * Modified by Hitoshi Asaeda, WIDE, August 2000 | |
88 | * Modified by Pavlin Radoslavov, ICSI, October 2002 | 88 | * Modified by Pavlin Radoslavov, ICSI, October 2002 | |
89 | * | 89 | * | |
90 | * MROUTING Revision: 1.2 | 90 | * MROUTING Revision: 1.2 | |
91 | * and PIM-SMv2 and PIM-DM support, advanced API support, | 91 | * and PIM-SMv2 and PIM-DM support, advanced API support, | |
92 | * bandwidth metering and signaling | 92 | * bandwidth metering and signaling | |
93 | */ | 93 | */ | |
94 | 94 | |||
95 | #include <sys/cdefs.h> | 95 | #include <sys/cdefs.h> | |
96 | __KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.146.6.1 2017/12/10 09:41:31 snj Exp $"); | 96 | __KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.146.6.2 2018/01/02 10:20:34 snj Exp $"); | |
97 | 97 | |||
98 | #ifdef _KERNEL_OPT | 98 | #ifdef _KERNEL_OPT | |
99 | #include "opt_inet.h" | 99 | #include "opt_inet.h" | |
100 | #include "opt_ipsec.h" | 100 | #include "opt_ipsec.h" | |
101 | #include "opt_pim.h" | 101 | #include "opt_pim.h" | |
102 | #endif | 102 | #endif | |
103 | 103 | |||
104 | #ifdef PIM | 104 | #ifdef PIM | |
105 | #define _PIM_VT 1 | 105 | #define _PIM_VT 1 | |
106 | #endif | 106 | #endif | |
107 | 107 | |||
108 | #include <sys/param.h> | 108 | #include <sys/param.h> | |
109 | #include <sys/systm.h> | 109 | #include <sys/systm.h> | |
@@ -1576,27 +1576,27 @@ expire_upcalls(void *v) | @@ -1576,27 +1576,27 @@ expire_upcalls(void *v) | |||
1576 | nrt = LIST_NEXT(rt, mfc_hash); | 1576 | nrt = LIST_NEXT(rt, mfc_hash); | |
1577 | 1577 | |||
1578 | if (rt->mfc_expire == 0 || --rt->mfc_expire > 0) | 1578 | if (rt->mfc_expire == 0 || --rt->mfc_expire > 0) | |
1579 | continue; | 1579 | continue; | |
1580 | nexpire[i]--; | 1580 | nexpire[i]--; | |
1581 | 1581 | |||
1582 | /* | 1582 | /* | |
1583 | * free the bw_meter entries | 1583 | * free the bw_meter entries | |
1584 | */ | 1584 | */ | |
1585 | while (rt->mfc_bw_meter != NULL) { | 1585 | while (rt->mfc_bw_meter != NULL) { | |
1586 | struct bw_meter *x = rt->mfc_bw_meter; | 1586 | struct bw_meter *x = rt->mfc_bw_meter; | |
1587 | 1587 | |||
1588 | rt->mfc_bw_meter = x->bm_mfc_next; | 1588 | rt->mfc_bw_meter = x->bm_mfc_next; | |
1589 | kmem_free(x, sizeof(*x)); | 1589 | kmem_intr_free(x, sizeof(*x)); | |
1590 | } | 1590 | } | |
1591 | 1591 | |||
1592 | ++mrtstat.mrts_cache_cleanups; | 1592 | ++mrtstat.mrts_cache_cleanups; | |
1593 | if (mrtdebug & DEBUG_EXPIRE) | 1593 | if (mrtdebug & DEBUG_EXPIRE) | |
1594 | log(LOG_DEBUG, | 1594 | log(LOG_DEBUG, | |
1595 | "expire_upcalls: expiring (%x %x)\n", | 1595 | "expire_upcalls: expiring (%x %x)\n", | |
1596 | ntohl(rt->mfc_origin.s_addr), | 1596 | ntohl(rt->mfc_origin.s_addr), | |
1597 | ntohl(rt->mfc_mcastgrp.s_addr)); | 1597 | ntohl(rt->mfc_mcastgrp.s_addr)); | |
1598 | 1598 | |||
1599 | expire_mfc(rt); | 1599 | expire_mfc(rt); | |
1600 | } | 1600 | } | |
1601 | } | 1601 | } | |
1602 | 1602 | |||
@@ -2521,27 +2521,27 @@ add_bw_upcall(struct bw_upcall *req) | @@ -2521,27 +2521,27 @@ add_bw_upcall(struct bw_upcall *req) | |||
2521 | splx(s); | 2521 | splx(s); | |
2522 | 2522 | |||
2523 | return 0; | 2523 | return 0; | |
2524 | } | 2524 | } | |
2525 | 2525 | |||
2526 | static void | 2526 | static void | |
2527 | free_bw_list(struct bw_meter *list) | 2527 | free_bw_list(struct bw_meter *list) | |
2528 | { | 2528 | { | |
2529 | while (list != NULL) { | 2529 | while (list != NULL) { | |
2530 | struct bw_meter *x = list; | 2530 | struct bw_meter *x = list; | |
2531 | 2531 | |||
2532 | list = list->bm_mfc_next; | 2532 | list = list->bm_mfc_next; | |
2533 | unschedule_bw_meter(x); | 2533 | unschedule_bw_meter(x); | |
2534 | kmem_free(x, sizeof(*x)); | 2534 | kmem_intr_free(x, sizeof(*x)); | |
2535 | } | 2535 | } | |
2536 | } | 2536 | } | |
2537 | 2537 | |||
2538 | /* | 2538 | /* | |
2539 | * Delete one or multiple bw_meter entries | 2539 | * Delete one or multiple bw_meter entries | |
2540 | */ | 2540 | */ | |
2541 | static int | 2541 | static int | |
2542 | del_bw_upcall(struct bw_upcall *req) | 2542 | del_bw_upcall(struct bw_upcall *req) | |
2543 | { | 2543 | { | |
2544 | int s; | 2544 | int s; | |
2545 | struct mfc *mfc; | 2545 | struct mfc *mfc; | |
2546 | struct bw_meter *x; | 2546 | struct bw_meter *x; | |
2547 | 2547 | |||
@@ -2580,27 +2580,27 @@ del_bw_upcall(struct bw_upcall *req) | @@ -2580,27 +2580,27 @@ del_bw_upcall(struct bw_upcall *req) | |||
2580 | (x->bm_threshold.b_bytes == req->bu_threshold.b_bytes) && | 2580 | (x->bm_threshold.b_bytes == req->bu_threshold.b_bytes) && | |
2581 | (x->bm_flags & BW_METER_USER_FLAGS) == flags) | 2581 | (x->bm_flags & BW_METER_USER_FLAGS) == flags) | |
2582 | break; | 2582 | break; | |
2583 | } | 2583 | } | |
2584 | if (x != NULL) { /* Delete entry from the list for this MFC */ | 2584 | if (x != NULL) { /* Delete entry from the list for this MFC */ | |
2585 | if (prev != NULL) | 2585 | if (prev != NULL) | |
2586 | prev->bm_mfc_next = x->bm_mfc_next; /* remove from middle*/ | 2586 | prev->bm_mfc_next = x->bm_mfc_next; /* remove from middle*/ | |
2587 | else | 2587 | else | |
2588 | x->bm_mfc->mfc_bw_meter = x->bm_mfc_next;/* new head of list */ | 2588 | x->bm_mfc->mfc_bw_meter = x->bm_mfc_next;/* new head of list */ | |
2589 | 2589 | |||
2590 | unschedule_bw_meter(x); | 2590 | unschedule_bw_meter(x); | |
2591 | splx(s); | 2591 | splx(s); | |
2592 | /* Free the bw_meter entry */ | 2592 | /* Free the bw_meter entry */ | |
2593 | kmem_free(x, sizeof(*x)); | 2593 | kmem_intr_free(x, sizeof(*x)); | |
2594 | return 0; | 2594 | return 0; | |
2595 | } else { | 2595 | } else { | |
2596 | splx(s); | 2596 | splx(s); | |
2597 | return EINVAL; | 2597 | return EINVAL; | |
2598 | } | 2598 | } | |
2599 | } | 2599 | } | |
2600 | /* NOTREACHED */ | 2600 | /* NOTREACHED */ | |
2601 | } | 2601 | } | |
2602 | 2602 | |||
2603 | /* | 2603 | /* | |
2604 | * Perform bandwidth measurement processing that may result in an upcall | 2604 | * Perform bandwidth measurement processing that may result in an upcall | |
2605 | */ | 2605 | */ | |
2606 | static void | 2606 | static void |
--- src/sys/netinet/ip_output.c 2017/12/21 21:08:13 1.279.2.2
+++ src/sys/netinet/ip_output.c 2018/01/02 10:20:34 1.279.2.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ip_output.c,v 1.279.2.2 2017/12/21 21:08:13 snj Exp $ */ | 1 | /* $NetBSD: ip_output.c,v 1.279.2.3 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
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. | |
@@ -81,27 +81,27 @@ | @@ -81,27 +81,27 @@ | |||
81 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 81 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
82 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 82 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
83 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 83 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
84 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 84 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
85 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 85 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
86 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 86 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
87 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 87 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
88 | * SUCH DAMAGE. | 88 | * SUCH DAMAGE. | |
89 | * | 89 | * | |
90 | * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 | 90 | * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 | |
91 | */ | 91 | */ | |
92 | 92 | |||
93 | #include <sys/cdefs.h> | 93 | #include <sys/cdefs.h> | |
94 | __KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.279.2.2 2017/12/21 21:08:13 snj Exp $"); | 94 | __KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.279.2.3 2018/01/02 10:20:34 snj Exp $"); | |
95 | 95 | |||
96 | #ifdef _KERNEL_OPT | 96 | #ifdef _KERNEL_OPT | |
97 | #include "opt_inet.h" | 97 | #include "opt_inet.h" | |
98 | #include "opt_ipsec.h" | 98 | #include "opt_ipsec.h" | |
99 | #include "opt_mrouting.h" | 99 | #include "opt_mrouting.h" | |
100 | #include "opt_net_mpsafe.h" | 100 | #include "opt_net_mpsafe.h" | |
101 | #include "opt_mpls.h" | 101 | #include "opt_mpls.h" | |
102 | #endif | 102 | #endif | |
103 | 103 | |||
104 | #include "arp.h" | 104 | #include "arp.h" | |
105 | 105 | |||
106 | #include <sys/param.h> | 106 | #include <sys/param.h> | |
107 | #include <sys/kmem.h> | 107 | #include <sys/kmem.h> | |
@@ -1761,27 +1761,30 @@ ip_add_membership(struct ip_moptions *im | @@ -1761,27 +1761,30 @@ ip_add_membership(struct ip_moptions *im | |||
1761 | error = EADDRINUSE; | 1761 | error = EADDRINUSE; | |
1762 | goto out; | 1762 | goto out; | |
1763 | } | 1763 | } | |
1764 | 1764 | |||
1765 | if (i == IP_MAX_MEMBERSHIPS) { | 1765 | if (i == IP_MAX_MEMBERSHIPS) { | |
1766 | error = ETOOMANYREFS; | 1766 | error = ETOOMANYREFS; | |
1767 | goto out; | 1767 | goto out; | |
1768 | } | 1768 | } | |
1769 | 1769 | |||
1770 | /* | 1770 | /* | |
1771 | * Everything looks good; add a new record to the multicast | 1771 | * Everything looks good; add a new record to the multicast | |
1772 | * address list for the given interface. | 1772 | * address list for the given interface. | |
1773 | */ | 1773 | */ | |
1774 | if ((imo->imo_membership[i] = in_addmulti(&ia, ifp)) == NULL) { | 1774 | IFNET_LOCK(ifp); | |
1775 | imo->imo_membership[i] = in_addmulti(&ia, ifp); | |||
1776 | IFNET_UNLOCK(ifp); | |||
1777 | if (imo->imo_membership[i] == NULL) { | |||
1775 | error = ENOBUFS; | 1778 | error = ENOBUFS; | |
1776 | goto out; | 1779 | goto out; | |
1777 | } | 1780 | } | |
1778 | 1781 | |||
1779 | ++imo->imo_num_memberships; | 1782 | ++imo->imo_num_memberships; | |
1780 | error = 0; | 1783 | error = 0; | |
1781 | out: | 1784 | out: | |
1782 | if_put(ifp, &psref); | 1785 | if_put(ifp, &psref); | |
1783 | curlwp_bindx(bound); | 1786 | curlwp_bindx(bound); | |
1784 | return error; | 1787 | return error; | |
1785 | } | 1788 | } | |
1786 | 1789 | |||
1787 | /* | 1790 | /* | |
@@ -1820,27 +1823,29 @@ ip_drop_membership(struct ip_moptions *i | @@ -1820,27 +1823,29 @@ ip_drop_membership(struct ip_moptions *i | |||
1820 | imo->imo_membership[i]->inm_ifp == ifp) && | 1823 | imo->imo_membership[i]->inm_ifp == ifp) && | |
1821 | in_hosteq(imo->imo_membership[i]->inm_addr, ia)) | 1824 | in_hosteq(imo->imo_membership[i]->inm_addr, ia)) | |
1822 | break; | 1825 | break; | |
1823 | } | 1826 | } | |
1824 | if (i == imo->imo_num_memberships) { | 1827 | if (i == imo->imo_num_memberships) { | |
1825 | error = EADDRNOTAVAIL; | 1828 | error = EADDRNOTAVAIL; | |
1826 | goto out; | 1829 | goto out; | |
1827 | } | 1830 | } | |
1828 | 1831 | |||
1829 | /* | 1832 | /* | |
1830 | * Give up the multicast address record to which the | 1833 | * Give up the multicast address record to which the | |
1831 | * membership points. | 1834 | * membership points. | |
1832 | */ | 1835 | */ | |
1836 | IFNET_LOCK(ifp); | |||
1833 | in_delmulti(imo->imo_membership[i]); | 1837 | in_delmulti(imo->imo_membership[i]); | |
1838 | IFNET_UNLOCK(ifp); | |||
1834 | 1839 | |||
1835 | /* | 1840 | /* | |
1836 | * Remove the gap in the membership array. | 1841 | * Remove the gap in the membership array. | |
1837 | */ | 1842 | */ | |
1838 | for (++i; i < imo->imo_num_memberships; ++i) | 1843 | for (++i; i < imo->imo_num_memberships; ++i) | |
1839 | imo->imo_membership[i-1] = imo->imo_membership[i]; | 1844 | imo->imo_membership[i-1] = imo->imo_membership[i]; | |
1840 | --imo->imo_num_memberships; | 1845 | --imo->imo_num_memberships; | |
1841 | error = 0; | 1846 | error = 0; | |
1842 | out: | 1847 | out: | |
1843 | if_put(ifp, &psref); | 1848 | if_put(ifp, &psref); | |
1844 | curlwp_bindx(bound); | 1849 | curlwp_bindx(bound); | |
1845 | return error; | 1850 | return error; | |
1846 | } | 1851 | } | |
@@ -1940,27 +1945,27 @@ ip_setmoptions(struct ip_moptions **pimo | @@ -1940,27 +1945,27 @@ ip_setmoptions(struct ip_moptions **pimo | |||
1940 | 1945 | |||
1941 | default: | 1946 | default: | |
1942 | error = EOPNOTSUPP; | 1947 | error = EOPNOTSUPP; | |
1943 | break; | 1948 | break; | |
1944 | } | 1949 | } | |
1945 | 1950 | |||
1946 | /* | 1951 | /* | |
1947 | * If all options have default values, no need to keep the mbuf. | 1952 | * If all options have default values, no need to keep the mbuf. | |
1948 | */ | 1953 | */ | |
1949 | if (imo->imo_multicast_if_index == 0 && | 1954 | if (imo->imo_multicast_if_index == 0 && | |
1950 | imo->imo_multicast_ttl == IP_DEFAULT_MULTICAST_TTL && | 1955 | imo->imo_multicast_ttl == IP_DEFAULT_MULTICAST_TTL && | |
1951 | imo->imo_multicast_loop == IP_DEFAULT_MULTICAST_LOOP && | 1956 | imo->imo_multicast_loop == IP_DEFAULT_MULTICAST_LOOP && | |
1952 | imo->imo_num_memberships == 0) { | 1957 | imo->imo_num_memberships == 0) { | |
1953 | kmem_free(imo, sizeof(*imo)); | 1958 | kmem_intr_free(imo, sizeof(*imo)); | |
1954 | *pimo = NULL; | 1959 | *pimo = NULL; | |
1955 | } | 1960 | } | |
1956 | 1961 | |||
1957 | return error; | 1962 | return error; | |
1958 | } | 1963 | } | |
1959 | 1964 | |||
1960 | /* | 1965 | /* | |
1961 | * Return the IP multicast options in response to user getsockopt(). | 1966 | * Return the IP multicast options in response to user getsockopt(). | |
1962 | */ | 1967 | */ | |
1963 | int | 1968 | int | |
1964 | ip_getmoptions(struct ip_moptions *imo, struct sockopt *sopt) | 1969 | ip_getmoptions(struct ip_moptions *imo, struct sockopt *sopt) | |
1965 | { | 1970 | { | |
1966 | struct in_addr addr; | 1971 | struct in_addr addr; | |
@@ -2013,29 +2018,36 @@ ip_getmoptions(struct ip_moptions *imo, | @@ -2013,29 +2018,36 @@ ip_getmoptions(struct ip_moptions *imo, | |||
2013 | } | 2018 | } | |
2014 | 2019 | |||
2015 | /* | 2020 | /* | |
2016 | * Discard the IP multicast options. | 2021 | * Discard the IP multicast options. | |
2017 | */ | 2022 | */ | |
2018 | void | 2023 | void | |
2019 | ip_freemoptions(struct ip_moptions *imo) | 2024 | ip_freemoptions(struct ip_moptions *imo) | |
2020 | { | 2025 | { | |
2021 | int i; | 2026 | int i; | |
2022 | 2027 | |||
2023 | /* The owner of imo (inp) should be protected by solock */ | 2028 | /* The owner of imo (inp) should be protected by solock */ | |
2024 | 2029 | |||
2025 | if (imo != NULL) { | 2030 | if (imo != NULL) { | |
2026 | for (i = 0; i < imo->imo_num_memberships; ++i) | 2031 | for (i = 0; i < imo->imo_num_memberships; ++i) { | |
2027 | in_delmulti(imo->imo_membership[i]); | 2032 | struct in_multi *inm = imo->imo_membership[i]; | |
2028 | kmem_free(imo, sizeof(*imo)); | 2033 | struct ifnet *ifp = inm->inm_ifp; | |
2034 | IFNET_LOCK(ifp); | |||
2035 | in_delmulti(inm); | |||
2036 | /* ifp should not leave thanks to solock */ | |||
2037 | IFNET_UNLOCK(ifp); | |||
2038 | } | |||
2039 | ||||
2040 | kmem_intr_free(imo, sizeof(*imo)); | |||
2029 | } | 2041 | } | |
2030 | } | 2042 | } | |
2031 | 2043 | |||
2032 | /* | 2044 | /* | |
2033 | * Routine called from ip_output() to loop back a copy of an IP multicast | 2045 | * Routine called from ip_output() to loop back a copy of an IP multicast | |
2034 | * packet to the input queue of a specified interface. Note that this | 2046 | * packet to the input queue of a specified interface. Note that this | |
2035 | * calls the output routine of the loopback "driver", but with an interface | 2047 | * calls the output routine of the loopback "driver", but with an interface | |
2036 | * pointer that might NOT be lo0ifp -- easier than replicating that code here. | 2048 | * pointer that might NOT be lo0ifp -- easier than replicating that code here. | |
2037 | */ | 2049 | */ | |
2038 | static void | 2050 | static void | |
2039 | ip_mloopback(struct ifnet *ifp, struct mbuf *m, const struct sockaddr_in *dst) | 2051 | ip_mloopback(struct ifnet *ifp, struct mbuf *m, const struct sockaddr_in *dst) | |
2040 | { | 2052 | { | |
2041 | struct ip *ip; | 2053 | struct ip *ip; | |
@@ -2051,33 +2063,29 @@ ip_mloopback(struct ifnet *ifp, struct m | @@ -2051,33 +2063,29 @@ ip_mloopback(struct ifnet *ifp, struct m | |||
2051 | * We don't bother to fragment if the IP length is greater | 2063 | * We don't bother to fragment if the IP length is greater | |
2052 | * than the interface's MTU. Can this possibly matter? | 2064 | * than the interface's MTU. Can this possibly matter? | |
2053 | */ | 2065 | */ | |
2054 | ip = mtod(copym, struct ip *); | 2066 | ip = mtod(copym, struct ip *); | |
2055 | 2067 | |||
2056 | if (copym->m_pkthdr.csum_flags & (M_CSUM_TCPv4|M_CSUM_UDPv4)) { | 2068 | if (copym->m_pkthdr.csum_flags & (M_CSUM_TCPv4|M_CSUM_UDPv4)) { | |
2057 | in_delayed_cksum(copym); | 2069 | in_delayed_cksum(copym); | |
2058 | copym->m_pkthdr.csum_flags &= | 2070 | copym->m_pkthdr.csum_flags &= | |
2059 | ~(M_CSUM_TCPv4|M_CSUM_UDPv4); | 2071 | ~(M_CSUM_TCPv4|M_CSUM_UDPv4); | |
2060 | } | 2072 | } | |
2061 | 2073 | |||
2062 | ip->ip_sum = 0; | 2074 | ip->ip_sum = 0; | |
2063 | ip->ip_sum = in_cksum(copym, ip->ip_hl << 2); | 2075 | ip->ip_sum = in_cksum(copym, ip->ip_hl << 2); | |
2064 | #ifndef NET_MPSAFE | 2076 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
2065 | KERNEL_LOCK(1, NULL); | |||
2066 | #endif | |||
2067 | (void)looutput(ifp, copym, sintocsa(dst), NULL); | 2077 | (void)looutput(ifp, copym, sintocsa(dst), NULL); | |
2068 | #ifndef NET_MPSAFE | 2078 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
2069 | KERNEL_UNLOCK_ONE(NULL); | |||
2070 | #endif | |||
2071 | } | 2079 | } | |
2072 | 2080 | |||
2073 | /* | 2081 | /* | |
2074 | * Ensure sending address is valid. | 2082 | * Ensure sending address is valid. | |
2075 | * Returns 0 on success, -1 if an error should be sent back or 1 | 2083 | * Returns 0 on success, -1 if an error should be sent back or 1 | |
2076 | * if the packet could be dropped without error (protocol dependent). | 2084 | * if the packet could be dropped without error (protocol dependent). | |
2077 | */ | 2085 | */ | |
2078 | static int | 2086 | static int | |
2079 | ip_ifaddrvalid(const struct in_ifaddr *ia) | 2087 | ip_ifaddrvalid(const struct in_ifaddr *ia) | |
2080 | { | 2088 | { | |
2081 | 2089 | |||
2082 | if (ia->ia_addr.sin_addr.s_addr == INADDR_ANY) | 2090 | if (ia->ia_addr.sin_addr.s_addr == INADDR_ANY) | |
2083 | return 0; | 2091 | return 0; |
--- src/sys/netinet6/frag6.c 2017/01/24 07:09:25 1.60
+++ src/sys/netinet6/frag6.c 2018/01/02 10:20:34 1.60.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: frag6.c,v 1.60 2017/01/24 07:09:25 ozaki-r Exp $ */ | 1 | /* $NetBSD: frag6.c,v 1.60.6.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $ */ | 2 | /* $KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -21,27 +21,27 @@ | @@ -21,27 +21,27 @@ | |||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | * SUCH DAMAGE. | 30 | * SUCH DAMAGE. | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | #include <sys/cdefs.h> | 33 | #include <sys/cdefs.h> | |
34 | __KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.60 2017/01/24 07:09:25 ozaki-r Exp $"); | 34 | __KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.60.6.1 2018/01/02 10:20:34 snj Exp $"); | |
35 | 35 | |||
36 | #ifdef _KERNEL_OPT | 36 | #ifdef _KERNEL_OPT | |
37 | #include "opt_net_mpsafe.h" | 37 | #include "opt_net_mpsafe.h" | |
38 | #endif | 38 | #endif | |
39 | 39 | |||
40 | #include <sys/param.h> | 40 | #include <sys/param.h> | |
41 | #include <sys/systm.h> | 41 | #include <sys/systm.h> | |
42 | #include <sys/mbuf.h> | 42 | #include <sys/mbuf.h> | |
43 | #include <sys/errno.h> | 43 | #include <sys/errno.h> | |
44 | #include <sys/time.h> | 44 | #include <sys/time.h> | |
45 | #include <sys/kmem.h> | 45 | #include <sys/kmem.h> | |
46 | #include <sys/kernel.h> | 46 | #include <sys/kernel.h> | |
47 | #include <sys/syslog.h> | 47 | #include <sys/syslog.h> | |
@@ -587,86 +587,74 @@ void | @@ -587,86 +587,74 @@ void | |||
587 | frag6_remque(struct ip6q *p6) | 587 | frag6_remque(struct ip6q *p6) | |
588 | { | 588 | { | |
589 | 589 | |||
590 | KASSERT(mutex_owned(&frag6_lock)); | 590 | KASSERT(mutex_owned(&frag6_lock)); | |
591 | 591 | |||
592 | p6->ip6q_prev->ip6q_next = p6->ip6q_next; | 592 | p6->ip6q_prev->ip6q_next = p6->ip6q_next; | |
593 | p6->ip6q_next->ip6q_prev = p6->ip6q_prev; | 593 | p6->ip6q_next->ip6q_prev = p6->ip6q_prev; | |
594 | } | 594 | } | |
595 | 595 | |||
596 | void | 596 | void | |
597 | frag6_fasttimo(void) | 597 | frag6_fasttimo(void) | |
598 | { | 598 | { | |
599 | 599 | |||
600 | #ifndef NET_MPSAFE | 600 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
601 | mutex_enter(softnet_lock); | |||
602 | KERNEL_LOCK(1, NULL); | |||
603 | #endif | |||
604 | 601 | |||
605 | if (frag6_drainwanted) { | 602 | if (frag6_drainwanted) { | |
606 | frag6_drain(); | 603 | frag6_drain(); | |
607 | frag6_drainwanted = 0; | 604 | frag6_drainwanted = 0; | |
608 | } | 605 | } | |
609 | 606 | |||
610 | #ifndef NET_MPSAFE | 607 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
611 | KERNEL_UNLOCK_ONE(NULL); | |||
612 | mutex_exit(softnet_lock); | |||
613 | #endif | |||
614 | } | 608 | } | |
615 | 609 | |||
616 | /* | 610 | /* | |
617 | * IPv6 reassembling timer processing; | 611 | * IPv6 reassembling timer processing; | |
618 | * if a timer expires on a reassembly | 612 | * if a timer expires on a reassembly | |
619 | * queue, discard it. | 613 | * queue, discard it. | |
620 | */ | 614 | */ | |
621 | void | 615 | void | |
622 | frag6_slowtimo(void) | 616 | frag6_slowtimo(void) | |
623 | { | 617 | { | |
624 | struct ip6q *q6; | 618 | struct ip6q *q6; | |
625 | 619 | |||
626 | #ifndef NET_MPSAFE | 620 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
627 | mutex_enter(softnet_lock); | |||
628 | KERNEL_LOCK(1, NULL); | |||
629 | #endif | |||
630 | 621 | |||
631 | mutex_enter(&frag6_lock); | 622 | mutex_enter(&frag6_lock); | |
632 | q6 = ip6q.ip6q_next; | 623 | q6 = ip6q.ip6q_next; | |
633 | if (q6) | 624 | if (q6) | |
634 | while (q6 != &ip6q) { | 625 | while (q6 != &ip6q) { | |
635 | --q6->ip6q_ttl; | 626 | --q6->ip6q_ttl; | |
636 | q6 = q6->ip6q_next; | 627 | q6 = q6->ip6q_next; | |
637 | if (q6->ip6q_prev->ip6q_ttl == 0) { | 628 | if (q6->ip6q_prev->ip6q_ttl == 0) { | |
638 | IP6_STATINC(IP6_STAT_FRAGTIMEOUT); | 629 | IP6_STATINC(IP6_STAT_FRAGTIMEOUT); | |
639 | /* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */ | 630 | /* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */ | |
640 | frag6_freef(q6->ip6q_prev); | 631 | frag6_freef(q6->ip6q_prev); | |
641 | } | 632 | } | |
642 | } | 633 | } | |
643 | /* | 634 | /* | |
644 | * If we are over the maximum number of fragments | 635 | * If we are over the maximum number of fragments | |
645 | * (due to the limit being lowered), drain off | 636 | * (due to the limit being lowered), drain off | |
646 | * enough to get down to the new limit. | 637 | * enough to get down to the new limit. | |
647 | */ | 638 | */ | |
648 | while (frag6_nfragpackets > (u_int)ip6_maxfragpackets && | 639 | while (frag6_nfragpackets > (u_int)ip6_maxfragpackets && | |
649 | ip6q.ip6q_prev) { | 640 | ip6q.ip6q_prev) { | |
650 | IP6_STATINC(IP6_STAT_FRAGOVERFLOW); | 641 | IP6_STATINC(IP6_STAT_FRAGOVERFLOW); | |
651 | /* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */ | 642 | /* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */ | |
652 | frag6_freef(ip6q.ip6q_prev); | 643 | frag6_freef(ip6q.ip6q_prev); | |
653 | } | 644 | } | |
654 | mutex_exit(&frag6_lock); | 645 | mutex_exit(&frag6_lock); | |
655 | 646 | |||
656 | #ifndef NET_MPSAFE | 647 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
657 | KERNEL_UNLOCK_ONE(NULL); | |||
658 | mutex_exit(softnet_lock); | |||
659 | #endif | |||
660 | 648 | |||
661 | #if 0 | 649 | #if 0 | |
662 | /* | 650 | /* | |
663 | * Routing changes might produce a better route than we last used; | 651 | * Routing changes might produce a better route than we last used; | |
664 | * make sure we notice eventually, even if forwarding only for one | 652 | * make sure we notice eventually, even if forwarding only for one | |
665 | * destination and the cache is never replaced. | 653 | * destination and the cache is never replaced. | |
666 | */ | 654 | */ | |
667 | rtcache_free(&ip6_forward_rt); | 655 | rtcache_free(&ip6_forward_rt); | |
668 | rtcache_free(&ipsrcchk_rt); | 656 | rtcache_free(&ipsrcchk_rt); | |
669 | #endif | 657 | #endif | |
670 | 658 | |||
671 | } | 659 | } | |
672 | 660 |
--- src/sys/netinet6/in6.c 2017/11/30 15:57:37 1.245.2.3
+++ src/sys/netinet6/in6.c 2018/01/02 10:20:34 1.245.2.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: in6.c,v 1.245.2.3 2017/11/30 15:57:37 martin Exp $ */ | 1 | /* $NetBSD: in6.c,v 1.245.2.4 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */ | 2 | /* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -52,27 +52,27 @@ | @@ -52,27 +52,27 @@ | |||
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | 59 | * SUCH DAMAGE. | |
60 | * | 60 | * | |
61 | * @(#)in.c 8.2 (Berkeley) 11/15/93 | 61 | * @(#)in.c 8.2 (Berkeley) 11/15/93 | |
62 | */ | 62 | */ | |
63 | 63 | |||
64 | #include <sys/cdefs.h> | 64 | #include <sys/cdefs.h> | |
65 | __KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.245.2.3 2017/11/30 15:57:37 martin Exp $"); | 65 | __KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.245.2.4 2018/01/02 10:20:34 snj Exp $"); | |
66 | 66 | |||
67 | #ifdef _KERNEL_OPT | 67 | #ifdef _KERNEL_OPT | |
68 | #include "opt_inet.h" | 68 | #include "opt_inet.h" | |
69 | #include "opt_compat_netbsd.h" | 69 | #include "opt_compat_netbsd.h" | |
70 | #include "opt_net_mpsafe.h" | 70 | #include "opt_net_mpsafe.h" | |
71 | #endif | 71 | #endif | |
72 | 72 | |||
73 | #include <sys/param.h> | 73 | #include <sys/param.h> | |
74 | #include <sys/ioctl.h> | 74 | #include <sys/ioctl.h> | |
75 | #include <sys/errno.h> | 75 | #include <sys/errno.h> | |
76 | #include <sys/malloc.h> | 76 | #include <sys/malloc.h> | |
77 | #include <sys/socket.h> | 77 | #include <sys/socket.h> | |
78 | #include <sys/socketvar.h> | 78 | #include <sys/socketvar.h> | |
@@ -757,33 +757,29 @@ in6_control(struct socket *so, u_long cm | @@ -757,33 +757,29 @@ in6_control(struct socket *so, u_long cm | |||
757 | 757 | |||
758 | case SIOCAADDRCTL_POLICY: | 758 | case SIOCAADDRCTL_POLICY: | |
759 | case SIOCDADDRCTL_POLICY: | 759 | case SIOCDADDRCTL_POLICY: | |
760 | 760 | |||
761 | if (kauth_authorize_network(curlwp->l_cred, | 761 | if (kauth_authorize_network(curlwp->l_cred, | |
762 | KAUTH_NETWORK_SOCKET, | 762 | KAUTH_NETWORK_SOCKET, | |
763 | KAUTH_REQ_NETWORK_SOCKET_SETPRIV, | 763 | KAUTH_REQ_NETWORK_SOCKET_SETPRIV, | |
764 | so, NULL, NULL)) | 764 | so, NULL, NULL)) | |
765 | return EPERM; | 765 | return EPERM; | |
766 | break; | 766 | break; | |
767 | } | 767 | } | |
768 | 768 | |||
769 | s = splsoftnet(); | 769 | s = splsoftnet(); | |
770 | #ifndef NET_MPSAFE | 770 | SOFTNET_LOCK_UNLESS_NET_MPSAFE(); | |
771 | mutex_enter(softnet_lock); | |||
772 | #endif | |||
773 | error = in6_control1(so , cmd, data, ifp); | 771 | error = in6_control1(so , cmd, data, ifp); | |
774 | #ifndef NET_MPSAFE | 772 | SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); | |
775 | mutex_exit(softnet_lock); | |||
776 | #endif | |||
777 | splx(s); | 773 | splx(s); | |
778 | return error; | 774 | return error; | |
779 | } | 775 | } | |
780 | 776 | |||
781 | static int | 777 | static int | |
782 | in6_get_llsol_addr(struct in6_addr *llsol, struct ifnet *ifp, | 778 | in6_get_llsol_addr(struct in6_addr *llsol, struct ifnet *ifp, | |
783 | struct in6_addr *ip6) | 779 | struct in6_addr *ip6) | |
784 | { | 780 | { | |
785 | int error; | 781 | int error; | |
786 | 782 | |||
787 | memset(llsol, 0, sizeof(struct in6_addr)); | 783 | memset(llsol, 0, sizeof(struct in6_addr)); | |
788 | llsol->s6_addr16[0] = htons(0xff02); | 784 | llsol->s6_addr16[0] = htons(0xff02); | |
789 | llsol->s6_addr32[1] = 0; | 785 | llsol->s6_addr32[1] = 0; | |
@@ -1379,47 +1375,50 @@ in6_update_ifa(struct ifnet *ifp, struct | @@ -1379,47 +1375,50 @@ in6_update_ifa(struct ifnet *ifp, struct | |||
1379 | rc = in6_update_ifa1(ifp, ifra, NULL, NULL, flags); | 1375 | rc = in6_update_ifa1(ifp, ifra, NULL, NULL, flags); | |
1380 | splx(s); | 1376 | splx(s); | |
1381 | return rc; | 1377 | return rc; | |
1382 | } | 1378 | } | |
1383 | 1379 | |||
1384 | void | 1380 | void | |
1385 | in6_purgeaddr(struct ifaddr *ifa) | 1381 | in6_purgeaddr(struct ifaddr *ifa) | |
1386 | { | 1382 | { | |
1387 | struct ifnet *ifp = ifa->ifa_ifp; | 1383 | struct ifnet *ifp = ifa->ifa_ifp; | |
1388 | struct in6_ifaddr *ia = (struct in6_ifaddr *) ifa; | 1384 | struct in6_ifaddr *ia = (struct in6_ifaddr *) ifa; | |
1389 | struct in6_multi_mship *imm; | 1385 | struct in6_multi_mship *imm; | |
1390 | 1386 | |||
1391 | KASSERT(!ifa_held(ifa)); | 1387 | KASSERT(!ifa_held(ifa)); | |
1388 | KASSERT(IFNET_LOCKED(ifp)); | |||
1392 | 1389 | |||
1393 | ifa->ifa_flags |= IFA_DESTROYING; | 1390 | ifa->ifa_flags |= IFA_DESTROYING; | |
1394 | 1391 | |||
1395 | /* stop DAD processing */ | 1392 | /* stop DAD processing */ | |
1396 | nd6_dad_stop(ifa); | 1393 | nd6_dad_stop(ifa); | |
1397 | 1394 | |||
1398 | /* Delete any network route. */ | 1395 | /* Delete any network route. */ | |
1399 | in6_ifremprefix(ia); | 1396 | in6_ifremprefix(ia); | |
1400 | 1397 | |||
1401 | /* Remove ownaddr's loopback rtentry, if it exists. */ | 1398 | /* Remove ownaddr's loopback rtentry, if it exists. */ | |
1402 | in6_ifremlocal(&(ia->ia_ifa)); | 1399 | in6_ifremlocal(&(ia->ia_ifa)); | |
1403 | 1400 | |||
1404 | /* | 1401 | /* | |
1405 | * leave from multicast groups we have joined for the interface | 1402 | * leave from multicast groups we have joined for the interface | |
1406 | */ | 1403 | */ | |
1404 | again: | |||
1407 | mutex_enter(&in6_ifaddr_lock); | 1405 | mutex_enter(&in6_ifaddr_lock); | |
1408 | while ((imm = LIST_FIRST(&ia->ia6_memberships)) != NULL) { | 1406 | while ((imm = LIST_FIRST(&ia->ia6_memberships)) != NULL) { | |
1409 | LIST_REMOVE(imm, i6mm_chain); | 1407 | LIST_REMOVE(imm, i6mm_chain); | |
1410 | mutex_exit(&in6_ifaddr_lock); | 1408 | mutex_exit(&in6_ifaddr_lock); | |
1409 | KASSERT(imm->i6mm_maddr->in6m_ifp == ifp); | |||
1411 | in6_leavegroup(imm); | 1410 | in6_leavegroup(imm); | |
1412 | mutex_enter(&in6_ifaddr_lock); | 1411 | goto again; | |
1413 | } | 1412 | } | |
1414 | mutex_exit(&in6_ifaddr_lock); | 1413 | mutex_exit(&in6_ifaddr_lock); | |
1415 | 1414 | |||
1416 | in6_unlink_ifa(ia, ifp); | 1415 | in6_unlink_ifa(ia, ifp); | |
1417 | } | 1416 | } | |
1418 | 1417 | |||
1419 | static void | 1418 | static void | |
1420 | in6_unlink_ifa(struct in6_ifaddr *ia, struct ifnet *ifp) | 1419 | in6_unlink_ifa(struct in6_ifaddr *ia, struct ifnet *ifp) | |
1421 | { | 1420 | { | |
1422 | int s = splsoftnet(); | 1421 | int s = splsoftnet(); | |
1423 | 1422 | |||
1424 | mutex_enter(&in6_ifaddr_lock); | 1423 | mutex_enter(&in6_ifaddr_lock); | |
1425 | IN6_ADDRLIST_WRITER_REMOVE(ia); | 1424 | IN6_ADDRLIST_WRITER_REMOVE(ia); | |
@@ -1450,27 +1449,29 @@ in6_unlink_ifa(struct in6_ifaddr *ia, st | @@ -1450,27 +1449,29 @@ in6_unlink_ifa(struct in6_ifaddr *ia, st | |||
1450 | /* | 1449 | /* | |
1451 | * release another refcnt for the link from in6_ifaddr. | 1450 | * release another refcnt for the link from in6_ifaddr. | |
1452 | * Note that we should decrement the refcnt at least once for all *BSD. | 1451 | * Note that we should decrement the refcnt at least once for all *BSD. | |
1453 | */ | 1452 | */ | |
1454 | ifafree(&ia->ia_ifa); | 1453 | ifafree(&ia->ia_ifa); | |
1455 | 1454 | |||
1456 | splx(s); | 1455 | splx(s); | |
1457 | } | 1456 | } | |
1458 | 1457 | |||
1459 | void | 1458 | void | |
1460 | in6_purgeif(struct ifnet *ifp) | 1459 | in6_purgeif(struct ifnet *ifp) | |
1461 | { | 1460 | { | |
1462 | 1461 | |||
1462 | IFNET_LOCK(ifp); | |||
1463 | in6_ifdetach(ifp); | 1463 | in6_ifdetach(ifp); | |
1464 | IFNET_UNLOCK(ifp); | |||
1464 | } | 1465 | } | |
1465 | 1466 | |||
1466 | void | 1467 | void | |
1467 | in6_purge_mcast_references(struct in6_multi *in6m) | 1468 | in6_purge_mcast_references(struct in6_multi *in6m) | |
1468 | { | 1469 | { | |
1469 | struct in6_ifaddr *ia; | 1470 | struct in6_ifaddr *ia; | |
1470 | 1471 | |||
1471 | KASSERT(in6_multi_locked(RW_WRITER)); | 1472 | KASSERT(in6_multi_locked(RW_WRITER)); | |
1472 | 1473 | |||
1473 | mutex_enter(&in6_ifaddr_lock); | 1474 | mutex_enter(&in6_ifaddr_lock); | |
1474 | IN6_ADDRLIST_WRITER_FOREACH(ia) { | 1475 | IN6_ADDRLIST_WRITER_FOREACH(ia) { | |
1475 | struct in6_multi_mship *imm; | 1476 | struct in6_multi_mship *imm; | |
1476 | LIST_FOREACH(imm, &ia->ia6_memberships, i6mm_chain) { | 1477 | LIST_FOREACH(imm, &ia->ia6_memberships, i6mm_chain) { | |
@@ -2706,33 +2707,29 @@ in6_domifattach(struct ifnet *ifp) | @@ -2706,33 +2707,29 @@ in6_domifattach(struct ifnet *ifp) | |||
2706 | 2707 | |||
2707 | ext->lltable = in6_lltattach(ifp); | 2708 | ext->lltable = in6_lltattach(ifp); | |
2708 | 2709 | |||
2709 | return ext; | 2710 | return ext; | |
2710 | } | 2711 | } | |
2711 | 2712 | |||
2712 | void | 2713 | void | |
2713 | in6_domifdetach(struct ifnet *ifp, void *aux) | 2714 | in6_domifdetach(struct ifnet *ifp, void *aux) | |
2714 | { | 2715 | { | |
2715 | struct in6_ifextra *ext = (struct in6_ifextra *)aux; | 2716 | struct in6_ifextra *ext = (struct in6_ifextra *)aux; | |
2716 | 2717 | |||
2717 | lltable_free(ext->lltable); | 2718 | lltable_free(ext->lltable); | |
2718 | ext->lltable = NULL; | 2719 | ext->lltable = NULL; | |
2719 | #ifndef NET_MPSAFE | 2720 | SOFTNET_LOCK_UNLESS_NET_MPSAFE(); | |
2720 | mutex_enter(softnet_lock); | |||
2721 | #endif | |||
2722 | nd6_ifdetach(ifp, ext); | 2721 | nd6_ifdetach(ifp, ext); | |
2723 | #ifndef NET_MPSAFE | 2722 | SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); | |
2724 | mutex_exit(softnet_lock); | |||
2725 | #endif | |||
2726 | free(ext->in6_ifstat, M_IFADDR); | 2723 | free(ext->in6_ifstat, M_IFADDR); | |
2727 | free(ext->icmp6_ifstat, M_IFADDR); | 2724 | free(ext->icmp6_ifstat, M_IFADDR); | |
2728 | scope6_ifdetach(ext->scope6_id); | 2725 | scope6_ifdetach(ext->scope6_id); | |
2729 | free(ext, M_IFADDR); | 2726 | free(ext, M_IFADDR); | |
2730 | } | 2727 | } | |
2731 | 2728 | |||
2732 | /* | 2729 | /* | |
2733 | * Convert IPv4 address stored in struct in_addr to IPv4-Mapped IPv6 address | 2730 | * Convert IPv4 address stored in struct in_addr to IPv4-Mapped IPv6 address | |
2734 | * stored in struct in6_addr as defined in RFC 4921 section 2.5.5.2. | 2731 | * stored in struct in6_addr as defined in RFC 4921 section 2.5.5.2. | |
2735 | */ | 2732 | */ | |
2736 | void | 2733 | void | |
2737 | in6_in_2_v4mapin6(const struct in_addr *in, struct in6_addr *in6) | 2734 | in6_in_2_v4mapin6(const struct in_addr *in, struct in6_addr *in6) | |
2738 | { | 2735 | { |
--- src/sys/netinet6/in6_pcb.c 2017/04/25 05:44:11 1.161
+++ src/sys/netinet6/in6_pcb.c 2018/01/02 10:20:34 1.161.4.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: in6_pcb.c,v 1.161 2017/04/25 05:44:11 ozaki-r Exp $ */ | 1 | /* $NetBSD: in6_pcb.c,v 1.161.4.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */ | 2 | /* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -52,27 +52,27 @@ | @@ -52,27 +52,27 @@ | |||
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | 59 | * SUCH DAMAGE. | |
60 | * | 60 | * | |
61 | * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94 | 61 | * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94 | |
62 | */ | 62 | */ | |
63 | 63 | |||
64 | #include <sys/cdefs.h> | 64 | #include <sys/cdefs.h> | |
65 | __KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.161 2017/04/25 05:44:11 ozaki-r Exp $"); | 65 | __KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.161.4.1 2018/01/02 10:20:34 snj Exp $"); | |
66 | 66 | |||
67 | #ifdef _KERNEL_OPT | 67 | #ifdef _KERNEL_OPT | |
68 | #include "opt_inet.h" | 68 | #include "opt_inet.h" | |
69 | #include "opt_ipsec.h" | 69 | #include "opt_ipsec.h" | |
70 | #endif | 70 | #endif | |
71 | 71 | |||
72 | #include <sys/param.h> | 72 | #include <sys/param.h> | |
73 | #include <sys/systm.h> | 73 | #include <sys/systm.h> | |
74 | #include <sys/mbuf.h> | 74 | #include <sys/mbuf.h> | |
75 | #include <sys/protosw.h> | 75 | #include <sys/protosw.h> | |
76 | #include <sys/socket.h> | 76 | #include <sys/socket.h> | |
77 | #include <sys/socketvar.h> | 77 | #include <sys/socketvar.h> | |
78 | #include <sys/ioctl.h> | 78 | #include <sys/ioctl.h> | |
@@ -865,31 +865,38 @@ in6_pcbpurgeif0(struct inpcbtable *table | @@ -865,31 +865,38 @@ in6_pcbpurgeif0(struct inpcbtable *table | |||
865 | if (im6o->im6o_multicast_if_index == ifp->if_index) | 865 | if (im6o->im6o_multicast_if_index == ifp->if_index) | |
866 | im6o->im6o_multicast_if_index = 0; | 866 | im6o->im6o_multicast_if_index = 0; | |
867 | 867 | |||
868 | /* | 868 | /* | |
869 | * Drop multicast group membership if we joined | 869 | * Drop multicast group membership if we joined | |
870 | * through the interface being detached. | 870 | * through the interface being detached. | |
871 | * XXX controversial - is it really legal for kernel | 871 | * XXX controversial - is it really legal for kernel | |
872 | * to force this? | 872 | * to force this? | |
873 | */ | 873 | */ | |
874 | LIST_FOREACH_SAFE(imm, &im6o->im6o_memberships, | 874 | LIST_FOREACH_SAFE(imm, &im6o->im6o_memberships, | |
875 | i6mm_chain, nimm) { | 875 | i6mm_chain, nimm) { | |
876 | if (imm->i6mm_maddr->in6m_ifp == ifp) { | 876 | if (imm->i6mm_maddr->in6m_ifp == ifp) { | |
877 | LIST_REMOVE(imm, i6mm_chain); | 877 | LIST_REMOVE(imm, i6mm_chain); | |
878 | IFNET_LOCK(ifp); | |||
878 | in6_leavegroup(imm); | 879 | in6_leavegroup(imm); | |
880 | IFNET_UNLOCK(ifp); | |||
879 | } | 881 | } | |
880 | } | 882 | } | |
881 | } | 883 | } | |
884 | ||||
885 | /* IFNET_LOCK must be taken after solock */ | |||
886 | IFNET_LOCK(ifp); | |||
882 | in_purgeifmcast(in6p->in6p_v4moptions, ifp); | 887 | in_purgeifmcast(in6p->in6p_v4moptions, ifp); | |
888 | IFNET_UNLOCK(ifp); | |||
889 | ||||
883 | if (need_unlock) | 890 | if (need_unlock) | |
884 | in6p_unlock(in6p); | 891 | in6p_unlock(in6p); | |
885 | } | 892 | } | |
886 | } | 893 | } | |
887 | 894 | |||
888 | void | 895 | void | |
889 | in6_pcbpurgeif(struct inpcbtable *table, struct ifnet *ifp) | 896 | in6_pcbpurgeif(struct inpcbtable *table, struct ifnet *ifp) | |
890 | { | 897 | { | |
891 | struct rtentry *rt; | 898 | struct rtentry *rt; | |
892 | struct inpcb_hdr *inph, *ninph; | 899 | struct inpcb_hdr *inph, *ninph; | |
893 | 900 | |||
894 | TAILQ_FOREACH_SAFE(inph, &table->inpt_queue, inph_queue, ninph) { | 901 | TAILQ_FOREACH_SAFE(inph, &table->inpt_queue, inph_queue, ninph) { | |
895 | struct in6pcb *in6p = (struct in6pcb *)inph; | 902 | struct in6pcb *in6p = (struct in6pcb *)inph; |
--- src/sys/netinet6/ip6_flow.c 2017/01/11 13:08:29 1.34
+++ src/sys/netinet6/ip6_flow.c 2018/01/02 10:20:34 1.34.8.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ip6_flow.c,v 1.34 2017/01/11 13:08:29 ozaki-r Exp $ */ | 1 | /* $NetBSD: ip6_flow.c,v 1.34.8.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2007 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2007 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 the 3am Software Foundry ("3am"). It was developed by Liam J. Foy | 8 | * by the 3am Software Foundry ("3am"). It was developed by Liam J. Foy | |
9 | * <liamjfoy@netbsd.org> and Matt Thomas <matt@netbsd.org>. | 9 | * <liamjfoy@netbsd.org> and Matt Thomas <matt@netbsd.org>. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -28,27 +28,27 @@ | @@ -28,27 +28,27 @@ | |||
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
30 | * POSSIBILITY OF SUCH DAMAGE. | 30 | * POSSIBILITY OF SUCH DAMAGE. | |
31 | * | 31 | * | |
32 | * IPv6 version was developed by Liam J. Foy. Original source existed in IPv4 | 32 | * IPv6 version was developed by Liam J. Foy. Original source existed in IPv4 | |
33 | * format developed by Matt Thomas. Thanks to Joerg Sonnenberger, Matt | 33 | * format developed by Matt Thomas. Thanks to Joerg Sonnenberger, Matt | |
34 | * Thomas and Christos Zoulas. | 34 | * Thomas and Christos Zoulas. | |
35 | * | 35 | * | |
36 | * Thanks to Liverpool John Moores University, especially Dr. David Llewellyn-Jones | 36 | * Thanks to Liverpool John Moores University, especially Dr. David Llewellyn-Jones | |
37 | * for providing resources (to test) and Professor Madjid Merabti. | 37 | * for providing resources (to test) and Professor Madjid Merabti. | |
38 | */ | 38 | */ | |
39 | 39 | |||
40 | #include <sys/cdefs.h> | 40 | #include <sys/cdefs.h> | |
41 | __KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.34 2017/01/11 13:08:29 ozaki-r Exp $"); | 41 | __KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.34.8.1 2018/01/02 10:20:34 snj Exp $"); | |
42 | 42 | |||
43 | #ifdef _KERNEL_OPT | 43 | #ifdef _KERNEL_OPT | |
44 | #include "opt_net_mpsafe.h" | 44 | #include "opt_net_mpsafe.h" | |
45 | #endif | 45 | #endif | |
46 | 46 | |||
47 | #include <sys/param.h> | 47 | #include <sys/param.h> | |
48 | #include <sys/systm.h> | 48 | #include <sys/systm.h> | |
49 | #include <sys/malloc.h> | 49 | #include <sys/malloc.h> | |
50 | #include <sys/mbuf.h> | 50 | #include <sys/mbuf.h> | |
51 | #include <sys/socketvar.h> | 51 | #include <sys/socketvar.h> | |
52 | #include <sys/time.h> | 52 | #include <sys/time.h> | |
53 | #include <sys/kernel.h> | 53 | #include <sys/kernel.h> | |
54 | #include <sys/pool.h> | 54 | #include <sys/pool.h> | |
@@ -509,82 +509,74 @@ ip6flow_reap(int just_one) | @@ -509,82 +509,74 @@ ip6flow_reap(int just_one) | |||
509 | return ip6f; | 509 | return ip6f; | |
510 | } | 510 | } | |
511 | 511 | |||
512 | static unsigned int ip6flow_work_enqueued = 0; | 512 | static unsigned int ip6flow_work_enqueued = 0; | |
513 | 513 | |||
514 | void | 514 | void | |
515 | ip6flow_slowtimo_work(struct work *wk, void *arg) | 515 | ip6flow_slowtimo_work(struct work *wk, void *arg) | |
516 | { | 516 | { | |
517 | struct ip6flow *ip6f, *next_ip6f; | 517 | struct ip6flow *ip6f, *next_ip6f; | |
518 | 518 | |||
519 | /* We can allow enqueuing another work at this point */ | 519 | /* We can allow enqueuing another work at this point */ | |
520 | atomic_swap_uint(&ip6flow_work_enqueued, 0); | 520 | atomic_swap_uint(&ip6flow_work_enqueued, 0); | |
521 | 521 | |||
522 | #ifndef NET_MPSAFE | 522 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
523 | mutex_enter(softnet_lock); | |||
524 | KERNEL_LOCK(1, NULL); | |||
525 | #endif | |||
526 | mutex_enter(&ip6flow_lock); | 523 | mutex_enter(&ip6flow_lock); | |
527 | 524 | |||
528 | for (ip6f = TAILQ_FIRST(&ip6flowlist); ip6f != NULL; ip6f = next_ip6f) { | 525 | for (ip6f = TAILQ_FIRST(&ip6flowlist); ip6f != NULL; ip6f = next_ip6f) { | |
529 | struct rtentry *rt = NULL; | 526 | struct rtentry *rt = NULL; | |
530 | next_ip6f = TAILQ_NEXT(ip6f, ip6f_list); | 527 | next_ip6f = TAILQ_NEXT(ip6f, ip6f_list); | |
531 | if (PRT_SLOW_ISEXPIRED(ip6f->ip6f_timer) || | 528 | if (PRT_SLOW_ISEXPIRED(ip6f->ip6f_timer) || | |
532 | (rt = rtcache_validate(&ip6f->ip6f_ro)) == NULL) { | 529 | (rt = rtcache_validate(&ip6f->ip6f_ro)) == NULL) { | |
533 | ip6flow_free(ip6f); | 530 | ip6flow_free(ip6f); | |
534 | } else { | 531 | } else { | |
535 | ip6f->ip6f_last_uses = ip6f->ip6f_uses; | 532 | ip6f->ip6f_last_uses = ip6f->ip6f_uses; | |
536 | ip6flow_addstats_rt(rt, ip6f); | 533 | ip6flow_addstats_rt(rt, ip6f); | |
537 | ip6f->ip6f_uses = 0; | 534 | ip6f->ip6f_uses = 0; | |
538 | ip6f->ip6f_dropped = 0; | 535 | ip6f->ip6f_dropped = 0; | |
539 | ip6f->ip6f_forwarded = 0; | 536 | ip6f->ip6f_forwarded = 0; | |
540 | } | 537 | } | |
541 | rtcache_unref(rt, &ip6f->ip6f_ro); | 538 | rtcache_unref(rt, &ip6f->ip6f_ro); | |
542 | } | 539 | } | |
543 | 540 | |||
544 | mutex_exit(&ip6flow_lock); | 541 | mutex_exit(&ip6flow_lock); | |
545 | #ifndef NET_MPSAFE | 542 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
546 | KERNEL_UNLOCK_ONE(NULL); | |||
547 | mutex_exit(softnet_lock); | |||
548 | #endif | |||
549 | } | 543 | } | |
550 | 544 | |||
551 | void | 545 | void | |
552 | ip6flow_slowtimo(void) | 546 | ip6flow_slowtimo(void) | |
553 | { | 547 | { | |
554 | 548 | |||
555 | /* Avoid enqueuing another work when one is already enqueued */ | 549 | /* Avoid enqueuing another work when one is already enqueued */ | |
556 | if (atomic_swap_uint(&ip6flow_work_enqueued, 1) == 1) | 550 | if (atomic_swap_uint(&ip6flow_work_enqueued, 1) == 1) | |
557 | return; | 551 | return; | |
558 | 552 | |||
559 | workqueue_enqueue(ip6flow_slowtimo_wq, &ip6flow_slowtimo_wk, NULL); | 553 | workqueue_enqueue(ip6flow_slowtimo_wq, &ip6flow_slowtimo_wk, NULL); | |
560 | } | 554 | } | |
561 | 555 | |||
562 | /* | 556 | /* | |
563 | * We have successfully forwarded a packet using the normal | 557 | * We have successfully forwarded a packet using the normal | |
564 | * IPv6 stack. Now create/update a flow. | 558 | * IPv6 stack. Now create/update a flow. | |
565 | */ | 559 | */ | |
566 | void | 560 | void | |
567 | ip6flow_create(struct route *ro, struct mbuf *m) | 561 | ip6flow_create(struct route *ro, struct mbuf *m) | |
568 | { | 562 | { | |
569 | const struct ip6_hdr *ip6; | 563 | const struct ip6_hdr *ip6; | |
570 | struct ip6flow *ip6f; | 564 | struct ip6flow *ip6f; | |
571 | size_t hash; | 565 | size_t hash; | |
572 | 566 | |||
573 | ip6 = mtod(m, const struct ip6_hdr *); | 567 | ip6 = mtod(m, const struct ip6_hdr *); | |
574 | 568 | |||
575 | #ifndef NET_MPSAFE | 569 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
576 | KERNEL_LOCK(1, NULL); | |||
577 | #endif | |||
578 | mutex_enter(&ip6flow_lock); | 570 | mutex_enter(&ip6flow_lock); | |
579 | 571 | |||
580 | /* | 572 | /* | |
581 | * If IPv6 Fast Forward is disabled, don't create a flow. | 573 | * If IPv6 Fast Forward is disabled, don't create a flow. | |
582 | * It can be disabled by setting net.inet6.ip6.maxflows to 0. | 574 | * It can be disabled by setting net.inet6.ip6.maxflows to 0. | |
583 | * | 575 | * | |
584 | * Don't create a flow for ICMPv6 messages. | 576 | * Don't create a flow for ICMPv6 messages. | |
585 | */ | 577 | */ | |
586 | if (ip6_maxflows == 0 || ip6->ip6_nxt == IPPROTO_IPV6_ICMP) | 578 | if (ip6_maxflows == 0 || ip6->ip6_nxt == IPPROTO_IPV6_ICMP) | |
587 | goto out; | 579 | goto out; | |
588 | 580 | |||
589 | /* | 581 | /* | |
590 | * See if an existing flow exists. If so: | 582 | * See if an existing flow exists. If so: | |
@@ -626,29 +618,27 @@ ip6flow_create(struct route *ro, struct | @@ -626,29 +618,27 @@ ip6flow_create(struct route *ro, struct | |||
626 | ip6f->ip6f_dst = ip6->ip6_dst; | 618 | ip6f->ip6f_dst = ip6->ip6_dst; | |
627 | ip6f->ip6f_src = ip6->ip6_src; | 619 | ip6f->ip6f_src = ip6->ip6_src; | |
628 | ip6f->ip6f_flow = ip6->ip6_flow; | 620 | ip6f->ip6f_flow = ip6->ip6_flow; | |
629 | PRT_SLOW_ARM(ip6f->ip6f_timer, IP6FLOW_TIMER); | 621 | PRT_SLOW_ARM(ip6f->ip6f_timer, IP6FLOW_TIMER); | |
630 | 622 | |||
631 | /* | 623 | /* | |
632 | * Insert into the approriate bucket of the flow table. | 624 | * Insert into the approriate bucket of the flow table. | |
633 | */ | 625 | */ | |
634 | hash = ip6flow_hash(ip6); | 626 | hash = ip6flow_hash(ip6); | |
635 | IP6FLOW_INSERT(hash, ip6f); | 627 | IP6FLOW_INSERT(hash, ip6f); | |
636 | 628 | |||
637 | out: | 629 | out: | |
638 | mutex_exit(&ip6flow_lock); | 630 | mutex_exit(&ip6flow_lock); | |
639 | #ifndef NET_MPSAFE | 631 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
640 | KERNEL_UNLOCK_ONE(NULL); | |||
641 | #endif | |||
642 | } | 632 | } | |
643 | 633 | |||
644 | /* | 634 | /* | |
645 | * Invalidate/remove all flows - if new_size is positive we | 635 | * Invalidate/remove all flows - if new_size is positive we | |
646 | * resize the hash table. | 636 | * resize the hash table. | |
647 | */ | 637 | */ | |
648 | int | 638 | int | |
649 | ip6flow_invalidate_all(int new_size) | 639 | ip6flow_invalidate_all(int new_size) | |
650 | { | 640 | { | |
651 | struct ip6flow *ip6f, *next_ip6f; | 641 | struct ip6flow *ip6f, *next_ip6f; | |
652 | int error; | 642 | int error; | |
653 | 643 | |||
654 | error = 0; | 644 | error = 0; | |
@@ -671,67 +661,55 @@ ip6flow_invalidate_all(int new_size) | @@ -671,67 +661,55 @@ ip6flow_invalidate_all(int new_size) | |||
671 | /* | 661 | /* | |
672 | * sysctl helper routine for net.inet.ip6.maxflows. Since | 662 | * sysctl helper routine for net.inet.ip6.maxflows. Since | |
673 | * we could reduce this value, call ip6flow_reap(); | 663 | * we could reduce this value, call ip6flow_reap(); | |
674 | */ | 664 | */ | |
675 | static int | 665 | static int | |
676 | sysctl_net_inet6_ip6_maxflows(SYSCTLFN_ARGS) | 666 | sysctl_net_inet6_ip6_maxflows(SYSCTLFN_ARGS) | |
677 | { | 667 | { | |
678 | int error; | 668 | int error; | |
679 | 669 | |||
680 | error = sysctl_lookup(SYSCTLFN_CALL(rnode)); | 670 | error = sysctl_lookup(SYSCTLFN_CALL(rnode)); | |
681 | if (error || newp == NULL) | 671 | if (error || newp == NULL) | |
682 | return (error); | 672 | return (error); | |
683 | 673 | |||
684 | #ifndef NET_MPSAFE | 674 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
685 | mutex_enter(softnet_lock); | |||
686 | KERNEL_LOCK(1, NULL); | |||
687 | #endif | |||
688 | 675 | |||
689 | ip6flow_reap(0); | 676 | ip6flow_reap(0); | |
690 | 677 | |||
691 | #ifndef NET_MPSAFE | 678 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
692 | KERNEL_UNLOCK_ONE(NULL); | |||
693 | mutex_exit(softnet_lock); | |||
694 | #endif | |||
695 | 679 | |||
696 | return (0); | 680 | return (0); | |
697 | } | 681 | } | |
698 | 682 | |||
699 | static int | 683 | static int | |
700 | sysctl_net_inet6_ip6_hashsize(SYSCTLFN_ARGS) | 684 | sysctl_net_inet6_ip6_hashsize(SYSCTLFN_ARGS) | |
701 | { | 685 | { | |
702 | int error, tmp; | 686 | int error, tmp; | |
703 | struct sysctlnode node; | 687 | struct sysctlnode node; | |
704 | 688 | |||
705 | node = *rnode; | 689 | node = *rnode; | |
706 | tmp = ip6_hashsize; | 690 | tmp = ip6_hashsize; | |
707 | node.sysctl_data = &tmp; | 691 | node.sysctl_data = &tmp; | |
708 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); | 692 | error = sysctl_lookup(SYSCTLFN_CALL(&node)); | |
709 | if (error || newp == NULL) | 693 | if (error || newp == NULL) | |
710 | return (error); | 694 | return (error); | |
711 | 695 | |||
712 | if ((tmp & (tmp - 1)) == 0 && tmp != 0) { | 696 | if ((tmp & (tmp - 1)) == 0 && tmp != 0) { | |
713 | /* | 697 | /* | |
714 | * Can only fail due to malloc() | 698 | * Can only fail due to malloc() | |
715 | */ | 699 | */ | |
716 | #ifndef NET_MPSAFE | 700 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
717 | mutex_enter(softnet_lock); | |||
718 | KERNEL_LOCK(1, NULL); | |||
719 | #endif | |||
720 | error = ip6flow_invalidate_all(tmp); | 701 | error = ip6flow_invalidate_all(tmp); | |
721 | #ifndef NET_MPSAFE | 702 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
722 | KERNEL_UNLOCK_ONE(NULL); | |||
723 | mutex_exit(softnet_lock); | |||
724 | #endif | |||
725 | } else { | 703 | } else { | |
726 | /* | 704 | /* | |
727 | * EINVAL if not a power of 2 | 705 | * EINVAL if not a power of 2 | |
728 | */ | 706 | */ | |
729 | error = EINVAL; | 707 | error = EINVAL; | |
730 | } | 708 | } | |
731 | 709 | |||
732 | return error; | 710 | return error; | |
733 | } | 711 | } | |
734 | 712 | |||
735 | static void | 713 | static void | |
736 | ip6flow_sysctl_init(struct sysctllog **clog) | 714 | ip6flow_sysctl_init(struct sysctllog **clog) | |
737 | { | 715 | { |
--- src/sys/netinet6/ip6_input.c 2017/12/10 09:24:30 1.178.2.2
+++ src/sys/netinet6/ip6_input.c 2018/01/02 10:20:34 1.178.2.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ip6_input.c,v 1.178.2.2 2017/12/10 09:24:30 snj Exp $ */ | 1 | /* $NetBSD: ip6_input.c,v 1.178.2.3 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ | 2 | /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -52,27 +52,27 @@ | @@ -52,27 +52,27 @@ | |||
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | 59 | * SUCH DAMAGE. | |
60 | * | 60 | * | |
61 | * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 | 61 | * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 | |
62 | */ | 62 | */ | |
63 | 63 | |||
64 | #include <sys/cdefs.h> | 64 | #include <sys/cdefs.h> | |
65 | __KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.178.2.2 2017/12/10 09:24:30 snj Exp $"); | 65 | __KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.178.2.3 2018/01/02 10:20:34 snj Exp $"); | |
66 | 66 | |||
67 | #ifdef _KERNEL_OPT | 67 | #ifdef _KERNEL_OPT | |
68 | #include "opt_gateway.h" | 68 | #include "opt_gateway.h" | |
69 | #include "opt_inet.h" | 69 | #include "opt_inet.h" | |
70 | #include "opt_inet6.h" | 70 | #include "opt_inet6.h" | |
71 | #include "opt_ipsec.h" | 71 | #include "opt_ipsec.h" | |
72 | #include "opt_compat_netbsd.h" | 72 | #include "opt_compat_netbsd.h" | |
73 | #include "opt_net_mpsafe.h" | 73 | #include "opt_net_mpsafe.h" | |
74 | #endif | 74 | #endif | |
75 | 75 | |||
76 | #include <sys/param.h> | 76 | #include <sys/param.h> | |
77 | #include <sys/systm.h> | 77 | #include <sys/systm.h> | |
78 | #include <sys/mbuf.h> | 78 | #include <sys/mbuf.h> | |
@@ -218,51 +218,47 @@ ip6_init2(void) | @@ -218,51 +218,47 @@ ip6_init2(void) | |||
218 | (ip6_temp_preferred_lifetime - ip6_desync_factor - | 218 | (ip6_temp_preferred_lifetime - ip6_desync_factor - | |
219 | ip6_temp_regen_advance) * hz, | 219 | ip6_temp_regen_advance) * hz, | |
220 | in6_tmpaddrtimer, NULL); | 220 | in6_tmpaddrtimer, NULL); | |
221 | } | 221 | } | |
222 | 222 | |||
223 | /* | 223 | /* | |
224 | * IP6 input interrupt handling. Just pass the packet to ip6_input. | 224 | * IP6 input interrupt handling. Just pass the packet to ip6_input. | |
225 | */ | 225 | */ | |
226 | static void | 226 | static void | |
227 | ip6intr(void *arg __unused) | 227 | ip6intr(void *arg __unused) | |
228 | { | 228 | { | |
229 | struct mbuf *m; | 229 | struct mbuf *m; | |
230 | 230 | |||
231 | #ifndef NET_MPSAFE | 231 | SOFTNET_LOCK_UNLESS_NET_MPSAFE(); | |
232 | mutex_enter(softnet_lock); | |||
233 | #endif | |||
234 | while ((m = pktq_dequeue(ip6_pktq)) != NULL) { | 232 | while ((m = pktq_dequeue(ip6_pktq)) != NULL) { | |
235 | struct psref psref; | 233 | struct psref psref; | |
236 | struct ifnet *rcvif = m_get_rcvif_psref(m, &psref); | 234 | struct ifnet *rcvif = m_get_rcvif_psref(m, &psref); | |
237 | 235 | |||
238 | if (rcvif == NULL) { | 236 | if (rcvif == NULL) { | |
239 | m_freem(m); | 237 | m_freem(m); | |
240 | continue; | 238 | continue; | |
241 | } | 239 | } | |
242 | /* | 240 | /* | |
243 | * Drop the packet if IPv6 is disabled on the interface. | 241 | * Drop the packet if IPv6 is disabled on the interface. | |
244 | */ | 242 | */ | |
245 | if ((ND_IFINFO(rcvif)->flags & ND6_IFF_IFDISABLED)) { | 243 | if ((ND_IFINFO(rcvif)->flags & ND6_IFF_IFDISABLED)) { | |
246 | m_put_rcvif_psref(rcvif, &psref); | 244 | m_put_rcvif_psref(rcvif, &psref); | |
247 | m_freem(m); | 245 | m_freem(m); | |
248 | continue; | 246 | continue; | |
249 | } | 247 | } | |
250 | ip6_input(m, rcvif); | 248 | ip6_input(m, rcvif); | |
251 | m_put_rcvif_psref(rcvif, &psref); | 249 | m_put_rcvif_psref(rcvif, &psref); | |
252 | } | 250 | } | |
253 | #ifndef NET_MPSAFE | 251 | SOFTNET_UNLOCK_UNLESS_NET_MPSAFE(); | |
254 | mutex_exit(softnet_lock); | |||
255 | #endif | |||
256 | } | 252 | } | |
257 | 253 | |||
258 | void | 254 | void | |
259 | ip6_input(struct mbuf *m, struct ifnet *rcvif) | 255 | ip6_input(struct mbuf *m, struct ifnet *rcvif) | |
260 | { | 256 | { | |
261 | struct ip6_hdr *ip6; | 257 | struct ip6_hdr *ip6; | |
262 | int hit, off = sizeof(struct ip6_hdr), nest; | 258 | int hit, off = sizeof(struct ip6_hdr), nest; | |
263 | u_int32_t plen; | 259 | u_int32_t plen; | |
264 | u_int32_t rtalert = ~0; | 260 | u_int32_t rtalert = ~0; | |
265 | int nxt, ours = 0, rh_present = 0; | 261 | int nxt, ours = 0, rh_present = 0; | |
266 | struct ifnet *deliverifp = NULL; | 262 | struct ifnet *deliverifp = NULL; | |
267 | int srcrt = 0; | 263 | int srcrt = 0; | |
268 | struct rtentry *rt = NULL; | 264 | struct rtentry *rt = NULL; |
--- src/sys/netinet6/ip6_output.c 2017/12/10 09:24:30 1.191.6.3
+++ src/sys/netinet6/ip6_output.c 2018/01/02 10:20:34 1.191.6.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ip6_output.c,v 1.191.6.3 2017/12/10 09:24:30 snj Exp $ */ | 1 | /* $NetBSD: ip6_output.c,v 1.191.6.4 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ | 2 | /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -52,27 +52,27 @@ | @@ -52,27 +52,27 @@ | |||
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | 59 | * SUCH DAMAGE. | |
60 | * | 60 | * | |
61 | * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 | 61 | * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 | |
62 | */ | 62 | */ | |
63 | 63 | |||
64 | #include <sys/cdefs.h> | 64 | #include <sys/cdefs.h> | |
65 | __KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.191.6.3 2017/12/10 09:24:30 snj Exp $"); | 65 | __KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.191.6.4 2018/01/02 10:20:34 snj Exp $"); | |
66 | 66 | |||
67 | #ifdef _KERNEL_OPT | 67 | #ifdef _KERNEL_OPT | |
68 | #include "opt_inet.h" | 68 | #include "opt_inet.h" | |
69 | #include "opt_inet6.h" | 69 | #include "opt_inet6.h" | |
70 | #include "opt_ipsec.h" | 70 | #include "opt_ipsec.h" | |
71 | #endif | 71 | #endif | |
72 | 72 | |||
73 | #include <sys/param.h> | 73 | #include <sys/param.h> | |
74 | #include <sys/malloc.h> | 74 | #include <sys/malloc.h> | |
75 | #include <sys/mbuf.h> | 75 | #include <sys/mbuf.h> | |
76 | #include <sys/errno.h> | 76 | #include <sys/errno.h> | |
77 | #include <sys/socket.h> | 77 | #include <sys/socket.h> | |
78 | #include <sys/socketvar.h> | 78 | #include <sys/socketvar.h> | |
@@ -2596,37 +2596,40 @@ ip6_setmoptions(const struct sockopt *so | @@ -2596,37 +2596,40 @@ ip6_setmoptions(const struct sockopt *so | |||
2596 | if (imm->i6mm_maddr->in6m_ifp == ifp && | 2596 | if (imm->i6mm_maddr->in6m_ifp == ifp && | |
2597 | IN6_ARE_ADDR_EQUAL(&imm->i6mm_maddr->in6m_addr, | 2597 | IN6_ARE_ADDR_EQUAL(&imm->i6mm_maddr->in6m_addr, | |
2598 | &ia)) | 2598 | &ia)) | |
2599 | goto put_break; | 2599 | goto put_break; | |
2600 | } | 2600 | } | |
2601 | if (imm != NULL) { | 2601 | if (imm != NULL) { | |
2602 | error = EADDRINUSE; | 2602 | error = EADDRINUSE; | |
2603 | goto put_break; | 2603 | goto put_break; | |
2604 | } | 2604 | } | |
2605 | /* | 2605 | /* | |
2606 | * Everything looks good; add a new record to the multicast | 2606 | * Everything looks good; add a new record to the multicast | |
2607 | * address list for the given interface. | 2607 | * address list for the given interface. | |
2608 | */ | 2608 | */ | |
2609 | IFNET_LOCK(ifp); | |||
2609 | imm = in6_joingroup(ifp, &ia, &error, 0); | 2610 | imm = in6_joingroup(ifp, &ia, &error, 0); | |
2611 | IFNET_UNLOCK(ifp); | |||
2610 | if (imm == NULL) | 2612 | if (imm == NULL) | |
2611 | goto put_break; | 2613 | goto put_break; | |
2612 | LIST_INSERT_HEAD(&im6o->im6o_memberships, imm, i6mm_chain); | 2614 | LIST_INSERT_HEAD(&im6o->im6o_memberships, imm, i6mm_chain); | |
2613 | put_break: | 2615 | put_break: | |
2614 | if_put(ifp, &psref); | 2616 | if_put(ifp, &psref); | |
2615 | curlwp_bindx(bound); | 2617 | curlwp_bindx(bound); | |
2616 | break; | 2618 | break; | |
2617 | } | 2619 | } | |
2618 | 2620 | |||
2619 | case IPV6_LEAVE_GROUP: | 2621 | case IPV6_LEAVE_GROUP: { | |
2622 | struct ifnet *in6m_ifp; | |||
2620 | /* | 2623 | /* | |
2621 | * Drop a multicast group membership. | 2624 | * Drop a multicast group membership. | |
2622 | * Group must be a valid IP6 multicast address. | 2625 | * Group must be a valid IP6 multicast address. | |
2623 | */ | 2626 | */ | |
2624 | error = sockopt_get(sopt, &mreq, sizeof(mreq)); | 2627 | error = sockopt_get(sopt, &mreq, sizeof(mreq)); | |
2625 | if (error != 0) | 2628 | if (error != 0) | |
2626 | break; | 2629 | break; | |
2627 | 2630 | |||
2628 | if (IN6_IS_ADDR_V4MAPPED(&mreq.ipv6mr_multiaddr)) { | 2631 | if (IN6_IS_ADDR_V4MAPPED(&mreq.ipv6mr_multiaddr)) { | |
2629 | error = ip_setmoptions(&in6p->in6p_v4moptions, sopt); | 2632 | error = ip_setmoptions(&in6p->in6p_v4moptions, sopt); | |
2630 | break; | 2633 | break; | |
2631 | } | 2634 | } | |
2632 | /* | 2635 | /* | |
@@ -2688,28 +2691,33 @@ ip6_setmoptions(const struct sockopt *so | @@ -2688,28 +2691,33 @@ ip6_setmoptions(const struct sockopt *so | |||
2688 | &mreq.ipv6mr_multiaddr)) | 2691 | &mreq.ipv6mr_multiaddr)) | |
2689 | break; | 2692 | break; | |
2690 | } | 2693 | } | |
2691 | if (imm == NULL) { | 2694 | if (imm == NULL) { | |
2692 | /* Unable to resolve interface */ | 2695 | /* Unable to resolve interface */ | |
2693 | error = EADDRNOTAVAIL; | 2696 | error = EADDRNOTAVAIL; | |
2694 | break; | 2697 | break; | |
2695 | } | 2698 | } | |
2696 | /* | 2699 | /* | |
2697 | * Give up the multicast address record to which the | 2700 | * Give up the multicast address record to which the | |
2698 | * membership points. | 2701 | * membership points. | |
2699 | */ | 2702 | */ | |
2700 | LIST_REMOVE(imm, i6mm_chain); | 2703 | LIST_REMOVE(imm, i6mm_chain); | |
2704 | in6m_ifp = imm->i6mm_maddr->in6m_ifp; | |||
2705 | IFNET_LOCK(in6m_ifp); | |||
2701 | in6_leavegroup(imm); | 2706 | in6_leavegroup(imm); | |
2707 | /* in6m_ifp should not leave thanks to in6p_lock */ | |||
2708 | IFNET_UNLOCK(in6m_ifp); | |||
2702 | break; | 2709 | break; | |
2710 | } | |||
2703 | 2711 | |||
2704 | default: | 2712 | default: | |
2705 | error = EOPNOTSUPP; | 2713 | error = EOPNOTSUPP; | |
2706 | break; | 2714 | break; | |
2707 | } | 2715 | } | |
2708 | 2716 | |||
2709 | /* | 2717 | /* | |
2710 | * If all options have default values, no need to keep the mbuf. | 2718 | * If all options have default values, no need to keep the mbuf. | |
2711 | */ | 2719 | */ | |
2712 | if (im6o->im6o_multicast_if_index == 0 && | 2720 | if (im6o->im6o_multicast_if_index == 0 && | |
2713 | im6o->im6o_multicast_hlim == ip6_defmcasthlim && | 2721 | im6o->im6o_multicast_hlim == ip6_defmcasthlim && | |
2714 | im6o->im6o_multicast_loop == IPV6_DEFAULT_MULTICAST_LOOP && | 2722 | im6o->im6o_multicast_loop == IPV6_DEFAULT_MULTICAST_LOOP && | |
2715 | LIST_EMPTY(&im6o->im6o_memberships)) { | 2723 | LIST_EMPTY(&im6o->im6o_memberships)) { | |
@@ -2768,28 +2776,35 @@ ip6_getmoptions(struct sockopt *sopt, st | @@ -2768,28 +2776,35 @@ ip6_getmoptions(struct sockopt *sopt, st | |||
2768 | /* | 2776 | /* | |
2769 | * Discard the IP6 multicast options. | 2777 | * Discard the IP6 multicast options. | |
2770 | */ | 2778 | */ | |
2771 | void | 2779 | void | |
2772 | ip6_freemoptions(struct ip6_moptions *im6o) | 2780 | ip6_freemoptions(struct ip6_moptions *im6o) | |
2773 | { | 2781 | { | |
2774 | struct in6_multi_mship *imm, *nimm; | 2782 | struct in6_multi_mship *imm, *nimm; | |
2775 | 2783 | |||
2776 | if (im6o == NULL) | 2784 | if (im6o == NULL) | |
2777 | return; | 2785 | return; | |
2778 | 2786 | |||
2779 | /* The owner of im6o (in6p) should be protected by solock */ | 2787 | /* The owner of im6o (in6p) should be protected by solock */ | |
2780 | LIST_FOREACH_SAFE(imm, &im6o->im6o_memberships, i6mm_chain, nimm) { | 2788 | LIST_FOREACH_SAFE(imm, &im6o->im6o_memberships, i6mm_chain, nimm) { | |
2789 | struct ifnet *ifp; | |||
2790 | ||||
2781 | LIST_REMOVE(imm, i6mm_chain); | 2791 | LIST_REMOVE(imm, i6mm_chain); | |
2792 | ||||
2793 | ifp = imm->i6mm_maddr->in6m_ifp; | |||
2794 | IFNET_LOCK(ifp); | |||
2782 | in6_leavegroup(imm); | 2795 | in6_leavegroup(imm); | |
2796 | /* ifp should not leave thanks to solock */ | |||
2797 | IFNET_UNLOCK(ifp); | |||
2783 | } | 2798 | } | |
2784 | free(im6o, M_IPMOPTS); | 2799 | free(im6o, M_IPMOPTS); | |
2785 | } | 2800 | } | |
2786 | 2801 | |||
2787 | /* | 2802 | /* | |
2788 | * Set IPv6 outgoing packet options based on advanced API. | 2803 | * Set IPv6 outgoing packet options based on advanced API. | |
2789 | */ | 2804 | */ | |
2790 | int | 2805 | int | |
2791 | ip6_setpktopts(struct mbuf *control, struct ip6_pktopts *opt, | 2806 | ip6_setpktopts(struct mbuf *control, struct ip6_pktopts *opt, | |
2792 | struct ip6_pktopts *stickyopt, kauth_cred_t cred, int uproto) | 2807 | struct ip6_pktopts *stickyopt, kauth_cred_t cred, int uproto) | |
2793 | { | 2808 | { | |
2794 | struct cmsghdr *cm = 0; | 2809 | struct cmsghdr *cm = 0; | |
2795 | 2810 |
--- src/sys/netinet6/mld6.c 2017/05/13 20:13:26 1.89
+++ src/sys/netinet6/mld6.c 2018/01/02 10:20:34 1.89.2.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: mld6.c,v 1.89 2017/05/13 20:13:26 kardel Exp $ */ | 1 | /* $NetBSD: mld6.c,v 1.89.2.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $ */ | 2 | /* $KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1998 WIDE Project. | 5 | * Copyright (C) 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -92,27 +92,27 @@ | @@ -92,27 +92,27 @@ | |||
92 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 92 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
93 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 93 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
94 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 94 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
95 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 95 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
96 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 96 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
97 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 97 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
98 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 98 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
99 | * SUCH DAMAGE. | 99 | * SUCH DAMAGE. | |
100 | * | 100 | * | |
101 | * @(#)igmp.c 8.1 (Berkeley) 7/19/93 | 101 | * @(#)igmp.c 8.1 (Berkeley) 7/19/93 | |
102 | */ | 102 | */ | |
103 | 103 | |||
104 | #include <sys/cdefs.h> | 104 | #include <sys/cdefs.h> | |
105 | __KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.89 2017/05/13 20:13:26 kardel Exp $"); | 105 | __KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.89.2.1 2018/01/02 10:20:34 snj Exp $"); | |
106 | 106 | |||
107 | #ifdef _KERNEL_OPT | 107 | #ifdef _KERNEL_OPT | |
108 | #include "opt_inet.h" | 108 | #include "opt_inet.h" | |
109 | #include "opt_net_mpsafe.h" | 109 | #include "opt_net_mpsafe.h" | |
110 | #endif | 110 | #endif | |
111 | 111 | |||
112 | #include <sys/param.h> | 112 | #include <sys/param.h> | |
113 | #include <sys/systm.h> | 113 | #include <sys/systm.h> | |
114 | #include <sys/mbuf.h> | 114 | #include <sys/mbuf.h> | |
115 | #include <sys/socket.h> | 115 | #include <sys/socket.h> | |
116 | #include <sys/socketvar.h> | 116 | #include <sys/socketvar.h> | |
117 | #include <sys/syslog.h> | 117 | #include <sys/syslog.h> | |
118 | #include <sys/sysctl.h> | 118 | #include <sys/sysctl.h> | |
@@ -232,53 +232,45 @@ mld_stoptimer(struct in6_multi *in6m) | @@ -232,53 +232,45 @@ mld_stoptimer(struct in6_multi *in6m) | |||
232 | 232 | |||
233 | rw_enter(&in6_multilock, RW_WRITER); | 233 | rw_enter(&in6_multilock, RW_WRITER); | |
234 | 234 | |||
235 | in6m->in6m_timer = IN6M_TIMER_UNDEF; | 235 | in6m->in6m_timer = IN6M_TIMER_UNDEF; | |
236 | } | 236 | } | |
237 | 237 | |||
238 | static void | 238 | static void | |
239 | mld_timeo(void *arg) | 239 | mld_timeo(void *arg) | |
240 | { | 240 | { | |
241 | struct in6_multi *in6m = arg; | 241 | struct in6_multi *in6m = arg; | |
242 | 242 | |||
243 | KASSERT(in6m->in6m_refcount > 0); | 243 | KASSERT(in6m->in6m_refcount > 0); | |
244 | 244 | |||
245 | #ifndef NET_MPSAFE | 245 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
246 | mutex_enter(softnet_lock); | |||
247 | KERNEL_LOCK(1, NULL); | |||
248 | #endif | |||
249 | rw_enter(&in6_multilock, RW_WRITER); | 246 | rw_enter(&in6_multilock, RW_WRITER); | |
250 | if (in6m->in6m_timer == IN6M_TIMER_UNDEF) | 247 | if (in6m->in6m_timer == IN6M_TIMER_UNDEF) | |
251 | goto out; | 248 | goto out; | |
252 | 249 | |||
253 | in6m->in6m_timer = IN6M_TIMER_UNDEF; | 250 | in6m->in6m_timer = IN6M_TIMER_UNDEF; | |
254 | 251 | |||
255 | switch (in6m->in6m_state) { | 252 | switch (in6m->in6m_state) { | |
256 | case MLD_REPORTPENDING: | 253 | case MLD_REPORTPENDING: | |
257 | mld_start_listening(in6m); | 254 | mld_start_listening(in6m); | |
258 | break; | 255 | break; | |
259 | default: | 256 | default: | |
260 | mld_sendpkt(in6m, MLD_LISTENER_REPORT, NULL); | 257 | mld_sendpkt(in6m, MLD_LISTENER_REPORT, NULL); | |
261 | break; | 258 | break; | |
262 | } | 259 | } | |
263 | 260 | |||
264 | out: | 261 | out: | |
265 | rw_exit(&in6_multilock); | 262 | rw_exit(&in6_multilock); | |
266 | #ifndef NET_MPSAFE | 263 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
267 | KERNEL_UNLOCK_ONE(NULL); | |||
268 | mutex_exit(softnet_lock); | |||
269 | #else | |||
270 | return; | |||
271 | #endif | |||
272 | } | 264 | } | |
273 | 265 | |||
274 | static u_long | 266 | static u_long | |
275 | mld_timerresid(struct in6_multi *in6m) | 267 | mld_timerresid(struct in6_multi *in6m) | |
276 | { | 268 | { | |
277 | struct timeval now, diff; | 269 | struct timeval now, diff; | |
278 | 270 | |||
279 | microtime(&now); | 271 | microtime(&now); | |
280 | 272 | |||
281 | if (now.tv_sec > in6m->in6m_timer_expire.tv_sec || | 273 | if (now.tv_sec > in6m->in6m_timer_expire.tv_sec || | |
282 | (now.tv_sec == in6m->in6m_timer_expire.tv_sec && | 274 | (now.tv_sec == in6m->in6m_timer_expire.tv_sec && | |
283 | now.tv_usec > in6m->in6m_timer_expire.tv_usec)) { | 275 | now.tv_usec > in6m->in6m_timer_expire.tv_usec)) { | |
284 | return (0); | 276 | return (0); |
--- src/sys/netinet6/nd6.c 2017/11/17 20:26:19 1.232.2.4
+++ src/sys/netinet6/nd6.c 2018/01/02 10:20:34 1.232.2.5
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nd6.c,v 1.232.2.4 2017/11/17 20:26:19 snj Exp $ */ | 1 | /* $NetBSD: nd6.c,v 1.232.2.5 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $ */ | 2 | /* $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -21,27 +21,27 @@ | @@ -21,27 +21,27 @@ | |||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | * SUCH DAMAGE. | 30 | * SUCH DAMAGE. | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | #include <sys/cdefs.h> | 33 | #include <sys/cdefs.h> | |
34 | __KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.232.2.4 2017/11/17 20:26:19 snj Exp $"); | 34 | __KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.232.2.5 2018/01/02 10:20:34 snj Exp $"); | |
35 | 35 | |||
36 | #ifdef _KERNEL_OPT | 36 | #ifdef _KERNEL_OPT | |
37 | #include "opt_net_mpsafe.h" | 37 | #include "opt_net_mpsafe.h" | |
38 | #endif | 38 | #endif | |
39 | 39 | |||
40 | #include "bridge.h" | 40 | #include "bridge.h" | |
41 | #include "carp.h" | 41 | #include "carp.h" | |
42 | 42 | |||
43 | #include <sys/param.h> | 43 | #include <sys/param.h> | |
44 | #include <sys/systm.h> | 44 | #include <sys/systm.h> | |
45 | #include <sys/callout.h> | 45 | #include <sys/callout.h> | |
46 | #include <sys/kmem.h> | 46 | #include <sys/kmem.h> | |
47 | #include <sys/mbuf.h> | 47 | #include <sys/mbuf.h> | |
@@ -440,30 +440,27 @@ nd6_llinfo_get_holdsrc(struct llentry *l | @@ -440,30 +440,27 @@ nd6_llinfo_get_holdsrc(struct llentry *l | |||
440 | 440 | |||
441 | return src; | 441 | return src; | |
442 | } | 442 | } | |
443 | 443 | |||
444 | static void | 444 | static void | |
445 | nd6_llinfo_timer(void *arg) | 445 | nd6_llinfo_timer(void *arg) | |
446 | { | 446 | { | |
447 | struct llentry *ln = arg; | 447 | struct llentry *ln = arg; | |
448 | struct ifnet *ifp; | 448 | struct ifnet *ifp; | |
449 | struct nd_ifinfo *ndi = NULL; | 449 | struct nd_ifinfo *ndi = NULL; | |
450 | bool send_ns = false; | 450 | bool send_ns = false; | |
451 | const struct in6_addr *daddr6 = NULL; | 451 | const struct in6_addr *daddr6 = NULL; | |
452 | 452 | |||
453 | #ifndef NET_MPSAFE | 453 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
454 | mutex_enter(softnet_lock); | |||
455 | KERNEL_LOCK(1, NULL); | |||
456 | #endif | |||
457 | LLE_WLOCK(ln); | 454 | LLE_WLOCK(ln); | |
458 | if ((ln->la_flags & LLE_LINKED) == 0) | 455 | if ((ln->la_flags & LLE_LINKED) == 0) | |
459 | goto out; | 456 | goto out; | |
460 | if (ln->ln_ntick > 0) { | 457 | if (ln->ln_ntick > 0) { | |
461 | nd6_llinfo_settimer(ln, ln->ln_ntick); | 458 | nd6_llinfo_settimer(ln, ln->ln_ntick); | |
462 | goto out; | 459 | goto out; | |
463 | } | 460 | } | |
464 | 461 | |||
465 | if (callout_pending(&ln->la_timer)) { | 462 | if (callout_pending(&ln->la_timer)) { | |
466 | /* | 463 | /* | |
467 | * Here we are a bit odd here in the treatment of | 464 | * Here we are a bit odd here in the treatment of | |
468 | * active/pending. If the pending bit is set, it got | 465 | * active/pending. If the pending bit is set, it got | |
469 | * rescheduled before I ran. The active | 466 | * rescheduled before I ran. The active | |
@@ -559,51 +556,45 @@ nd6_llinfo_timer(void *arg) | @@ -559,51 +556,45 @@ nd6_llinfo_timer(void *arg) | |||
559 | struct in6_addr src, *psrc; | 556 | struct in6_addr src, *psrc; | |
560 | const struct in6_addr *taddr6 = &ln->r_l3addr.addr6; | 557 | const struct in6_addr *taddr6 = &ln->r_l3addr.addr6; | |
561 | 558 | |||
562 | nd6_llinfo_settimer(ln, ndi->retrans * hz / 1000); | 559 | nd6_llinfo_settimer(ln, ndi->retrans * hz / 1000); | |
563 | psrc = nd6_llinfo_get_holdsrc(ln, &src); | 560 | psrc = nd6_llinfo_get_holdsrc(ln, &src); | |
564 | LLE_FREE_LOCKED(ln); | 561 | LLE_FREE_LOCKED(ln); | |
565 | ln = NULL; | 562 | ln = NULL; | |
566 | nd6_ns_output(ifp, daddr6, taddr6, psrc, 0); | 563 | nd6_ns_output(ifp, daddr6, taddr6, psrc, 0); | |
567 | } | 564 | } | |
568 | 565 | |||
569 | out: | 566 | out: | |
570 | if (ln != NULL) | 567 | if (ln != NULL) | |
571 | LLE_FREE_LOCKED(ln); | 568 | LLE_FREE_LOCKED(ln); | |
572 | #ifndef NET_MPSAFE | 569 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
573 | KERNEL_UNLOCK_ONE(NULL); | |||
574 | mutex_exit(softnet_lock); | |||
575 | #endif | |||
576 | } | 570 | } | |
577 | 571 | |||
578 | /* | 572 | /* | |
579 | * ND6 timer routine to expire default route list and prefix list | 573 | * ND6 timer routine to expire default route list and prefix list | |
580 | */ | 574 | */ | |
581 | static void | 575 | static void | |
582 | nd6_timer_work(struct work *wk, void *arg) | 576 | nd6_timer_work(struct work *wk, void *arg) | |
583 | { | 577 | { | |
584 | struct nd_defrouter *next_dr, *dr; | 578 | struct nd_defrouter *next_dr, *dr; | |
585 | struct nd_prefix *next_pr, *pr; | 579 | struct nd_prefix *next_pr, *pr; | |
586 | struct in6_ifaddr *ia6, *nia6; | 580 | struct in6_ifaddr *ia6, *nia6; | |
587 | int s, bound; | 581 | int s, bound; | |
588 | struct psref psref; | 582 | struct psref psref; | |
589 | 583 | |||
590 | callout_reset(&nd6_timer_ch, nd6_prune * hz, | 584 | callout_reset(&nd6_timer_ch, nd6_prune * hz, | |
591 | nd6_timer, NULL); | 585 | nd6_timer, NULL); | |
592 | 586 | |||
593 | #ifndef NET_MPSAFE | 587 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
594 | mutex_enter(softnet_lock); | |||
595 | KERNEL_LOCK(1, NULL); | |||
596 | #endif | |||
597 | 588 | |||
598 | /* expire default router list */ | 589 | /* expire default router list */ | |
599 | 590 | |||
600 | ND6_WLOCK(); | 591 | ND6_WLOCK(); | |
601 | ND_DEFROUTER_LIST_FOREACH_SAFE(dr, next_dr) { | 592 | ND_DEFROUTER_LIST_FOREACH_SAFE(dr, next_dr) { | |
602 | if (dr->expire && dr->expire < time_uptime) { | 593 | if (dr->expire && dr->expire < time_uptime) { | |
603 | nd6_defrtrlist_del(dr, NULL); | 594 | nd6_defrtrlist_del(dr, NULL); | |
604 | } | 595 | } | |
605 | } | 596 | } | |
606 | ND6_UNLOCK(); | 597 | ND6_UNLOCK(); | |
607 | 598 | |||
608 | /* | 599 | /* | |
609 | * expire interface addresses. | 600 | * expire interface addresses. | |
@@ -613,46 +604,64 @@ nd6_timer_work(struct work *wk, void *ar | @@ -613,46 +604,64 @@ nd6_timer_work(struct work *wk, void *ar | |||
613 | */ | 604 | */ | |
614 | bound = curlwp_bind(); | 605 | bound = curlwp_bind(); | |
615 | addrloop: | 606 | addrloop: | |
616 | s = pserialize_read_enter(); | 607 | s = pserialize_read_enter(); | |
617 | for (ia6 = IN6_ADDRLIST_READER_FIRST(); ia6; ia6 = nia6) { | 608 | for (ia6 = IN6_ADDRLIST_READER_FIRST(); ia6; ia6 = nia6) { | |
618 | nia6 = IN6_ADDRLIST_READER_NEXT(ia6); | 609 | nia6 = IN6_ADDRLIST_READER_NEXT(ia6); | |
619 | 610 | |||
620 | ia6_acquire(ia6, &psref); | 611 | ia6_acquire(ia6, &psref); | |
621 | pserialize_read_exit(s); | 612 | pserialize_read_exit(s); | |
622 | 613 | |||
623 | /* check address lifetime */ | 614 | /* check address lifetime */ | |
624 | if (IFA6_IS_INVALID(ia6)) { | 615 | if (IFA6_IS_INVALID(ia6)) { | |
625 | int regen = 0; | 616 | int regen = 0; | |
617 | struct ifnet *ifp; | |||
626 | 618 | |||
627 | /* | 619 | /* | |
628 | * If the expiring address is temporary, try | 620 | * If the expiring address is temporary, try | |
629 | * regenerating a new one. This would be useful when | 621 | * regenerating a new one. This would be useful when | |
630 | * we suspended a laptop PC, then turned it on after a | 622 | * we suspended a laptop PC, then turned it on after a | |
631 | * period that could invalidate all temporary | 623 | * period that could invalidate all temporary | |
632 | * addresses. Although we may have to restart the | 624 | * addresses. Although we may have to restart the | |
633 | * loop (see below), it must be after purging the | 625 | * loop (see below), it must be after purging the | |
634 | * address. Otherwise, we'd see an infinite loop of | 626 | * address. Otherwise, we'd see an infinite loop of | |
635 | * regeneration. | 627 | * regeneration. | |
636 | */ | 628 | */ | |
637 | if (ip6_use_tempaddr && | 629 | if (ip6_use_tempaddr && | |
638 | (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0) { | 630 | (ia6->ia6_flags & IN6_IFF_TEMPORARY) != 0) { | |
631 | IFNET_LOCK(ia6->ia_ifa.ifa_ifp); | |||
639 | if (regen_tmpaddr(ia6) == 0) | 632 | if (regen_tmpaddr(ia6) == 0) | |
640 | regen = 1; | 633 | regen = 1; | |
634 | IFNET_UNLOCK(ia6->ia_ifa.ifa_ifp); | |||
641 | } | 635 | } | |
642 | 636 | |||
643 | ia6_release(ia6, &psref); | 637 | ifp = ia6->ia_ifa.ifa_ifp; | |
644 | in6_purgeaddr(&ia6->ia_ifa); | 638 | IFNET_LOCK(ifp); | |
639 | /* | |||
640 | * Need to take the lock first to prevent if_detach | |||
641 | * from running in6_purgeaddr concurrently. | |||
642 | */ | |||
643 | if (!if_is_deactivated(ifp)) { | |||
644 | ia6_release(ia6, &psref); | |||
645 | in6_purgeaddr(&ia6->ia_ifa); | |||
646 | } else { | |||
647 | /* | |||
648 | * ifp is being destroyed, ia6 will be destroyed | |||
649 | * by if_detach. | |||
650 | */ | |||
651 | ia6_release(ia6, &psref); | |||
652 | } | |||
645 | ia6 = NULL; | 653 | ia6 = NULL; | |
654 | IFNET_UNLOCK(ifp); | |||
646 | 655 | |||
647 | if (regen) | 656 | if (regen) | |
648 | goto addrloop; /* XXX: see below */ | 657 | goto addrloop; /* XXX: see below */ | |
649 | } else if (IFA6_IS_DEPRECATED(ia6)) { | 658 | } else if (IFA6_IS_DEPRECATED(ia6)) { | |
650 | int oldflags = ia6->ia6_flags; | 659 | int oldflags = ia6->ia6_flags; | |
651 | 660 | |||
652 | if ((oldflags & IN6_IFF_DEPRECATED) == 0) { | 661 | if ((oldflags & IN6_IFF_DEPRECATED) == 0) { | |
653 | ia6->ia6_flags |= IN6_IFF_DEPRECATED; | 662 | ia6->ia6_flags |= IN6_IFF_DEPRECATED; | |
654 | rt_newaddrmsg(RTM_NEWADDR, | 663 | rt_newaddrmsg(RTM_NEWADDR, | |
655 | (struct ifaddr *)ia6, 0, NULL); | 664 | (struct ifaddr *)ia6, 0, NULL); | |
656 | } | 665 | } | |
657 | 666 | |||
658 | /* | 667 | /* | |
@@ -707,30 +716,27 @@ nd6_timer_work(struct work *wk, void *ar | @@ -707,30 +716,27 @@ nd6_timer_work(struct work *wk, void *ar | |||
707 | */ | 716 | */ | |
708 | if (pr->ndpr_vltime != ND6_INFINITE_LIFETIME && | 717 | if (pr->ndpr_vltime != ND6_INFINITE_LIFETIME && | |
709 | time_uptime - pr->ndpr_lastupdate > pr->ndpr_vltime) { | 718 | time_uptime - pr->ndpr_lastupdate > pr->ndpr_vltime) { | |
710 | /* | 719 | /* | |
711 | * Just invalidate the prefix here. Removing it | 720 | * Just invalidate the prefix here. Removing it | |
712 | * will be done when purging an associated address. | 721 | * will be done when purging an associated address. | |
713 | */ | 722 | */ | |
714 | KASSERT(pr->ndpr_refcnt > 0); | 723 | KASSERT(pr->ndpr_refcnt > 0); | |
715 | nd6_invalidate_prefix(pr); | 724 | nd6_invalidate_prefix(pr); | |
716 | } | 725 | } | |
717 | } | 726 | } | |
718 | ND6_UNLOCK(); | 727 | ND6_UNLOCK(); | |
719 | 728 | |||
720 | #ifndef NET_MPSAFE | 729 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
721 | KERNEL_UNLOCK_ONE(NULL); | |||
722 | mutex_exit(softnet_lock); | |||
723 | #endif | |||
724 | } | 730 | } | |
725 | 731 | |||
726 | static void | 732 | static void | |
727 | nd6_timer(void *ignored_arg) | 733 | nd6_timer(void *ignored_arg) | |
728 | { | 734 | { | |
729 | 735 | |||
730 | workqueue_enqueue(nd6_timer_wq, &nd6_timer_wk, NULL); | 736 | workqueue_enqueue(nd6_timer_wq, &nd6_timer_wk, NULL); | |
731 | } | 737 | } | |
732 | 738 | |||
733 | /* ia6: deprecated/invalidated temporary address */ | 739 | /* ia6: deprecated/invalidated temporary address */ | |
734 | static int | 740 | static int | |
735 | regen_tmpaddr(const struct in6_ifaddr *ia6) | 741 | regen_tmpaddr(const struct in6_ifaddr *ia6) | |
736 | { | 742 | { | |
@@ -1885,40 +1891,73 @@ nd6_ioctl(u_long cmd, void *data, struct | @@ -1885,40 +1891,73 @@ nd6_ioctl(u_long cmd, void *data, struct | |||
1885 | restart: | 1891 | restart: | |
1886 | ND6_WLOCK(); | 1892 | ND6_WLOCK(); | |
1887 | ND_PREFIX_LIST_FOREACH_SAFE(pfx, next) { | 1893 | ND_PREFIX_LIST_FOREACH_SAFE(pfx, next) { | |
1888 | struct in6_ifaddr *ia, *ia_next; | 1894 | struct in6_ifaddr *ia, *ia_next; | |
1889 | int _s; | 1895 | int _s; | |
1890 | 1896 | |||
1891 | if (IN6_IS_ADDR_LINKLOCAL(&pfx->ndpr_prefix.sin6_addr)) | 1897 | if (IN6_IS_ADDR_LINKLOCAL(&pfx->ndpr_prefix.sin6_addr)) | |
1892 | continue; /* XXX */ | 1898 | continue; /* XXX */ | |
1893 | 1899 | |||
1894 | /* do we really have to remove addresses as well? */ | 1900 | /* do we really have to remove addresses as well? */ | |
1895 | _s = pserialize_read_enter(); | 1901 | _s = pserialize_read_enter(); | |
1896 | for (ia = IN6_ADDRLIST_READER_FIRST(); ia; | 1902 | for (ia = IN6_ADDRLIST_READER_FIRST(); ia; | |
1897 | ia = ia_next) { | 1903 | ia = ia_next) { | |
1904 | struct ifnet *ifa_ifp; | |||
1905 | int bound; | |||
1906 | struct psref psref; | |||
1907 | ||||
1898 | /* ia might be removed. keep the next ptr. */ | 1908 | /* ia might be removed. keep the next ptr. */ | |
1899 | ia_next = IN6_ADDRLIST_READER_NEXT(ia); | 1909 | ia_next = IN6_ADDRLIST_READER_NEXT(ia); | |
1900 | 1910 | |||
1901 | if ((ia->ia6_flags & IN6_IFF_AUTOCONF) == 0) | 1911 | if ((ia->ia6_flags & IN6_IFF_AUTOCONF) == 0) | |
1902 | continue; | 1912 | continue; | |
1903 | 1913 | |||
1904 | if (ia->ia6_ndpr == pfx) { | 1914 | if (ia->ia6_ndpr != pfx) | |
1905 | pserialize_read_exit(_s); | 1915 | continue; | |
1906 | ND6_UNLOCK(); | 1916 | ||
1907 | /* XXX NOMPSAFE? */ | 1917 | bound = curlwp_bind(); | |
1908 | /* in6_purgeaddr may destroy pfx. */ | 1918 | ia6_acquire(ia, &psref); | |
1919 | pserialize_read_exit(_s); | |||
1920 | ND6_UNLOCK(); | |||
1921 | ||||
1922 | ifa_ifp = ia->ia_ifa.ifa_ifp; | |||
1923 | if (ifa_ifp == ifp) { | |||
1924 | /* Already have IFNET_LOCK(ifp) */ | |||
1925 | KASSERT(!if_is_deactivated(ifp)); | |||
1926 | ia6_release(ia, &psref); | |||
1909 | in6_purgeaddr(&ia->ia_ifa); | 1927 | in6_purgeaddr(&ia->ia_ifa); | |
1928 | curlwp_bindx(bound); | |||
1910 | goto restart; | 1929 | goto restart; | |
1911 | } | 1930 | } | |
1931 | IFNET_LOCK(ifa_ifp); | |||
1932 | /* | |||
1933 | * Need to take the lock first to prevent | |||
1934 | * if_detach from running in6_purgeaddr | |||
1935 | * concurrently. | |||
1936 | */ | |||
1937 | if (!if_is_deactivated(ifa_ifp)) { | |||
1938 | ia6_release(ia, &psref); | |||
1939 | in6_purgeaddr(&ia->ia_ifa); | |||
1940 | } else { | |||
1941 | /* | |||
1942 | * ifp is being destroyed, ia will be | |||
1943 | * destroyed by if_detach. | |||
1944 | */ | |||
1945 | ia6_release(ia, &psref); | |||
1946 | /* XXX may cause busy loop */ | |||
1947 | } | |||
1948 | IFNET_UNLOCK(ifa_ifp); | |||
1949 | curlwp_bindx(bound); | |||
1950 | goto restart; | |||
1912 | } | 1951 | } | |
1913 | pserialize_read_exit(_s); | 1952 | pserialize_read_exit(_s); | |
1914 | 1953 | |||
1915 | KASSERT(pfx->ndpr_refcnt == 0); | 1954 | KASSERT(pfx->ndpr_refcnt == 0); | |
1916 | nd6_prelist_remove(pfx); | 1955 | nd6_prelist_remove(pfx); | |
1917 | } | 1956 | } | |
1918 | ND6_UNLOCK(); | 1957 | ND6_UNLOCK(); | |
1919 | break; | 1958 | break; | |
1920 | } | 1959 | } | |
1921 | case SIOCSRTRFLUSH_IN6: | 1960 | case SIOCSRTRFLUSH_IN6: | |
1922 | { | 1961 | { | |
1923 | /* flush all the default routers */ | 1962 | /* flush all the default routers */ | |
1924 | struct nd_defrouter *drtr, *next; | 1963 | struct nd_defrouter *drtr, *next; | |
@@ -2218,54 +2257,48 @@ nd6_cache_lladdr( | @@ -2218,54 +2257,48 @@ nd6_cache_lladdr( | |||
2218 | ND6_WLOCK(); | 2257 | ND6_WLOCK(); | |
2219 | nd6_defrouter_select(); | 2258 | nd6_defrouter_select(); | |
2220 | ND6_UNLOCK(); | 2259 | ND6_UNLOCK(); | |
2221 | } | 2260 | } | |
2222 | } | 2261 | } | |
2223 | 2262 | |||
2224 | static void | 2263 | static void | |
2225 | nd6_slowtimo(void *ignored_arg) | 2264 | nd6_slowtimo(void *ignored_arg) | |
2226 | { | 2265 | { | |
2227 | struct nd_ifinfo *nd6if; | 2266 | struct nd_ifinfo *nd6if; | |
2228 | struct ifnet *ifp; | 2267 | struct ifnet *ifp; | |
2229 | int s; | 2268 | int s; | |
2230 | 2269 | |||
2231 | #ifndef NET_MPSAFE | 2270 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
2232 | mutex_enter(softnet_lock); | |||
2233 | KERNEL_LOCK(1, NULL); | |||
2234 | #endif | |||
2235 | callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz, | 2271 | callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz, | |
2236 | nd6_slowtimo, NULL); | 2272 | nd6_slowtimo, NULL); | |
2237 | 2273 | |||
2238 | s = pserialize_read_enter(); | 2274 | s = pserialize_read_enter(); | |
2239 | IFNET_READER_FOREACH(ifp) { | 2275 | IFNET_READER_FOREACH(ifp) { | |
2240 | nd6if = ND_IFINFO(ifp); | 2276 | nd6if = ND_IFINFO(ifp); | |
2241 | if (nd6if->basereachable && /* already initialized */ | 2277 | if (nd6if->basereachable && /* already initialized */ | |
2242 | (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) { | 2278 | (nd6if->recalctm -= ND6_SLOWTIMER_INTERVAL) <= 0) { | |
2243 | /* | 2279 | /* | |
2244 | * Since reachable time rarely changes by router | 2280 | * Since reachable time rarely changes by router | |
2245 | * advertisements, we SHOULD insure that a new random | 2281 | * advertisements, we SHOULD insure that a new random | |
2246 | * value gets recomputed at least once every few hours. | 2282 | * value gets recomputed at least once every few hours. | |
2247 | * (RFC 2461, 6.3.4) | 2283 | * (RFC 2461, 6.3.4) | |
2248 | */ | 2284 | */ | |
2249 | nd6if->recalctm = nd6_recalc_reachtm_interval; | 2285 | nd6if->recalctm = nd6_recalc_reachtm_interval; | |
2250 | nd6if->reachable = ND_COMPUTE_RTIME(nd6if->basereachable); | 2286 | nd6if->reachable = ND_COMPUTE_RTIME(nd6if->basereachable); | |
2251 | } | 2287 | } | |
2252 | } | 2288 | } | |
2253 | pserialize_read_exit(s); | 2289 | pserialize_read_exit(s); | |
2254 | 2290 | |||
2255 | #ifndef NET_MPSAFE | 2291 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
2256 | KERNEL_UNLOCK_ONE(NULL); | |||
2257 | mutex_exit(softnet_lock); | |||
2258 | #endif | |||
2259 | } | 2292 | } | |
2260 | 2293 | |||
2261 | /* | 2294 | /* | |
2262 | * Return 0 if a neighbor cache is found. Return EWOULDBLOCK if a cache is not | 2295 | * Return 0 if a neighbor cache is found. Return EWOULDBLOCK if a cache is not | |
2263 | * found and trying to resolve a neighbor; in this case the mbuf is queued in | 2296 | * found and trying to resolve a neighbor; in this case the mbuf is queued in | |
2264 | * the list. Otherwise return errno after freeing the mbuf. | 2297 | * the list. Otherwise return errno after freeing the mbuf. | |
2265 | */ | 2298 | */ | |
2266 | int | 2299 | int | |
2267 | nd6_resolve(struct ifnet *ifp, const struct rtentry *rt, struct mbuf *m, | 2300 | nd6_resolve(struct ifnet *ifp, const struct rtentry *rt, struct mbuf *m, | |
2268 | const struct sockaddr *_dst, uint8_t *lldst, size_t dstsize) | 2301 | const struct sockaddr *_dst, uint8_t *lldst, size_t dstsize) | |
2269 | { | 2302 | { | |
2270 | struct llentry *ln = NULL; | 2303 | struct llentry *ln = NULL; | |
2271 | bool created = false; | 2304 | bool created = false; |
--- src/sys/netinet6/nd6_nbr.c 2017/03/14 04:25:10 1.138
+++ src/sys/netinet6/nd6_nbr.c 2018/01/02 10:20:34 1.138.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nd6_nbr.c,v 1.138 2017/03/14 04:25:10 ozaki-r Exp $ */ | 1 | /* $NetBSD: nd6_nbr.c,v 1.138.6.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */ | 2 | /* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -21,27 +21,27 @@ | @@ -21,27 +21,27 @@ | |||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | * SUCH DAMAGE. | 30 | * SUCH DAMAGE. | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | #include <sys/cdefs.h> | 33 | #include <sys/cdefs.h> | |
34 | __KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.138 2017/03/14 04:25:10 ozaki-r Exp $"); | 34 | __KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.138.6.1 2018/01/02 10:20:34 snj Exp $"); | |
35 | 35 | |||
36 | #ifdef _KERNEL_OPT | 36 | #ifdef _KERNEL_OPT | |
37 | #include "opt_inet.h" | 37 | #include "opt_inet.h" | |
38 | #include "opt_net_mpsafe.h" | 38 | #include "opt_net_mpsafe.h" | |
39 | #endif | 39 | #endif | |
40 | 40 | |||
41 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
42 | #include <sys/systm.h> | 42 | #include <sys/systm.h> | |
43 | #include <sys/kmem.h> | 43 | #include <sys/kmem.h> | |
44 | #include <sys/mbuf.h> | 44 | #include <sys/mbuf.h> | |
45 | #include <sys/socket.h> | 45 | #include <sys/socket.h> | |
46 | #include <sys/socketvar.h> | 46 | #include <sys/socketvar.h> | |
47 | #include <sys/sockio.h> | 47 | #include <sys/sockio.h> | |
@@ -1218,30 +1218,27 @@ nd6_dad_stop(struct ifaddr *ifa) | @@ -1218,30 +1218,27 @@ nd6_dad_stop(struct ifaddr *ifa) | |||
1218 | kmem_intr_free(dp, sizeof(*dp)); | 1218 | kmem_intr_free(dp, sizeof(*dp)); | |
1219 | ifafree(ifa); | 1219 | ifafree(ifa); | |
1220 | } | 1220 | } | |
1221 | 1221 | |||
1222 | static void | 1222 | static void | |
1223 | nd6_dad_timer(struct ifaddr *ifa) | 1223 | nd6_dad_timer(struct ifaddr *ifa) | |
1224 | { | 1224 | { | |
1225 | struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa; | 1225 | struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa; | |
1226 | struct dadq *dp; | 1226 | struct dadq *dp; | |
1227 | int duplicate = 0; | 1227 | int duplicate = 0; | |
1228 | char ip6buf[INET6_ADDRSTRLEN]; | 1228 | char ip6buf[INET6_ADDRSTRLEN]; | |
1229 | bool need_free = false; | 1229 | bool need_free = false; | |
1230 | 1230 | |||
1231 | #ifndef NET_MPSAFE | 1231 | SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
1232 | mutex_enter(softnet_lock); | |||
1233 | KERNEL_LOCK(1, NULL); | |||
1234 | #endif | |||
1235 | mutex_enter(&nd6_dad_lock); | 1232 | mutex_enter(&nd6_dad_lock); | |
1236 | 1233 | |||
1237 | /* Sanity check */ | 1234 | /* Sanity check */ | |
1238 | if (ia == NULL) { | 1235 | if (ia == NULL) { | |
1239 | log(LOG_ERR, "nd6_dad_timer: called with null parameter\n"); | 1236 | log(LOG_ERR, "nd6_dad_timer: called with null parameter\n"); | |
1240 | goto done; | 1237 | goto done; | |
1241 | } | 1238 | } | |
1242 | dp = nd6_dad_find(ifa); | 1239 | dp = nd6_dad_find(ifa); | |
1243 | if (dp == NULL) { | 1240 | if (dp == NULL) { | |
1244 | /* DAD seems to be stopping, so do nothing. */ | 1241 | /* DAD seems to be stopping, so do nothing. */ | |
1245 | goto done; | 1242 | goto done; | |
1246 | } | 1243 | } | |
1247 | if (ia->ia6_flags & IN6_IFF_DUPLICATED) { | 1244 | if (ia->ia6_flags & IN6_IFF_DUPLICATED) { | |
@@ -1317,30 +1314,27 @@ nd6_dad_timer(struct ifaddr *ifa) | @@ -1317,30 +1314,27 @@ nd6_dad_timer(struct ifaddr *ifa) | |||
1317 | } | 1314 | } | |
1318 | done: | 1315 | done: | |
1319 | mutex_exit(&nd6_dad_lock); | 1316 | mutex_exit(&nd6_dad_lock); | |
1320 | 1317 | |||
1321 | if (need_free) { | 1318 | if (need_free) { | |
1322 | kmem_intr_free(dp, sizeof(*dp)); | 1319 | kmem_intr_free(dp, sizeof(*dp)); | |
1323 | ifafree(ifa); | 1320 | ifafree(ifa); | |
1324 | ifa = NULL; | 1321 | ifa = NULL; | |
1325 | } | 1322 | } | |
1326 | 1323 | |||
1327 | if (duplicate) | 1324 | if (duplicate) | |
1328 | nd6_dad_duplicated(ifa); | 1325 | nd6_dad_duplicated(ifa); | |
1329 | 1326 | |||
1330 | #ifndef NET_MPSAFE | 1327 | SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
1331 | KERNEL_UNLOCK_ONE(NULL); | |||
1332 | mutex_exit(softnet_lock); | |||
1333 | #endif | |||
1334 | } | 1328 | } | |
1335 | 1329 | |||
1336 | static void | 1330 | static void | |
1337 | nd6_dad_duplicated(struct ifaddr *ifa) | 1331 | nd6_dad_duplicated(struct ifaddr *ifa) | |
1338 | { | 1332 | { | |
1339 | struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa; | 1333 | struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa; | |
1340 | struct ifnet *ifp; | 1334 | struct ifnet *ifp; | |
1341 | struct dadq *dp; | 1335 | struct dadq *dp; | |
1342 | char ip6buf[INET6_ADDRSTRLEN]; | 1336 | char ip6buf[INET6_ADDRSTRLEN]; | |
1343 | 1337 | |||
1344 | mutex_enter(&nd6_dad_lock); | 1338 | mutex_enter(&nd6_dad_lock); | |
1345 | dp = nd6_dad_find(ifa); | 1339 | dp = nd6_dad_find(ifa); | |
1346 | if (dp == NULL) { | 1340 | if (dp == NULL) { |
--- src/sys/netinet6/nd6_rtr.c 2017/03/14 04:21:38 1.135
+++ src/sys/netinet6/nd6_rtr.c 2018/01/02 10:20:34 1.135.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nd6_rtr.c,v 1.135 2017/03/14 04:21:38 ozaki-r Exp $ */ | 1 | /* $NetBSD: nd6_rtr.c,v 1.135.6.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | /* $KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $ */ | 2 | /* $KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -21,27 +21,27 @@ | @@ -21,27 +21,27 @@ | |||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | * SUCH DAMAGE. | 30 | * SUCH DAMAGE. | |
31 | */ | 31 | */ | |
32 | 32 | |||
33 | #include <sys/cdefs.h> | 33 | #include <sys/cdefs.h> | |
34 | __KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.135 2017/03/14 04:21:38 ozaki-r Exp $"); | 34 | __KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.135.6.1 2018/01/02 10:20:34 snj Exp $"); | |
35 | 35 | |||
36 | #ifdef _KERNEL_OPT | 36 | #ifdef _KERNEL_OPT | |
37 | #include "opt_net_mpsafe.h" | 37 | #include "opt_net_mpsafe.h" | |
38 | #endif | 38 | #endif | |
39 | 39 | |||
40 | #include <sys/param.h> | 40 | #include <sys/param.h> | |
41 | #include <sys/systm.h> | 41 | #include <sys/systm.h> | |
42 | #include <sys/malloc.h> | 42 | #include <sys/malloc.h> | |
43 | #include <sys/mbuf.h> | 43 | #include <sys/mbuf.h> | |
44 | #include <sys/socket.h> | 44 | #include <sys/socket.h> | |
45 | #include <sys/sockio.h> | 45 | #include <sys/sockio.h> | |
46 | #include <sys/time.h> | 46 | #include <sys/time.h> | |
47 | #include <sys/kernel.h> | 47 | #include <sys/kernel.h> | |
@@ -309,26 +309,27 @@ nd6_ra_input(struct mbuf *m, int off, in | @@ -309,26 +309,27 @@ nd6_ra_input(struct mbuf *m, int off, in | |||
309 | } | 309 | } | |
310 | } | 310 | } | |
311 | if (nd_ra->nd_ra_retransmit) | 311 | if (nd_ra->nd_ra_retransmit) | |
312 | ndi->retrans = ntohl(nd_ra->nd_ra_retransmit); | 312 | ndi->retrans = ntohl(nd_ra->nd_ra_retransmit); | |
313 | if (nd_ra->nd_ra_curhoplimit) { | 313 | if (nd_ra->nd_ra_curhoplimit) { | |
314 | if (ndi->chlim < nd_ra->nd_ra_curhoplimit) | 314 | if (ndi->chlim < nd_ra->nd_ra_curhoplimit) | |
315 | ndi->chlim = nd_ra->nd_ra_curhoplimit; | 315 | ndi->chlim = nd_ra->nd_ra_curhoplimit; | |
316 | else if (ndi->chlim != nd_ra->nd_ra_curhoplimit) | 316 | else if (ndi->chlim != nd_ra->nd_ra_curhoplimit) | |
317 | log(LOG_ERR, "nd_ra_input: lower CurHopLimit sent from " | 317 | log(LOG_ERR, "nd_ra_input: lower CurHopLimit sent from " | |
318 | "%s on %s (current=%d, received=%d), ignored\n", | 318 | "%s on %s (current=%d, received=%d), ignored\n", | |
319 | IN6_PRINT(ip6buf, &ip6->ip6_src), | 319 | IN6_PRINT(ip6buf, &ip6->ip6_src), | |
320 | if_name(ifp), ndi->chlim, nd_ra->nd_ra_curhoplimit); | 320 | if_name(ifp), ndi->chlim, nd_ra->nd_ra_curhoplimit); | |
321 | } | 321 | } | |
322 | IFNET_LOCK(ifp); | |||
322 | ND6_WLOCK(); | 323 | ND6_WLOCK(); | |
323 | dr = defrtrlist_update(&drtr); | 324 | dr = defrtrlist_update(&drtr); | |
324 | } | 325 | } | |
325 | 326 | |||
326 | /* | 327 | /* | |
327 | * prefix | 328 | * prefix | |
328 | */ | 329 | */ | |
329 | if (ndopts.nd_opts_pi) { | 330 | if (ndopts.nd_opts_pi) { | |
330 | struct nd_opt_hdr *pt; | 331 | struct nd_opt_hdr *pt; | |
331 | struct nd_opt_prefix_info *pi = NULL; | 332 | struct nd_opt_prefix_info *pi = NULL; | |
332 | struct nd_prefixctl prc; | 333 | struct nd_prefixctl prc; | |
333 | 334 | |||
334 | for (pt = (struct nd_opt_hdr *)ndopts.nd_opts_pi; | 335 | for (pt = (struct nd_opt_hdr *)ndopts.nd_opts_pi; | |
@@ -368,26 +369,27 @@ nd6_ra_input(struct mbuf *m, int off, in | @@ -368,26 +369,27 @@ nd6_ra_input(struct mbuf *m, int off, in | |||
368 | 369 | |||
369 | prc.ndprc_raf_onlink = (pi->nd_opt_pi_flags_reserved & | 370 | prc.ndprc_raf_onlink = (pi->nd_opt_pi_flags_reserved & | |
370 | ND_OPT_PI_FLAG_ONLINK) ? 1 : 0; | 371 | ND_OPT_PI_FLAG_ONLINK) ? 1 : 0; | |
371 | prc.ndprc_raf_auto = (pi->nd_opt_pi_flags_reserved & | 372 | prc.ndprc_raf_auto = (pi->nd_opt_pi_flags_reserved & | |
372 | ND_OPT_PI_FLAG_AUTO) ? 1 : 0; | 373 | ND_OPT_PI_FLAG_AUTO) ? 1 : 0; | |
373 | prc.ndprc_plen = pi->nd_opt_pi_prefix_len; | 374 | prc.ndprc_plen = pi->nd_opt_pi_prefix_len; | |
374 | prc.ndprc_vltime = ntohl(pi->nd_opt_pi_valid_time); | 375 | prc.ndprc_vltime = ntohl(pi->nd_opt_pi_valid_time); | |
375 | prc.ndprc_pltime = ntohl(pi->nd_opt_pi_preferred_time); | 376 | prc.ndprc_pltime = ntohl(pi->nd_opt_pi_preferred_time); | |
376 | 377 | |||
377 | (void)prelist_update(&prc, dr, m, mcast); | 378 | (void)prelist_update(&prc, dr, m, mcast); | |
378 | } | 379 | } | |
379 | } | 380 | } | |
380 | ND6_UNLOCK(); | 381 | ND6_UNLOCK(); | |
382 | IFNET_UNLOCK(ifp); | |||
381 | 383 | |||
382 | /* | 384 | /* | |
383 | * MTU | 385 | * MTU | |
384 | */ | 386 | */ | |
385 | if (ndopts.nd_opts_mtu && ndopts.nd_opts_mtu->nd_opt_mtu_len == 1) { | 387 | if (ndopts.nd_opts_mtu && ndopts.nd_opts_mtu->nd_opt_mtu_len == 1) { | |
386 | u_long mtu; | 388 | u_long mtu; | |
387 | u_long maxmtu; | 389 | u_long maxmtu; | |
388 | 390 | |||
389 | mtu = ntohl(ndopts.nd_opts_mtu->nd_opt_mtu_mtu); | 391 | mtu = ntohl(ndopts.nd_opts_mtu->nd_opt_mtu_mtu); | |
390 | 392 | |||
391 | /* lower bound */ | 393 | /* lower bound */ | |
392 | if (mtu < IPV6_MMTU) { | 394 | if (mtu < IPV6_MMTU) { | |
393 | nd6log(LOG_INFO, "bogus mtu option " | 395 | nd6log(LOG_INFO, "bogus mtu option " |
--- src/sys/netipsec/ipsec_output.c 2017/10/21 19:43:54 1.48.2.1
+++ src/sys/netipsec/ipsec_output.c 2018/01/02 10:20:34 1.48.2.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: ipsec_output.c,v 1.48.2.1 2017/10/21 19:43:54 snj Exp $ */ | 1 | /* $NetBSD: ipsec_output.c,v 1.48.2.2 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting | 4 | * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting | |
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. | |
@@ -19,27 +19,27 @@ | @@ -19,27 +19,27 @@ | |||
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | 26 | * SUCH DAMAGE. | |
27 | * | 27 | * | |
28 | * $FreeBSD: /repoman/r/ncvs/src/sys/netipsec/ipsec_output.c,v 1.3.2.2 2003/03/28 20:32:53 sam Exp $ | 28 | * $FreeBSD: /repoman/r/ncvs/src/sys/netipsec/ipsec_output.c,v 1.3.2.2 2003/03/28 20:32:53 sam Exp $ | |
29 | */ | 29 | */ | |
30 | 30 | |||
31 | #include <sys/cdefs.h> | 31 | #include <sys/cdefs.h> | |
32 | __KERNEL_RCSID(0, "$NetBSD: ipsec_output.c,v 1.48.2.1 2017/10/21 19:43:54 snj Exp $"); | 32 | __KERNEL_RCSID(0, "$NetBSD: ipsec_output.c,v 1.48.2.2 2018/01/02 10:20:34 snj Exp $"); | |
33 | 33 | |||
34 | /* | 34 | /* | |
35 | * IPsec output processing. | 35 | * IPsec output processing. | |
36 | */ | 36 | */ | |
37 | #if defined(_KERNEL_OPT) | 37 | #if defined(_KERNEL_OPT) | |
38 | #include "opt_inet.h" | 38 | #include "opt_inet.h" | |
39 | #include "opt_net_mpsafe.h" | 39 | #include "opt_net_mpsafe.h" | |
40 | #endif | 40 | #endif | |
41 | 41 | |||
42 | #include <sys/param.h> | 42 | #include <sys/param.h> | |
43 | #include <sys/systm.h> | 43 | #include <sys/systm.h> | |
44 | #include <sys/mbuf.h> | 44 | #include <sys/mbuf.h> | |
45 | #include <sys/domain.h> | 45 | #include <sys/domain.h> | |
@@ -107,51 +107,47 @@ ipsec_register_done(struct mbuf *m, int | @@ -107,51 +107,47 @@ ipsec_register_done(struct mbuf *m, int | |||
107 | 107 | |||
108 | m_tag_prepend(m, mtag); | 108 | m_tag_prepend(m, mtag); | |
109 | return 0; | 109 | return 0; | |
110 | } | 110 | } | |
111 | 111 | |||
112 | static int | 112 | static int | |
113 | ipsec_reinject_ipstack(struct mbuf *m, int af) | 113 | ipsec_reinject_ipstack(struct mbuf *m, int af) | |
114 | { | 114 | { | |
115 | int rv = -1; | 115 | int rv = -1; | |
116 | struct route *ro; | 116 | struct route *ro; | |
117 | 117 | |||
118 | KASSERT(af == AF_INET || af == AF_INET6); | 118 | KASSERT(af == AF_INET || af == AF_INET6); | |
119 | 119 | |||
120 | #ifndef NET_MPSAFE | 120 | KERNEL_LOCK_UNLESS_NET_MPSAFE(); | |
121 | KERNEL_LOCK(1, NULL); | |||
122 | #endif | |||
123 | ro = percpu_getref(ipsec_rtcache_percpu); | 121 | ro = percpu_getref(ipsec_rtcache_percpu); | |
124 | switch (af) { | 122 | switch (af) { | |
125 | #ifdef INET | 123 | #ifdef INET | |
126 | case AF_INET: | 124 | case AF_INET: | |
127 | rv = ip_output(m, NULL, ro, IP_RAWOUTPUT|IP_NOIPNEWID, | 125 | rv = ip_output(m, NULL, ro, IP_RAWOUTPUT|IP_NOIPNEWID, | |
128 | NULL, NULL); | 126 | NULL, NULL); | |
129 | break; | 127 | break; | |
130 | #endif | 128 | #endif | |
131 | #ifdef INET6 | 129 | #ifdef INET6 | |
132 | case AF_INET6: | 130 | case AF_INET6: | |
133 | /* | 131 | /* | |
134 | * We don't need massage, IPv6 header fields are always in | 132 | * We don't need massage, IPv6 header fields are always in | |
135 | * net endian. | 133 | * net endian. | |
136 | */ | 134 | */ | |
137 | rv = ip6_output(m, NULL, ro, 0, NULL, NULL, NULL); | 135 | rv = ip6_output(m, NULL, ro, 0, NULL, NULL, NULL); | |
138 | break; | 136 | break; | |
139 | #endif | 137 | #endif | |
140 | } | 138 | } | |
141 | percpu_putref(ipsec_rtcache_percpu); | 139 | percpu_putref(ipsec_rtcache_percpu); | |
142 | #ifndef NET_MPSAFE | 140 | KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); | |
143 | KERNEL_UNLOCK_ONE(NULL); | |||
144 | #endif | |||
145 | 141 | |||
146 | return rv; | 142 | return rv; | |
147 | } | 143 | } | |
148 | 144 | |||
149 | int | 145 | int | |
150 | ipsec_process_done(struct mbuf *m, const struct ipsecrequest *isr, | 146 | ipsec_process_done(struct mbuf *m, const struct ipsecrequest *isr, | |
151 | struct secasvar *sav) | 147 | struct secasvar *sav) | |
152 | { | 148 | { | |
153 | struct secasindex *saidx; | 149 | struct secasindex *saidx; | |
154 | int error; | 150 | int error; | |
155 | #ifdef INET | 151 | #ifdef INET | |
156 | struct ip * ip; | 152 | struct ip * ip; | |
157 | #endif /* INET */ | 153 | #endif /* INET */ |
--- src/sys/rump/net/lib/libnetinet/netinet_component.c 2017/01/20 08:35:33 1.8
+++ src/sys/rump/net/lib/libnetinet/netinet_component.c 2018/01/02 10:20:34 1.8.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: netinet_component.c,v 1.8 2017/01/20 08:35:33 ozaki-r Exp $ */ | 1 | /* $NetBSD: netinet_component.c,v 1.8.6.1 2018/01/02 10:20:34 snj Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2009 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2009 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Development of this software was supported by The Nokia Foundation | 6 | * Development of this software was supported by The Nokia Foundation | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -18,27 +18,27 @@ | @@ -18,27 +18,27 @@ | |||
18 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 18 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
27 | * SUCH DAMAGE. | 27 | * SUCH DAMAGE. | |
28 | */ | 28 | */ | |
29 | 29 | |||
30 | #include <sys/cdefs.h> | 30 | #include <sys/cdefs.h> | |
31 | __KERNEL_RCSID(0, "$NetBSD: netinet_component.c,v 1.8 2017/01/20 08:35:33 ozaki-r Exp $"); | 31 | __KERNEL_RCSID(0, "$NetBSD: netinet_component.c,v 1.8.6.1 2018/01/02 10:20:34 snj Exp $"); | |
32 | 32 | |||
33 | #include <sys/param.h> | 33 | #include <sys/param.h> | |
34 | #include <sys/domain.h> | 34 | #include <sys/domain.h> | |
35 | #include <sys/protosw.h> | 35 | #include <sys/protosw.h> | |
36 | #include <sys/socketvar.h> | 36 | #include <sys/socketvar.h> | |
37 | 37 | |||
38 | #include <net/if.h> | 38 | #include <net/if.h> | |
39 | #include <net/netisr.h> | 39 | #include <net/netisr.h> | |
40 | #include <netinet/in.h> | 40 | #include <netinet/in.h> | |
41 | #include <netinet/in_var.h> | 41 | #include <netinet/in_var.h> | |
42 | #include <netinet/ip_var.h> | 42 | #include <netinet/ip_var.h> | |
43 | #include <netinet/if_inarp.h> | 43 | #include <netinet/if_inarp.h> | |
44 | 44 | |||
@@ -84,17 +84,19 @@ RUMP_COMPONENT(RUMP_COMPONENT_NET_IFCFG) | @@ -84,17 +84,19 @@ RUMP_COMPONENT(RUMP_COMPONENT_NET_IFCFG) | |||
84 | sin->sin_len = sizeof(struct sockaddr_in); | 84 | sin->sin_len = sizeof(struct sockaddr_in); | |
85 | sin->sin_addr.s_addr = inet_addr("127.0.0.1"); | 85 | sin->sin_addr.s_addr = inet_addr("127.0.0.1"); | |
86 | 86 | |||
87 | sin = (struct sockaddr_in *)&ia.ifra_mask; | 87 | sin = (struct sockaddr_in *)&ia.ifra_mask; | |
88 | sin->sin_family = AF_INET; | 88 | sin->sin_family = AF_INET; | |
89 | sin->sin_len = sizeof(struct sockaddr_in); | 89 | sin->sin_len = sizeof(struct sockaddr_in); | |
90 | sin->sin_addr.s_addr = inet_addr("255.0.0.0"); | 90 | sin->sin_addr.s_addr = inet_addr("255.0.0.0"); | |
91 | 91 | |||
92 | sin = (struct sockaddr_in *)&ia.ifra_broadaddr; | 92 | sin = (struct sockaddr_in *)&ia.ifra_broadaddr; | |
93 | sin->sin_family = AF_INET; | 93 | sin->sin_family = AF_INET; | |
94 | sin->sin_len = sizeof(struct sockaddr_in); | 94 | sin->sin_len = sizeof(struct sockaddr_in); | |
95 | sin->sin_addr.s_addr = inet_addr("127.255.255.255"); | 95 | sin->sin_addr.s_addr = inet_addr("127.255.255.255"); | |
96 | 96 | |||
97 | IFNET_LOCK(lo0ifp); | |||
97 | in_control(so, SIOCAIFADDR, &ia, lo0ifp); | 98 | in_control(so, SIOCAIFADDR, &ia, lo0ifp); | |
99 | IFNET_UNLOCK(lo0ifp); | |||
98 | if_up(lo0ifp); | 100 | if_up(lo0ifp); | |
99 | soclose(so); | 101 | soclose(so); | |
100 | } | 102 | } |