Module Name:    src
Committed By:   ozaki-r
Date:           Fri Nov 17 07:37:12 UTC 2017

Modified Files:
        src/sys/net: bpf.c if.c if.h if_loop.c if_pppoe.c rtsock.c
        src/sys/net/npf: npf_os.c
        src/sys/netinet: if_arp.c igmp.c in.c ip_flow.c ip_input.c ip_output.c
        src/sys/netinet6: frag6.c in6.c ip6_flow.c ip6_input.c mld6.c nd6.c
            nd6_nbr.c
        src/sys/netipsec: ipsec_output.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/sys/net/bpf.c
cvs rdiff -u -r1.396 -r1.397 src/sys/net/if.c
cvs rdiff -u -r1.242 -r1.243 src/sys/net/if.h
cvs rdiff -u -r1.98 -r1.99 src/sys/net/if_loop.c
cvs rdiff -u -r1.131 -r1.132 src/sys/net/if_pppoe.c
cvs rdiff -u -r1.229 -r1.230 src/sys/net/rtsock.c
cvs rdiff -u -r1.7 -r1.8 src/sys/net/npf/npf_os.c
cvs rdiff -u -r1.254 -r1.255 src/sys/netinet/if_arp.c
cvs rdiff -u -r1.64 -r1.65 src/sys/netinet/igmp.c
cvs rdiff -u -r1.209 -r1.210 src/sys/netinet/in.c
cvs rdiff -u -r1.80 -r1.81 src/sys/netinet/ip_flow.c
cvs rdiff -u -r1.361 -r1.362 src/sys/netinet/ip_input.c
cvs rdiff -u -r1.284 -r1.285 src/sys/netinet/ip_output.c
cvs rdiff -u -r1.60 -r1.61 src/sys/netinet6/frag6.c
cvs rdiff -u -r1.250 -r1.251 src/sys/netinet6/in6.c
cvs rdiff -u -r1.34 -r1.35 src/sys/netinet6/ip6_flow.c
cvs rdiff -u -r1.182 -r1.183 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.89 -r1.90 src/sys/netinet6/mld6.c
cvs rdiff -u -r1.238 -r1.239 src/sys/netinet6/nd6.c
cvs rdiff -u -r1.138 -r1.139 src/sys/netinet6/nd6_nbr.c
cvs rdiff -u -r1.64 -r1.65 src/sys/netipsec/ipsec_output.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/bpf.c
diff -u src/sys/net/bpf.c:1.218 src/sys/net/bpf.c:1.219
--- src/sys/net/bpf.c:1.218	Wed Oct 25 08:12:40 2017
+++ src/sys/net/bpf.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.218 2017/10/25 08:12:40 maya Exp $	*/
+/*	$NetBSD: bpf.c,v 1.219 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.218 2017/10/25 08:12:40 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.219 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_bpf.h"
@@ -484,13 +484,9 @@ bpf_detachd(struct bpf_d *d)
 		 * the interface was configured down, so only panic
 		 * if we don't get an unexpected error.
 		 */
-#ifndef NET_MPSAFE
-		KERNEL_LOCK(1, NULL);
-#endif
+		KERNEL_LOCK_UNLESS_NET_MPSAFE();
   		error = ifpromisc(bp->bif_ifp, 0);
-#ifndef NET_MPSAFE
-		KERNEL_UNLOCK_ONE(NULL);
-#endif
+		KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 #ifdef DIAGNOSTIC
 		if (error)
 			printf("%s: ifpromisc failed: %d", __func__, error);
@@ -1022,13 +1018,9 @@ bpf_ioctl(struct file *fp, u_long cmd, v
 			break;
 		}
 		if (d->bd_promisc == 0) {
-#ifndef NET_MPSAFE
-			KERNEL_LOCK(1, NULL);
-#endif
+			KERNEL_LOCK_UNLESS_NET_MPSAFE();
 			error = ifpromisc(d->bd_bif->bif_ifp, 1);
-#ifndef NET_MPSAFE
-			KERNEL_UNLOCK_ONE(NULL);
-#endif
+			KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 			if (error == 0)
 				d->bd_promisc = 1;
 		}
@@ -2249,13 +2241,9 @@ bpf_setdlt(struct bpf_d *d, u_int dlt)
 	bpf_attachd(d, bp);
 	reset_d(d);
 	if (opromisc) {
-#ifndef NET_MPSAFE
-		KERNEL_LOCK(1, NULL);
-#endif
+		KERNEL_LOCK_UNLESS_NET_MPSAFE();
 		error = ifpromisc(bp->bif_ifp, 1);
-#ifndef NET_MPSAFE
-		KERNEL_UNLOCK_ONE(NULL);
-#endif
+		KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 		if (error)
 			printf("%s: bpf_setdlt: ifpromisc failed (%d)\n",
 			    bp->bif_ifp->if_xname, error);

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.396 src/sys/net/if.c:1.397
--- src/sys/net/if.c:1.396	Mon Oct 23 09:21:20 2017
+++ src/sys/net/if.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.396 2017/10/23 09:21:20 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.397 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.396 2017/10/23 09:21:20 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.397 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2331,10 +2331,7 @@ if_link_state_change_si(void *arg)
 	int s;
 	uint8_t state;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	s = splnet();
 
 	/* Pop a link state change from the queue and process it. */
@@ -2346,10 +2343,7 @@ if_link_state_change_si(void *arg)
 		softint_schedule(ifp->if_link_si);
 
 	splx(s);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /*

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.242 src/sys/net/if.h:1.243
--- src/sys/net/if.h:1.242	Thu Nov 16 03:07:18 2017
+++ src/sys/net/if.h	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.242 2017/11/16 03:07:18 ozaki-r Exp $	*/
+/*	$NetBSD: if.h,v 1.243 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -440,6 +440,46 @@ if_is_link_state_changeable(struct ifnet
 
 	return ((ifp->if_extflags & IFEF_NO_LINK_STATE_CHANGE) == 0);
 }
+
+#ifdef _KERNEL_OPT
+#include "opt_net_mpsafe.h"
+#endif
+
+/* XXX explore a better place to define */
+#ifdef NET_MPSAFE
+
+#define KERNEL_LOCK_UNLESS_NET_MPSAFE()		do { } while (0)
+#define KERNEL_UNLOCK_UNLESS_NET_MPSAFE()	do { } while (0)
+
+#define SOFTNET_LOCK_UNLESS_NET_MPSAFE()	do { } while (0)
+#define SOFTNET_UNLOCK_UNLESS_NET_MPSAFE()	do { } while (0)
+
+#else /* NET_MPSAFE */
+
+#define KERNEL_LOCK_UNLESS_NET_MPSAFE()					\
+	do { KERNEL_LOCK(1, NULL); } while (0)
+#define KERNEL_UNLOCK_UNLESS_NET_MPSAFE()				\
+	do { KERNEL_UNLOCK_ONE(NULL); } while (0)
+
+#define SOFTNET_LOCK_UNLESS_NET_MPSAFE()				\
+	do { mutex_enter(softnet_lock); } while (0)
+#define SOFTNET_UNLOCK_UNLESS_NET_MPSAFE()				\
+	do { mutex_exit(softnet_lock); } while (0)
+
+#endif /* NET_MPSAFE */
+
+#define SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE()				\
+	do {								\
+		SOFTNET_LOCK_UNLESS_NET_MPSAFE();			\
+		KERNEL_LOCK_UNLESS_NET_MPSAFE();			\
+	} while (0)
+
+#define SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE()			\
+	do {								\
+		KERNEL_UNLOCK_UNLESS_NET_MPSAFE();			\
+		SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();			\
+	} while (0)
+
 #endif /* _KERNEL */
 
 #define	IFFBITS \

Index: src/sys/net/if_loop.c
diff -u src/sys/net/if_loop.c:1.98 src/sys/net/if_loop.c:1.99
--- src/sys/net/if_loop.c:1.98	Thu Nov 16 03:07:18 2017
+++ src/sys/net/if_loop.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_loop.c,v 1.98 2017/11/16 03:07:18 ozaki-r Exp $	*/
+/*	$NetBSD: if_loop.c,v 1.99 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.98 2017/11/16 03:07:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.99 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -247,9 +247,7 @@ looutput(struct ifnet *ifp, struct mbuf 
 
 	MCLAIM(m, ifp->if_mowner);
 
-#ifndef NET_MPSAFE
-	KERNEL_LOCK(1, NULL);
-#endif
+	KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
 	if ((m->m_flags & M_PKTHDR) == 0)
 		panic("looutput: no header mbuf");
@@ -375,9 +373,7 @@ looutput(struct ifnet *ifp, struct mbuf 
 	schednetisr(isr);
 	splx(s);
 out:
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-#endif
+	KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 	return error;
 }
 

Index: src/sys/net/if_pppoe.c
diff -u src/sys/net/if_pppoe.c:1.131 src/sys/net/if_pppoe.c:1.132
--- src/sys/net/if_pppoe.c:1.131	Thu Nov 16 03:07:18 2017
+++ src/sys/net/if_pppoe.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.131 2017/11/16 03:07:18 ozaki-r Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.132 2017/11/17 07:37:12 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.131 2017/11/16 03:07:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.132 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pppoe.h"
@@ -477,9 +477,7 @@ pppoeintr(void)
 	struct mbuf *m;
 	int disc_done, data_done;
 
-#ifndef PPPOE_MPSAFE
-		mutex_enter(softnet_lock);
-#endif
+	SOFTNET_LOCK_UNLESS_NET_MPSAFE();
 
 	do {
 		disc_done = 0;
@@ -502,9 +500,8 @@ pppoeintr(void)
 			pppoe_data_input(m);
 		}
 	} while (disc_done || data_done);
-#ifndef PPPOE_MPSAFE
-		mutex_exit(softnet_lock);
-#endif
+
+	SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /* analyze and handle a single received packet while not in session state */

Index: src/sys/net/rtsock.c
diff -u src/sys/net/rtsock.c:1.229 src/sys/net/rtsock.c:1.230
--- src/sys/net/rtsock.c:1.229	Mon Sep 25 01:57:54 2017
+++ src/sys/net/rtsock.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock.c,v 1.229 2017/09/25 01:57:54 ozaki-r Exp $	*/
+/*	$NetBSD: rtsock.c,v 1.230 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.229 2017/09/25 01:57:54 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.230 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2038,10 +2038,7 @@ COMPATNAME(route_intr)(void *cookie)
 	struct route_info * const ri = &COMPATNAME(route_info);
 	struct mbuf *m;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	for (;;) {
 		IFQ_LOCK(&ri->ri_intrq);
 		IF_DEQUEUE(&ri->ri_intrq, m);
@@ -2057,10 +2054,7 @@ COMPATNAME(route_intr)(void *cookie)
 		mutex_exit(rt_so_mtx);
 #endif
 	}
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /*

Index: src/sys/net/npf/npf_os.c
diff -u src/sys/net/npf/npf_os.c:1.7 src/sys/net/npf/npf_os.c:1.8
--- src/sys/net/npf/npf_os.c:1.7	Thu Jul 20 23:37:56 2017
+++ src/sys/net/npf/npf_os.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: npf_os.c,v 1.7 2017/07/20 23:37:56 pgoyette Exp $	*/
+/*	$NetBSD: npf_os.c,v 1.8 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2009-2016 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.7 2017/07/20 23:37:56 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_os.c,v 1.8 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "pf.h"
@@ -397,10 +397,7 @@ npf_pfil_register(bool init)
 	npf_t *npf = npf_getkernctx();
 	int error = 0;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
 	/* Init: interface re-config and attach/detach hook. */
 	if (!npf_ph_if) {
@@ -455,10 +452,7 @@ npf_pfil_register(bool init)
 	npf_ifaddr_syncall(npf);
 	pfil_registered = true;
 out:
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 
 	return error;
 }
@@ -471,10 +465,7 @@ npf_pfil_unregister(bool fini)
 {
 	npf_t *npf = npf_getkernctx();
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
 	if (fini && npf_ph_if) {
 		(void)pfil_remove_ihook(npf_ifhook, NULL,
@@ -492,10 +483,7 @@ npf_pfil_unregister(bool fini)
 	}
 	pfil_registered = false;
 
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 bool

Index: src/sys/netinet/if_arp.c
diff -u src/sys/netinet/if_arp.c:1.254 src/sys/netinet/if_arp.c:1.255
--- src/sys/netinet/if_arp.c:1.254	Fri Nov 10 07:24:28 2017
+++ src/sys/netinet/if_arp.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.c,v 1.254 2017/11/10 07:24:28 ozaki-r Exp $	*/
+/*	$NetBSD: if_arp.c,v 1.255 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.254 2017/11/10 07:24:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.255 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -920,10 +920,7 @@ arpintr(void)
 	int s;
 	int arplen;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	for (;;) {
 		struct ifnet *rcvif;
 
@@ -980,12 +977,8 @@ free:
 		m_freem(m);
 	}
 out:
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#else
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 	return; /* XXX gcc */
-#endif
 }
 
 /*
@@ -1689,10 +1682,7 @@ arp_dad_timer(struct ifaddr *ifa)
 	char ipbuf[INET_ADDRSTRLEN];
 	bool need_free = false;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	mutex_enter(&arp_dad_lock);
 
 	/* Sanity check */
@@ -1783,10 +1773,7 @@ done:
 		ifafree(ifa);
 	}
 
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 static void

Index: src/sys/netinet/igmp.c
diff -u src/sys/netinet/igmp.c:1.64 src/sys/netinet/igmp.c:1.65
--- src/sys/netinet/igmp.c:1.64	Tue Jan 24 07:09:24 2017
+++ src/sys/netinet/igmp.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: igmp.c,v 1.64 2017/01/24 07:09:24 ozaki-r Exp $	*/
+/*	$NetBSD: igmp.c,v 1.65 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.64 2017/01/24 07:09:24 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: igmp.c,v 1.65 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_mrouting.h"
@@ -542,10 +542,8 @@ igmp_fasttimo(void)
 		return;
 	}
 
-#ifndef NET_MPSAFE
 	/* XXX: Needed for ip_output(). */
-	mutex_enter(softnet_lock);
-#endif
+	SOFTNET_LOCK_UNLESS_NET_MPSAFE();
 
 	in_multi_lock(RW_WRITER);
 	igmp_timers_on = false;
@@ -569,9 +567,7 @@ igmp_fasttimo(void)
 		inm = in_next_multi(&step);
 	}
 	in_multi_unlock();
-#ifndef NET_MPSAFE
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 void

Index: src/sys/netinet/in.c
diff -u src/sys/netinet/in.c:1.209 src/sys/netinet/in.c:1.210
--- src/sys/netinet/in.c:1.209	Fri Nov 10 07:24:28 2017
+++ src/sys/netinet/in.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in.c,v 1.209 2017/11/10 07:24:28 ozaki-r Exp $	*/
+/*	$NetBSD: in.c,v 1.210 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.209 2017/11/10 07:24:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.210 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #include "arp.h"
 
@@ -751,13 +751,9 @@ in_control(struct socket *so, u_long cmd
 {
 	int error;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-#endif
+	SOFTNET_LOCK_UNLESS_NET_MPSAFE();
 	error = in_control0(so, cmd, data, ifp);
-#ifndef NET_MPSAFE
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
 
 	return error;
 }

Index: src/sys/netinet/ip_flow.c
diff -u src/sys/netinet/ip_flow.c:1.80 src/sys/netinet/ip_flow.c:1.81
--- src/sys/netinet/ip_flow.c:1.80	Tue Feb  7 02:38:08 2017
+++ src/sys/netinet/ip_flow.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_flow.c,v 1.80 2017/02/07 02:38:08 ozaki-r Exp $	*/
+/*	$NetBSD: ip_flow.c,v 1.81 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.80 2017/02/07 02:38:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_flow.c,v 1.81 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -482,10 +482,7 @@ ipflow_slowtimo_work(struct work *wk, vo
 	/* We can allow enqueuing another work at this point */
 	atomic_swap_uint(&ipflow_work_enqueued, 0);
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	mutex_enter(&ipflow_lock);
 	for (ipf = TAILQ_FIRST(&ipflowlist); ipf != NULL; ipf = next_ipf) {
 		next_ipf = TAILQ_NEXT(ipf, ipf_list);
@@ -505,10 +502,7 @@ ipflow_slowtimo_work(struct work *wk, vo
 		}
 	}
 	mutex_exit(&ipflow_lock);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 void
@@ -529,9 +523,7 @@ ipflow_create(struct route *ro, struct m
 	struct ipflow *ipf;
 	size_t hash;
 
-#ifndef NET_MPSAFE
-	KERNEL_LOCK(1, NULL);
-#endif
+	KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	mutex_enter(&ipflow_lock);
 
 	/*
@@ -582,9 +574,7 @@ ipflow_create(struct route *ro, struct m
 
  out:
 	mutex_exit(&ipflow_lock);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-#endif
+	KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 int
@@ -622,19 +612,13 @@ sysctl_net_inet_ip_maxflows(SYSCTLFN_ARG
 	if (error || newp == NULL)
 		return (error);
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	mutex_enter(&ipflow_lock);
 
 	ipflow_reap(false);
 
 	mutex_exit(&ipflow_lock);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 
 	return (0);
 }
@@ -656,15 +640,9 @@ sysctl_net_inet_ip_hashsize(SYSCTLFN_ARG
 		/*
 		 * Can only fail due to malloc()
 		 */
-#ifndef NET_MPSAFE
-		mutex_enter(softnet_lock);
-		KERNEL_LOCK(1, NULL);
-#endif
+		SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 		error = ipflow_invalidate_all(tmp);
-#ifndef NET_MPSAFE
-		KERNEL_UNLOCK_ONE(NULL);
-		mutex_exit(softnet_lock);
-#endif
+		SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 	} else {
 		/*
 		 * EINVAL if not a power of 2

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.361 src/sys/netinet/ip_input.c:1.362
--- src/sys/netinet/ip_input.c:1.361	Wed Sep 27 10:05:04 2017
+++ src/sys/netinet/ip_input.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.361 2017/09/27 10:05:04 ozaki-r Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.362 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.361 2017/09/27 10:05:04 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.362 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -426,15 +426,11 @@ ipintr(void *arg __unused)
 
 	KASSERT(cpu_softintr_p());
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-#endif
+	SOFTNET_LOCK_UNLESS_NET_MPSAFE();
 	while ((m = pktq_dequeue(ip_pktq)) != NULL) {
 		ip_input(m);
 	}
-#ifndef NET_MPSAFE
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /*
@@ -842,17 +838,11 @@ void
 ip_slowtimo(void)
 {
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
 	ip_reass_slowtimo();
 
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /*

Index: src/sys/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.284 src/sys/netinet/ip_output.c:1.285
--- src/sys/netinet/ip_output.c:1.284	Thu Aug 10 04:31:58 2017
+++ src/sys/netinet/ip_output.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.284 2017/08/10 04:31:58 ryo Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.285 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.284 2017/08/10 04:31:58 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.285 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2072,13 +2072,9 @@ ip_mloopback(struct ifnet *ifp, struct m
 
 	ip->ip_sum = 0;
 	ip->ip_sum = in_cksum(copym, ip->ip_hl << 2);
-#ifndef NET_MPSAFE
-	KERNEL_LOCK(1, NULL);
-#endif
+	KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	(void)looutput(ifp, copym, sintocsa(dst), NULL);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-#endif
+	KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /*

Index: src/sys/netinet6/frag6.c
diff -u src/sys/netinet6/frag6.c:1.60 src/sys/netinet6/frag6.c:1.61
--- src/sys/netinet6/frag6.c:1.60	Tue Jan 24 07:09:25 2017
+++ src/sys/netinet6/frag6.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: frag6.c,v 1.60 2017/01/24 07:09:25 ozaki-r Exp $	*/
+/*	$NetBSD: frag6.c,v 1.61 2017/11/17 07:37:12 ozaki-r Exp $	*/
 /*	$KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.60 2017/01/24 07:09:25 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.61 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -597,20 +597,14 @@ void
 frag6_fasttimo(void)
 {
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
 	if (frag6_drainwanted) {
 		frag6_drain();
 		frag6_drainwanted = 0;
 	}
 
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /*
@@ -623,10 +617,7 @@ frag6_slowtimo(void)
 {
 	struct ip6q *q6;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
 	mutex_enter(&frag6_lock);
 	q6 = ip6q.ip6q_next;
@@ -653,10 +644,7 @@ frag6_slowtimo(void)
 	}
 	mutex_exit(&frag6_lock);
 
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 
 #if 0
 	/*

Index: src/sys/netinet6/in6.c
diff -u src/sys/netinet6/in6.c:1.250 src/sys/netinet6/in6.c:1.251
--- src/sys/netinet6/in6.c:1.250	Fri Nov 10 07:24:28 2017
+++ src/sys/netinet6/in6.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.250 2017/11/10 07:24:28 ozaki-r Exp $	*/
+/*	$NetBSD: in6.c,v 1.251 2017/11/17 07:37:12 ozaki-r Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.250 2017/11/10 07:24:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.251 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -767,13 +767,9 @@ in6_control(struct socket *so, u_long cm
 	}
 
 	s = splsoftnet();
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-#endif
+	SOFTNET_LOCK_UNLESS_NET_MPSAFE();
 	error = in6_control1(so , cmd, data, ifp);
-#ifndef NET_MPSAFE
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
 	splx(s);
 	return error;
 }
@@ -2709,13 +2705,9 @@ in6_domifdetach(struct ifnet *ifp, void 
 
 	lltable_free(ext->lltable);
 	ext->lltable = NULL;
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-#endif
+	SOFTNET_LOCK_UNLESS_NET_MPSAFE();
 	nd6_ifdetach(ifp, ext);
-#ifndef NET_MPSAFE
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
 	free(ext->in6_ifstat, M_IFADDR);
 	free(ext->icmp6_ifstat, M_IFADDR);
 	scope6_ifdetach(ext->scope6_id);

Index: src/sys/netinet6/ip6_flow.c
diff -u src/sys/netinet6/ip6_flow.c:1.34 src/sys/netinet6/ip6_flow.c:1.35
--- src/sys/netinet6/ip6_flow.c:1.34	Wed Jan 11 13:08:29 2017
+++ src/sys/netinet6/ip6_flow.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_flow.c,v 1.34 2017/01/11 13:08:29 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_flow.c,v 1.35 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.34 2017/01/11 13:08:29 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_flow.c,v 1.35 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -519,10 +519,7 @@ ip6flow_slowtimo_work(struct work *wk, v
 	/* We can allow enqueuing another work at this point */
 	atomic_swap_uint(&ip6flow_work_enqueued, 0);
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	mutex_enter(&ip6flow_lock);
 
 	for (ip6f = TAILQ_FIRST(&ip6flowlist); ip6f != NULL; ip6f = next_ip6f) {
@@ -542,10 +539,7 @@ ip6flow_slowtimo_work(struct work *wk, v
 	}
 
 	mutex_exit(&ip6flow_lock);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 void
@@ -572,9 +566,7 @@ ip6flow_create(struct route *ro, struct 
 
 	ip6 = mtod(m, const struct ip6_hdr *);
 
-#ifndef NET_MPSAFE
-	KERNEL_LOCK(1, NULL);
-#endif
+	KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	mutex_enter(&ip6flow_lock);
 
 	/*
@@ -636,9 +628,7 @@ ip6flow_create(struct route *ro, struct 
 
  out:
 	mutex_exit(&ip6flow_lock);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-#endif
+	KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /*
@@ -681,17 +671,11 @@ sysctl_net_inet6_ip6_maxflows(SYSCTLFN_A
 	if (error || newp == NULL)
 		return (error);
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
 	ip6flow_reap(0);
 
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 
 	return (0);
 }
@@ -713,15 +697,9 @@ sysctl_net_inet6_ip6_hashsize(SYSCTLFN_A
 		/*
 		 * Can only fail due to malloc()
 		 */
-#ifndef NET_MPSAFE
-		mutex_enter(softnet_lock);
-		KERNEL_LOCK(1, NULL);
-#endif
+		SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 		error = ip6flow_invalidate_all(tmp);
-#ifndef NET_MPSAFE
-		KERNEL_UNLOCK_ONE(NULL);
-		mutex_exit(softnet_lock);
-#endif
+		SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 	} else {
 		/*
 		 * EINVAL if not a power of 2

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.182 src/sys/netinet6/ip6_input.c:1.183
--- src/sys/netinet6/ip6_input.c:1.182	Wed Sep 27 10:05:05 2017
+++ src/sys/netinet6/ip6_input.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.182 2017/09/27 10:05:05 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.183 2017/11/17 07:37:12 ozaki-r Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.182 2017/09/27 10:05:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.183 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -222,9 +222,7 @@ ip6intr(void *arg __unused)
 {
 	struct mbuf *m;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-#endif
+	SOFTNET_LOCK_UNLESS_NET_MPSAFE();
 	while ((m = pktq_dequeue(ip6_pktq)) != NULL) {
 		struct psref psref;
 		struct ifnet *rcvif = m_get_rcvif_psref(m, &psref);
@@ -244,9 +242,7 @@ ip6intr(void *arg __unused)
 		ip6_input(m, rcvif);
 		m_put_rcvif_psref(rcvif, &psref);
 	}
-#ifndef NET_MPSAFE
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 void

Index: src/sys/netinet6/mld6.c
diff -u src/sys/netinet6/mld6.c:1.89 src/sys/netinet6/mld6.c:1.90
--- src/sys/netinet6/mld6.c:1.89	Sat May 13 20:13:26 2017
+++ src/sys/netinet6/mld6.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: mld6.c,v 1.89 2017/05/13 20:13:26 kardel Exp $	*/
+/*	$NetBSD: mld6.c,v 1.90 2017/11/17 07:37:12 ozaki-r Exp $	*/
 /*	$KAME: mld6.c,v 1.25 2001/01/16 14:14:18 itojun Exp $	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.89 2017/05/13 20:13:26 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mld6.c,v 1.90 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -242,10 +242,7 @@ mld_timeo(void *arg)
 
 	KASSERT(in6m->in6m_refcount > 0);
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	rw_enter(&in6_multilock, RW_WRITER);
 	if (in6m->in6m_timer == IN6M_TIMER_UNDEF)
 		goto out;
@@ -263,12 +260,7 @@ mld_timeo(void *arg)
 
 out:
 	rw_exit(&in6_multilock);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#else
-	return;
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 static u_long

Index: src/sys/netinet6/nd6.c
diff -u src/sys/netinet6/nd6.c:1.238 src/sys/netinet6/nd6.c:1.239
--- src/sys/netinet6/nd6.c:1.238	Fri Nov 10 07:25:39 2017
+++ src/sys/netinet6/nd6.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.238 2017/11/10 07:25:39 ozaki-r Exp $	*/
+/*	$NetBSD: nd6.c,v 1.239 2017/11/17 07:37:12 ozaki-r Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.238 2017/11/10 07:25:39 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.239 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -450,10 +450,7 @@ nd6_llinfo_timer(void *arg)
 	bool send_ns = false;
 	const struct in6_addr *daddr6 = NULL;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	LLE_WLOCK(ln);
 	if ((ln->la_flags & LLE_LINKED) == 0)
 		goto out;
@@ -569,10 +566,7 @@ nd6_llinfo_timer(void *arg)
 out:
 	if (ln != NULL)
 		LLE_FREE_LOCKED(ln);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /*
@@ -590,10 +584,7 @@ nd6_timer_work(struct work *wk, void *ar
 	callout_reset(&nd6_timer_ch, nd6_prune * hz,
 	    nd6_timer, NULL);
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 
 	/* expire default router list */
 
@@ -717,10 +708,7 @@ nd6_timer_work(struct work *wk, void *ar
 	}
 	ND6_UNLOCK();
 
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 static void
@@ -2228,10 +2216,7 @@ nd6_slowtimo(void *ignored_arg)
 	struct ifnet *ifp;
 	int s;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	callout_reset(&nd6_slowtimo_ch, ND6_SLOWTIMER_INTERVAL * hz,
 	    nd6_slowtimo, NULL);
 
@@ -2252,10 +2237,7 @@ nd6_slowtimo(void *ignored_arg)
 	}
 	pserialize_read_exit(s);
 
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 /*

Index: src/sys/netinet6/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.138 src/sys/netinet6/nd6_nbr.c:1.139
--- src/sys/netinet6/nd6_nbr.c:1.138	Tue Mar 14 04:25:10 2017
+++ src/sys/netinet6/nd6_nbr.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.138 2017/03/14 04:25:10 ozaki-r Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.139 2017/11/17 07:37:12 ozaki-r Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.138 2017/03/14 04:25:10 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.139 2017/11/17 07:37:12 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1228,10 +1228,7 @@ nd6_dad_timer(struct ifaddr *ifa)
 	char ip6buf[INET6_ADDRSTRLEN];
 	bool need_free = false;
 
-#ifndef NET_MPSAFE
-	mutex_enter(softnet_lock);
-	KERNEL_LOCK(1, NULL);
-#endif
+	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	mutex_enter(&nd6_dad_lock);
 
 	/* Sanity check */
@@ -1327,10 +1324,7 @@ done:
 	if (duplicate)
 		nd6_dad_duplicated(ifa);
 
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-	mutex_exit(softnet_lock);
-#endif
+	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 }
 
 static void

Index: src/sys/netipsec/ipsec_output.c
diff -u src/sys/netipsec/ipsec_output.c:1.64 src/sys/netipsec/ipsec_output.c:1.65
--- src/sys/netipsec/ipsec_output.c:1.64	Tue Oct  3 08:56:52 2017
+++ src/sys/netipsec/ipsec_output.c	Fri Nov 17 07:37:12 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec_output.c,v 1.64 2017/10/03 08:56:52 ozaki-r Exp $	*/
+/*	$NetBSD: ipsec_output.c,v 1.65 2017/11/17 07:37:12 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ipsec_output.c,v 1.64 2017/10/03 08:56:52 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec_output.c,v 1.65 2017/11/17 07:37:12 ozaki-r Exp $");
 
 /*
  * IPsec output processing.
@@ -117,9 +117,7 @@ ipsec_reinject_ipstack(struct mbuf *m, i
 
 	KASSERT(af == AF_INET || af == AF_INET6);
 
-#ifndef NET_MPSAFE
-	KERNEL_LOCK(1, NULL);
-#endif
+	KERNEL_LOCK_UNLESS_NET_MPSAFE();
 	ro = percpu_getref(ipsec_rtcache_percpu);
 	switch (af) {
 #ifdef INET
@@ -139,9 +137,7 @@ ipsec_reinject_ipstack(struct mbuf *m, i
 #endif
 	}
 	percpu_putref(ipsec_rtcache_percpu);
-#ifndef NET_MPSAFE
-	KERNEL_UNLOCK_ONE(NULL);
-#endif
+	KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
 
 	return rv;
 }

Reply via email to