Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys split PRU_CONNECT2 & PRU_PURGEIF function out of pr_gene...
details: https://anonhg.NetBSD.org/src/rev/3a848fabf114
branches: trunk
changeset: 331352:3a848fabf114
user: rtr <rtr%NetBSD.org@localhost>
date: Sat Aug 09 05:33:00 2014 +0000
description:
split PRU_CONNECT2 & PRU_PURGEIF function out of pr_generic() usrreq
switches and put into separate functions
- always KASSERT(solocked(so)) even if not implemented
(for PRU_CONNECT2 only)
- replace calls to pr_generic() with req = PRU_CONNECT2 with calls to
pr_connect2()
- replace calls to pr_generic() with req = PRU_PURGEIF with calls to
pr_purgeif()
put common code from unp_connect2() (used by unp_connect() into
unp_connect1() and call out to it when needed
patch only briefly reviewed by rmind@
diffstat:
sys/kern/uipc_socket.c | 7 +-
sys/kern/uipc_syscalls.c | 6 +-
sys/kern/uipc_usrreq.c | 170 ++++++++++++++++++++++-------------
sys/miscfs/fifofs/fifo_vnops.c | 6 +-
sys/net/if.c | 12 +-
sys/net/link_proto.c | 25 ++++-
sys/net/raw_usrreq.c | 38 +------
sys/net/rtsock.c | 24 ++++-
sys/netatalk/ddp_usrreq.c | 36 +++++-
sys/netbt/hci_socket.c | 33 +++++-
sys/netbt/l2cap_socket.c | 35 +++++-
sys/netbt/rfcomm_socket.c | 36 +++++-
sys/netbt/sco_socket.c | 38 ++++++-
sys/netinet/raw_ip.c | 67 +++++++------
sys/netinet/tcp_usrreq.c | 130 +++++++++++++-------------
sys/netinet/udp_usrreq.c | 70 +++++++-------
sys/netinet6/raw_ip6.c | 53 ++++++----
sys/netinet6/udp6_usrreq.c | 43 ++++++--
sys/netipsec/keysock.c | 27 +++++-
sys/netmpls/mpls_proto.c | 26 ++++-
sys/netnatm/natm.c | 43 +++++---
sys/rump/net/lib/libsockin/sockin.c | 34 +++++-
sys/sys/protosw.h | 28 +++++-
sys/sys/un.h | 4 +-
24 files changed, 630 insertions(+), 361 deletions(-)
diffs (truncated from 2476 to 300 lines):
diff -r 3be66e695165 -r 3a848fabf114 sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c Sat Aug 09 03:17:11 2014 +0000
+++ b/sys/kern/uipc_socket.c Sat Aug 09 05:33:00 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_socket.c,v 1.233 2014/08/08 03:05:45 rtr Exp $ */
+/* $NetBSD: uipc_socket.c,v 1.234 2014/08/09 05:33:00 rtr Exp $ */
/*-
* Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.233 2014/08/08 03:05:45 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.234 2014/08/09 05:33:00 rtr Exp $");
#include "opt_compat_netbsd.h"
#include "opt_sock_counters.h"
@@ -836,8 +836,7 @@
{
KASSERT(solocked2(so1, so2));
- return (*so1->so_proto->pr_usrreqs->pr_generic)(so1,
- PRU_CONNECT2, NULL, (struct mbuf *)so2, NULL, NULL);
+ return (*so1->so_proto->pr_usrreqs->pr_connect2)(so1, so2);
}
int
diff -r 3be66e695165 -r 3a848fabf114 sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c Sat Aug 09 03:17:11 2014 +0000
+++ b/sys/kern/uipc_syscalls.c Sat Aug 09 05:33:00 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_syscalls.c,v 1.171 2014/07/09 04:54:03 rtr Exp $ */
+/* $NetBSD: uipc_syscalls.c,v 1.172 2014/08/09 05:33:00 rtr Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.171 2014/07/09 04:54:03 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.172 2014/08/09 05:33:00 rtr Exp $");
#include "opt_pipe.h"
@@ -1276,7 +1276,7 @@
wf->f_data = wso;
retval[1] = fd;
solock(wso);
- error = unp_connect2(wso, rso, PRU_CONNECT2);
+ error = unp_connect2(wso, rso);
sounlock(wso);
if (error != 0)
goto free4;
diff -r 3be66e695165 -r 3a848fabf114 sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c Sat Aug 09 03:17:11 2014 +0000
+++ b/sys/kern/uipc_usrreq.c Sat Aug 09 05:33:00 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_usrreq.c,v 1.168 2014/08/08 03:05:45 rtr Exp $ */
+/* $NetBSD: uipc_usrreq.c,v 1.169 2014/08/09 05:33:00 rtr Exp $ */
/*-
* Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.168 2014/08/08 03:05:45 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.169 2014/08/09 05:33:00 rtr Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -565,8 +565,6 @@
unp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
struct mbuf *control, struct lwp *l)
{
- struct unpcb *unp;
- int error = 0;
KASSERT(req != PRU_ATTACH);
KASSERT(req != PRU_DETACH);
@@ -574,6 +572,7 @@
KASSERT(req != PRU_BIND);
KASSERT(req != PRU_LISTEN);
KASSERT(req != PRU_CONNECT);
+ KASSERT(req != PRU_CONNECT2);
KASSERT(req != PRU_DISCONNECT);
KASSERT(req != PRU_SHUTDOWN);
KASSERT(req != PRU_ABORT);
@@ -585,27 +584,16 @@
KASSERT(req != PRU_RCVOOB);
KASSERT(req != PRU_SEND);
KASSERT(req != PRU_SENDOOB);
+ KASSERT(req != PRU_PURGEIF);
KASSERT(solocked(so));
- unp = sotounpcb(so);
- KASSERT(!control);
- if (unp == NULL) {
- error = EINVAL;
- goto release;
- }
+ if (sotounpcb(so) == NULL)
+ return EINVAL;
- switch (req) {
- case PRU_CONNECT2:
- error = unp_connect2(so, (struct socket *)nam, PRU_CONNECT2);
- break;
+ panic("piusrreq");
- default:
- panic("piusrreq");
- }
-
-release:
- return (error);
+ return 0;
}
/*
@@ -1088,6 +1076,56 @@
return 0;
}
+static int
+unp_connect1(struct socket *so, struct socket *so2)
+{
+ struct unpcb *unp = sotounpcb(so);
+ struct unpcb *unp2;
+
+ if (so2->so_type != so->so_type)
+ return EPROTOTYPE;
+
+ /*
+ * All three sockets involved must be locked by same lock:
+ *
+ * local endpoint (so)
+ * remote endpoint (so2)
+ * queue head (so2->so_head, only if PR_CONNREQUIRED)
+ */
+ KASSERT(solocked2(so, so2));
+ KASSERT(so->so_head == NULL);
+ if (so2->so_head != NULL) {
+ KASSERT(so2->so_lock == uipc_lock);
+ KASSERT(solocked2(so2, so2->so_head));
+ }
+
+ unp2 = sotounpcb(so2);
+ unp->unp_conn = unp2;
+ switch (so->so_type) {
+
+ case SOCK_DGRAM:
+ unp->unp_nextref = unp2->unp_refs;
+ unp2->unp_refs = unp;
+ soisconnected(so);
+ break;
+
+ case SOCK_SEQPACKET: /* FALLTHROUGH */
+ case SOCK_STREAM:
+
+ /*
+ * SOCK_SEQPACKET and SOCK_STREAM cases are handled by callers
+ * which are unp_connect() or unp_connect2().
+ */
+
+ break;
+
+ default:
+ panic("unp_connect1");
+ }
+
+ return 0;
+}
+
int
unp_connect(struct socket *so, struct mbuf *nam, struct lwp *l)
{
@@ -1182,7 +1220,38 @@
}
so2 = so3;
}
- error = unp_connect2(so, so2, PRU_CONNECT);
+ error = unp_connect1(so, so2);
+ if (error) {
+ sounlock(so);
+ goto bad;
+ }
+ unp2 = sotounpcb(so2);
+ switch (so->so_type) {
+
+ /*
+ * SOCK_DGRAM and default cases are handled in prior call to
+ * unp_connect1(), do not add a default case without fixing
+ * unp_connect1().
+ */
+
+ case SOCK_SEQPACKET: /* FALLTHROUGH */
+ case SOCK_STREAM:
+ unp2->unp_conn = unp;
+ if ((unp->unp_flags | unp2->unp_flags) & UNP_CONNWAIT)
+ soisconnecting(so);
+ else
+ soisconnected(so);
+ soisconnected(so2);
+ /*
+ * If the connection is fully established, break the
+ * association with uipc_lock and give the connected
+ * pair a seperate lock to share.
+ */
+ KASSERT(so2->so_head != NULL);
+ unp_setpeerlocks(so, so2);
+ break;
+
+ }
sounlock(so);
bad:
vput(vp);
@@ -1194,64 +1263,36 @@
}
int
-unp_connect2(struct socket *so, struct socket *so2, int req)
+unp_connect2(struct socket *so, struct socket *so2)
{
struct unpcb *unp = sotounpcb(so);
struct unpcb *unp2;
+ int error = 0;
- if (so2->so_type != so->so_type)
- return (EPROTOTYPE);
+ KASSERT(solocked2(so, so2));
+
+ error = unp_connect1(so, so2);
+ if (error)
+ return error;
+
+ unp2 = sotounpcb(so2);
+ switch (so->so_type) {
/*
- * All three sockets involved must be locked by same lock:
- *
- * local endpoint (so)
- * remote endpoint (so2)
- * queue head (so2->so_head, only if PR_CONNREQUIRED)
+ * SOCK_DGRAM and default cases are handled in prior call to
+ * unp_connect1(), do not add a default case without fixing
+ * unp_connect1().
*/
- KASSERT(solocked2(so, so2));
- KASSERT(so->so_head == NULL);
- if (so2->so_head != NULL) {
- KASSERT(so2->so_lock == uipc_lock);
- KASSERT(solocked2(so2, so2->so_head));
- }
-
- unp2 = sotounpcb(so2);
- unp->unp_conn = unp2;
- switch (so->so_type) {
-
- case SOCK_DGRAM:
- unp->unp_nextref = unp2->unp_refs;
- unp2->unp_refs = unp;
- soisconnected(so);
- break;
case SOCK_SEQPACKET: /* FALLTHROUGH */
case SOCK_STREAM:
unp2->unp_conn = unp;
- if (req == PRU_CONNECT &&
- ((unp->unp_flags | unp2->unp_flags) & UNP_CONNWAIT))
- soisconnecting(so);
- else
- soisconnected(so);
+ soisconnected(so);
soisconnected(so2);
- /*
- * If the connection is fully established, break the
- * association with uipc_lock and give the connected
- * pair a seperate lock to share. For CONNECT2, we
- * require that the locks already match (the sockets
- * are created that way).
- */
- if (req == PRU_CONNECT) {
- KASSERT(so2->so_head != NULL);
- unp_setpeerlocks(so, so2);
- }
break;
- default:
- panic("unp_connect2");
}
- return (0);
+ return error;
}
static void
Home |
Main Index |
Thread Index |
Old Index