summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorozaki-r <ozaki-r@NetBSD.org>2017-09-27 10:05:04 +0000
committerozaki-r <ozaki-r@NetBSD.org>2017-09-27 10:05:04 +0000
commit9ec002730b264aad540a9cedca53e2578486d785 (patch)
treeb7b85b81b17189ce1adec9079459c490de9912ad /sys
parent0cd953860d6624511a69e27fee0a4e91c1bd509b (diff)
Take softnet_lock on pr_input properly if NET_MPSAFE
Currently softnet_lock is taken unnecessarily in some cases, e.g., icmp_input and encap4_input from ip_input, or not taken even if needed, e.g., udp_input and tcp_input from ipsec4_common_input_cb. Fix them. NFC if NET_MPSAFE is disabled (default).
Diffstat (limited to 'sys')
-rw-r--r--sys/netinet/in_proto.c37
-rw-r--r--sys/netinet/ip_input.c6
-rw-r--r--sys/netinet6/in6_proto.c38
-rw-r--r--sys/netinet6/ip6_input.c6
-rw-r--r--sys/netinet6/ip6protosw.h15
-rw-r--r--sys/sys/protosw.h18
6 files changed, 106 insertions, 14 deletions
diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c
index ef1d6879b16..9f054cd8863 100644
--- a/sys/netinet/in_proto.c
+++ b/sys/netinet/in_proto.c
@@ -1,4 +1,4 @@
-/* $NetBSD: in_proto.c,v 1.124 2017/09/21 07:15:34 ozaki-r Exp $ */
+/* $NetBSD: in_proto.c,v 1.125 2017/09/27 10:05:04 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.124 2017/09/21 07:15:34 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.125 2017/09/27 10:05:04 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_mrouting.h"
@@ -72,6 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.124 2017/09/21 07:15:34 ozaki-r Exp $
#include "opt_dccp.h"
#include "opt_sctp.h"
#include "opt_compat_netbsd.h"
+#include "opt_net_mpsafe.h"
#endif
#include <sys/param.h>
@@ -185,6 +186,38 @@ PR_WRAP_CTLOUTPUT(sctp_ctloutput)
#define sctp_ctloutput sctp_ctloutput_wrapper
#endif
+#ifdef NET_MPSAFE
+PR_WRAP_INPUT(udp_input)
+PR_WRAP_INPUT(tcp_input)
+#ifdef DCCP
+PR_WRAP_INPUT(dccp_input)
+#endif
+#ifdef SCTP
+PR_WRAP_INPUT(sctp_input)
+#endif
+PR_WRAP_INPUT(rip_input)
+#if NETHERIP > 0
+PR_WRAP_INPUT(ip_etherip_input)
+#endif
+#if NPFSYNC > 0
+PR_WRAP_INPUT(pfsync_input)
+#endif
+PR_WRAP_INPUT(igmp_input)
+#ifdef PIM
+PR_WRAP_INPUT(pim_input)
+#endif
+
+#define udp_input udp_input_wrapper
+#define tcp_input tcp_input_wrapper
+#define dccp_input dccp_input_wrapper
+#define sctp_input sctp_input_wrapper
+#define rip_input rip_input_wrapper
+#define ip_etherip_input ip_etherip_input_wrapper
+#define pfsync_input pfsync_input_wrapper
+#define igmp_input igmp_input_wrapper
+#define pim_input pim_input_wrapper
+#endif
+
#if defined(IPSEC)
#ifdef IPSEC_RUMPKERNEL
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index 2b5e5825358..c8940bb13b9 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ip_input.c,v 1.360 2017/07/27 06:59:28 ozaki-r Exp $ */
+/* $NetBSD: ip_input.c,v 1.361 2017/09/27 10:05:04 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.360 2017/07/27 06:59:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.361 2017/09/27 10:05:04 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -826,9 +826,7 @@ ours:
const int off = hlen, nh = ip->ip_p;
- SOFTNET_LOCK();
(*inetsw[ip_protox[nh]].pr_input)(m, off, nh);
- SOFTNET_UNLOCK();
return;
out:
diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c
index f7ff2029964..455daf6bf15 100644
--- a/sys/netinet6/in6_proto.c
+++ b/sys/netinet6/in6_proto.c
@@ -1,4 +1,4 @@
-/* $NetBSD: in6_proto.c,v 1.118 2017/09/21 07:15:35 ozaki-r Exp $ */
+/* $NetBSD: in6_proto.c,v 1.119 2017/09/27 10:05:05 ozaki-r Exp $ */
/* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */
/*
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.118 2017/09/21 07:15:35 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.119 2017/09/27 10:05:05 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_gateway.h"
@@ -70,6 +70,7 @@ __KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.118 2017/09/21 07:15:35 ozaki-r Exp
#include "opt_ipsec.h"
#include "opt_dccp.h"
#include "opt_sctp.h"
+#include "opt_net_mpsafe.h"
#endif
#include <sys/param.h>
@@ -184,6 +185,39 @@ PR_WRAP_CTLOUTPUT(sctp_ctloutput)
#define sctp_ctloutput sctp_ctloutput_wrapper
#endif
+#ifdef NET_MPSAFE
+PR_WRAP_INPUT6(udp6_input)
+PR_WRAP_INPUT6(tcp6_input)
+#ifdef DCCP
+PR_WRAP_INPUT6(dccp6_input)
+#endif
+#ifdef SCTP
+PR_WRAP_INPUT6(sctp6_input)
+#endif
+PR_WRAP_INPUT6(rip6_input)
+PR_WRAP_INPUT6(dest6_input)
+PR_WRAP_INPUT6(route6_input)
+PR_WRAP_INPUT6(frag6_input)
+#if NETHERIP > 0
+PR_WRAP_INPUT6(ip6_etherip_input)
+#endif
+#if NPFSYNC > 0
+PR_WRAP_INPUT6(pfsync_input)
+#endif
+PR_WRAP_INPUT6(pim6_input)
+
+#define udp6_input udp6_input_wrapper
+#define tcp6_input tcp6_input_wrapper
+#define dccp6_input dccp6_input_wrapper
+#define sctp6_input sctp6_input_wrapper
+#define rip6_input rip6_input_wrapper
+#define dest6_input dest6_input_wrapper
+#define route6_input route6_input_wrapper
+#define frag6_input frag6_input_wrapper
+#define ip6_etherip_input ip6_etherip_input_wrapper
+#define pim6_input pim6_input_wrapper
+#endif
+
#if defined(IPSEC)
#ifdef IPSEC_RUMPKERNEL
diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c
index ab1b7943512..17a0a88f49e 100644
--- a/sys/netinet6/ip6_input.c
+++ b/sys/netinet6/ip6_input.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6_input.c,v 1.181 2017/07/27 06:59:28 ozaki-r Exp $ */
+/* $NetBSD: ip6_input.c,v 1.182 2017/09/27 10:05:05 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.181 2017/07/27 06:59:28 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.182 2017/09/27 10:05:05 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_gateway.h"
@@ -797,9 +797,7 @@ ip6_input(struct mbuf *m, struct ifnet *rcvif)
}
#endif /* IPSEC */
- SOFTNET_LOCK();
nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
- SOFTNET_UNLOCK();
}
return;
diff --git a/sys/netinet6/ip6protosw.h b/sys/netinet6/ip6protosw.h
index fdbd99dc5f7..7d8c97ecfaa 100644
--- a/sys/netinet6/ip6protosw.h
+++ b/sys/netinet6/ip6protosw.h
@@ -1,4 +1,4 @@
-/* $NetBSD: ip6protosw.h,v 1.25 2016/01/21 15:41:30 riastradh Exp $ */
+/* $NetBSD: ip6protosw.h,v 1.26 2017/09/27 10:05:05 ozaki-r Exp $ */
/* $KAME: ip6protosw.h,v 1.22 2001/02/08 18:02:08 itojun Exp $ */
/*
@@ -140,6 +140,19 @@ struct ip6protosw {
(void);
};
+#ifdef _KERNEL
+#define PR_WRAP_INPUT6(name) \
+static int \
+name##_wrapper(struct mbuf **mp, int *offp, int proto) \
+{ \
+ int rv; \
+ mutex_enter(softnet_lock); \
+ rv = name(mp, offp, proto); \
+ mutex_exit(softnet_lock); \
+ return rv; \
+}
+#endif
+
extern const struct ip6protosw inet6sw[];
#endif /* !_NETINET6_IP6PROTOSW_H_ */
diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h
index 75f32fc598c..b78cce86edf 100644
--- a/sys/sys/protosw.h
+++ b/sys/sys/protosw.h
@@ -1,4 +1,4 @@
-/* $NetBSD: protosw.h,v 1.66 2016/01/20 21:43:59 riastradh Exp $ */
+/* $NetBSD: protosw.h,v 1.67 2017/09/27 10:05:05 ozaki-r Exp $ */
/*-
* Copyright (c) 1982, 1986, 1993
@@ -494,6 +494,22 @@ name##_wrapper(int a, const struct sockaddr *b, void *c)\
return rv; \
}
+#define PR_WRAP_INPUT(name) \
+static void \
+name##_wrapper(struct mbuf *m, ...) \
+{ \
+ va_list args; \
+ int off, nxt; \
+ /* XXX just passing args doesn't work on rump kernels */\
+ va_start(args, m); \
+ off = va_arg(args, int); \
+ nxt = va_arg(args, int); \
+ va_end(args); \
+ mutex_enter(softnet_lock); \
+ name(m, off, nxt); \
+ mutex_exit(softnet_lock); \
+}
+
#endif /* _KERNEL */
#endif /* !_SYS_PROTOSW_H_ */