summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2017-05-27 18:50:54 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2017-05-27 18:50:54 +0000
commit34d9c708a48dc0063042b79688c796d7319ac8d1 (patch)
tree826104955ed236967f1f197cf810e29ffbf779cc
parent0fd2ceb34880ceebcf665b361f68b2cba04f090f (diff)
Push the NET_LOCK down into PF_KEY so that it can be treated like PF_ROUTE.
Only pfkeyv2_send() needs the NET_LOCK() so grab it at the start and release at the end. This should allow to push the locks down in other places. OK mpi@, bluhm@
-rw-r--r--sys/kern/uipc_socket.c5
-rw-r--r--sys/kern/uipc_socket2.c11
-rw-r--r--sys/net/pfkeyv2.c9
3 files changed, 15 insertions, 10 deletions
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 29323e8a41f..6003a4661c1 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket.c,v 1.184 2017/05/15 13:00:10 mpi Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.185 2017/05/27 18:50:53 claudio Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
@@ -1043,7 +1043,8 @@ sorflush(struct socket *so)
sb->sb_flags |= SB_NOINTR;
sblock(sb, M_WAITOK,
- (af != PF_LOCAL && af != PF_ROUTE) ? &netlock : NULL);
+ (af != PF_LOCAL && af != PF_ROUTE && af != PF_KEY) ?
+ &netlock : NULL);
socantrcvmore(so);
sbunlock(sb);
asb = *sb;
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index 4ef71d5c6ca..235a20059a9 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket2.c,v 1.76 2017/05/15 12:26:00 mpi Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.77 2017/05/27 18:50:53 claudio Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
@@ -273,7 +273,8 @@ solock(struct socket *so)
int s;
if ((so->so_proto->pr_domain->dom_family != PF_LOCAL) &&
- (so->so_proto->pr_domain->dom_family != PF_ROUTE))
+ (so->so_proto->pr_domain->dom_family != PF_ROUTE) &&
+ (so->so_proto->pr_domain->dom_family != PF_KEY))
NET_LOCK(s);
else
s = -42;
@@ -292,7 +293,8 @@ void
soassertlocked(struct socket *so)
{
if ((so->so_proto->pr_domain->dom_family != PF_LOCAL) &&
- (so->so_proto->pr_domain->dom_family != PF_ROUTE))
+ (so->so_proto->pr_domain->dom_family != PF_ROUTE) &&
+ (so->so_proto->pr_domain->dom_family != PF_KEY))
NET_ASSERT_LOCKED();
}
@@ -300,7 +302,8 @@ int
sosleep(struct socket *so, void *ident, int prio, const char *wmesg, int timo)
{
if ((so->so_proto->pr_domain->dom_family != PF_LOCAL) &&
- (so->so_proto->pr_domain->dom_family != PF_ROUTE)) {
+ (so->so_proto->pr_domain->dom_family != PF_ROUTE) &&
+ (so->so_proto->pr_domain->dom_family != PF_KEY)) {
return rwsleep(ident, &netlock, prio, wmesg, timo);
} else
return tsleep(ident, prio, wmesg, timo);
diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c
index 5c08cca6882..d61fc480862 100644
--- a/sys/net/pfkeyv2.c
+++ b/sys/net/pfkeyv2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkeyv2.c,v 1.156 2017/05/26 19:11:20 claudio Exp $ */
+/* $OpenBSD: pfkeyv2.c,v 1.157 2017/05/27 18:50:53 claudio Exp $ */
/*
* @(#)COPYRIGHT 1.1 (NRL) 17 January 1995
@@ -795,7 +795,7 @@ pfkeyv2_get_proto_alg(u_int8_t satype, u_int8_t *sproto, int *alg)
int
pfkeyv2_send(struct socket *socket, void *message, int len)
{
- int i, j, rval = 0, mode = PFKEYV2_SENDMESSAGE_BROADCAST;
+ int i, j, s, rval = 0, mode = PFKEYV2_SENDMESSAGE_BROADCAST;
int delflag = 0;
struct sockaddr_encap encapdst, encapnetmask;
struct ipsec_policy *ipo, *tmpipo;
@@ -820,7 +820,7 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
u_int rdomain;
- NET_ASSERT_LOCKED();
+ NET_LOCK(s);
/* Verify that we received this over a legitimate pfkeyv2 socket */
bzero(headers, sizeof(headers));
@@ -1356,7 +1356,6 @@ pfkeyv2_send(struct socket *socket, void *message, int len)
rval = tdb_walk(rdomain, pfkeyv2_dump_walker, &dump_state);
if (!rval)
goto realret;
-
if ((rval == ENOMEM) || (rval == ENOBUFS))
rval = 0;
}
@@ -1690,6 +1689,8 @@ ret:
rval = pfkeyv2_sendmessage(headers, mode, socket, 0, 0, rdomain);
realret:
+ NET_UNLOCK(s);
+
if (freeme)
free(freeme, M_PFKEY, 0);